From 970d05653b941a5c9b206ee44112ccf1cebc8699 Mon Sep 17 00:00:00 2001 From: sujanadh Date: Tue, 12 Sep 2023 14:15:39 +0545 Subject: [PATCH] fix: changed single polygon to merged polygon POI if uploaded multi polygon during project area edit --- src/backend/app/projects/project_crud.py | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/src/backend/app/projects/project_crud.py b/src/backend/app/projects/project_crud.py index adc69cdc9b..e91260de7e 100644 --- a/src/backend/app/projects/project_crud.py +++ b/src/backend/app/projects/project_crud.py @@ -830,15 +830,20 @@ def remove_z_dimension(coord): ) """ Apply the lambda function to each coordinate in its geometry """ + multi_polygons = [] for feature in features: list(map(remove_z_dimension, feature["geometry"]["coordinates"][0])) + if feature["geometry"]["type"] == "MultiPolygon": + multi_polygons.append(Polygon(feature["geometry"]["coordinates"][0][0])) + """Update the boundary polyon on the database.""" - outline = shape(features[0]["geometry"]) - - # If the outline is a multipolygon, use the first polygon - if isinstance(outline, MultiPolygon): - outline = outline.geoms[0] + if multi_polygons: + outline = multi_polygons[0] + for geom in multi_polygons[1:]: + outline = outline.union(geom) + else: + outline = shape(features[0]["geometry"]) db_project.outline = outline.wkt db_project.centroid = outline.centroid.wkt