From 12e072a505d2203b3783139e22d87f247975b8ef Mon Sep 17 00:00:00 2001 From: sujanadh Date: Tue, 13 Feb 2024 09:59:32 +0545 Subject: [PATCH] fix: feature type not being saved as a geojson type --- src/backend/app/db/postgis_utils.py | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/backend/app/db/postgis_utils.py b/src/backend/app/db/postgis_utils.py index 4fafaacaa6..820df7eaa6 100644 --- a/src/backend/app/db/postgis_utils.py +++ b/src/backend/app/db/postgis_utils.py @@ -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 = ( @@ -292,7 +292,9 @@ 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 @@ -300,7 +302,7 @@ def is_valid_coordinate(coord): 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)