From b61c727a685b464b04a3279d7c3da6c2db0a8b32 Mon Sep 17 00:00:00 2001 From: spwoodcock Date: Thu, 15 Feb 2024 17:29:03 +0000 Subject: [PATCH] fix: first coordinate check when check_crs geojson --- src/backend/app/db/postgis_utils.py | 24 +++++++----------------- 1 file changed, 7 insertions(+), 17 deletions(-) diff --git a/src/backend/app/db/postgis_utils.py b/src/backend/app/db/postgis_utils.py index 0a77c88b78..cbdb2c1031 100644 --- a/src/backend/app/db/postgis_utils.py +++ b/src/backend/app/db/postgis_utils.py @@ -325,24 +325,14 @@ def is_valid_coordinate(coord): ) elif input_geojson_type == "Feature": coordinates = input_geojson.get("geometry", {}).get("coordinates", []) - - geometry_type = ( - features[0].get("geometry", {}).get("type") - if input_geojson_type == "FeatureCollection" and features - else input_geojson.get("geometry", {}).get("type", "") - ) - if geometry_type == "MultiPolygon": - 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 # type polygon + coordinates = input_geojson.get("coordinates", {}) + + first_coordinate = None + if coordinates: + while isinstance(coordinates, list): + first_coordinate = coordinates + coordinates = coordinates[0] if not is_valid_coordinate(first_coordinate): log.error(error_message)