From e6c0d8b1cf36d7e3469635314b119a92eab983eb Mon Sep 17 00:00:00 2001 From: mpeltriaux Date: Fri, 14 Oct 2022 08:02:08 +0200 Subject: [PATCH] Map client holes fix MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * fixes bug where holes in stored geometries would not be rendered properly on initial loading the map client * drawback: multiple polygons are treated as a single feature on the map client. Not a real issue but maybe we can find a better solution to this * quality of life: renders geometry area in m² on detail and report view --- konova/models/geometry.py | 11 ++++------- .../konova/includes/parcels/parcels.html | 17 +++++++++++++---- 2 files changed, 17 insertions(+), 11 deletions(-) diff --git a/konova/models/geometry.py b/konova/models/geometry.py index f69fcc7e..f8c272f9 100644 --- a/konova/models/geometry.py +++ b/konova/models/geometry.py @@ -213,12 +213,9 @@ class Geometry(BaseResource): geojson (dict): The FeatureCollection json (as dict) """ geom = self.geom - geom.transform(ct=srid) + if geom.srid != srid: + geom.transform(ct=srid) - polygons = [] - for coords in geom.coords: - p = Polygon(coords[0], srid=geom.srid) - polygons.append(p) geojson = { "type": "FeatureCollection", "crs": { @@ -230,8 +227,8 @@ class Geometry(BaseResource): "features": [ { "type": "Feature", - "geometry": json.loads(x.geojson) - } for x in polygons + "geometry": json.loads(geom.json), + } ] } return geojson diff --git a/konova/templates/konova/includes/parcels/parcels.html b/konova/templates/konova/includes/parcels/parcels.html index a8a882ed..9512c09c 100644 --- a/konova/templates/konova/includes/parcels/parcels.html +++ b/konova/templates/konova/includes/parcels/parcels.html @@ -2,10 +2,19 @@
-
- {% fa5_icon 'search-location' %} - {% trans 'Spatial reference' %} -
+
+
+
+ {% fa5_icon 'search-location' %} + {% trans 'Spatial reference' %} +
+
+
+
+ {{ obj.geometry.geom.area|floatformat:2 }} m² +
+
+