Skip to content

Commit

Permalink
Merge pull request #1195 from hotosm/fix-check-crs
Browse files Browse the repository at this point in the history
Fix: Ensure GeoJSON Feature Type is Properly Saved
  • Loading branch information
nrjadkry authored Feb 13, 2024
2 parents 5d68122 + 12e072a commit 39b70e9
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions src/backend/app/db/postgis_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -278,12 +278,12 @@ def is_valid_coordinate(coord):
raise HTTPException(status_code=400, detail=error_message)
return

if input_geojson_type := input_geojson.get("type") == "FeatureCollection":
if (input_geojson_type := input_geojson.get("type")) == "FeatureCollection":
features = input_geojson.get("features", [])
coordinates = (
features[-1].get("geometry", {}).get("coordinates", []) if features else []
)
elif input_geojson_type := input_geojson.get("type") == "Feature":
elif input_geojson_type == "Feature":
coordinates = input_geojson.get("geometry", {}).get("coordinates", [])

geometry_type = (
Expand All @@ -292,15 +292,17 @@ def is_valid_coordinate(coord):
else input_geojson.get("geometry", {}).get("type", "")
)
if geometry_type == "MultiPolygon":
first_coordinate = coordinates[0][0] if coordinates and coordinates[0] else None
first_coordinate = (
coordinates[0][0][0] if coordinates and coordinates[0] else None
)
elif geometry_type == "Point":
first_coordinate = coordinates if coordinates else None

elif geometry_type == "LineString":
first_coordinate = coordinates[0] if coordinates else None

else:
first_coordinate = coordinates[0][0] if coordinates else None
first_coordinate = coordinates[0][0] if coordinates else None # type polygon

if not is_valid_coordinate(first_coordinate):
log.error(error_message)
Expand Down

0 comments on commit 39b70e9

Please sign in to comment.