Skip to content

Commit

Permalink
fix: feature type not being saved as a geojson type
Browse files Browse the repository at this point in the history
  • Loading branch information
sujanadh committed Feb 13, 2024
1 parent 5d68122 commit 12e072a
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 12e072a

Please sign in to comment.