From 167be0c24e74805ca20278c2ca7597ce7fbce0d0 Mon Sep 17 00:00:00 2001 From: mpeltriaux Date: Fri, 16 Sep 2022 12:09:25 +0200 Subject: [PATCH] Bugfix Parcel calculation * fixes a bug where neighbouring parcels would be detected using Intersection operation as well --- konova/forms/geometry_form.py | 2 +- konova/utils/wfs/spatial.py | 31 +++++++++---------- .../map/client/libs/netgis/MapOpenLayers.js | 2 +- 3 files changed, 17 insertions(+), 18 deletions(-) diff --git a/konova/forms/geometry_form.py b/konova/forms/geometry_form.py index 3c957aa..5d25a85 100644 --- a/konova/forms/geometry_form.py +++ b/konova/forms/geometry_form.py @@ -130,4 +130,4 @@ class SimpleGeomForm(BaseForm): ) # Start the parcel update procedure in a background process celery_update_parcels.delay(geometry.id) - return geometry \ No newline at end of file + return geometry diff --git a/konova/utils/wfs/spatial.py b/konova/utils/wfs/spatial.py index e6cae84..5578c35 100644 --- a/konova/utils/wfs/spatial.py +++ b/konova/utils/wfs/spatial.py @@ -11,10 +11,11 @@ from json import JSONDecodeError from time import sleep import requests -from django.contrib.gis.db.models.functions import AsGML, Transform, MakeValid +from django.contrib.gis.db.models.functions import AsGML, MakeValid +from django.db.models import Func, F from requests.auth import HTTPDigestAuth -from konova.settings import DEFAULT_SRID_RLP, PARCEL_WFS_USER, PARCEL_WFS_PW, PROXIES +from konova.settings import PARCEL_WFS_USER, PARCEL_WFS_PW, PROXIES class AbstractWFSFetcher: @@ -72,33 +73,34 @@ class ParcelWFSFetcher(AbstractWFSFetcher): self.geometry_property_name = geometry_property_name def _create_spatial_filter(self, - geometry_operation: str, - filter_srid: str = None): + geometry_operation: str): """ Creates a xml spatial filter according to the WFS filter specification + The geometry needs to be shrinked by a very small factor (-0.01) before a GML can be created for intersection + checking. Otherwise perfect parcel outline placement on top of a neighbouring parcel would result in an + intersection hit, despite the fact they do not truly intersect just because their vertices match. + Args: geometry_operation (str): One of the WFS supported spatial filter operations (according to capabilities) - filter_srid (str): Used to transform the geometry into the spatial reference system identified by this srid Returns: spatial_filter (str): The spatial filter element """ from konova.models import Geometry - if filter_srid is None: - filter_srid = DEFAULT_SRID_RLP - geom_gml = Geometry.objects.filter( + + geom = Geometry.objects.filter( id=self.geometry_id ).annotate( - transformed=Transform(srid=filter_srid, expression="geom") + smaller=Func(F('geom'), -0.001, function="ST_Buffer") ).annotate( - gml=AsGML(MakeValid('transformed')) - ).first().gml + gml=AsGML(MakeValid('smaller')) + ).first() + geom_gml = geom.gml spatial_filter = f"<{geometry_operation}>{self.geometry_property_name}{geom_gml}" return spatial_filter def _create_post_data(self, geometry_operation: str, - filter_srid: str = None, typenames: str = None, start_index: int = 0, ): @@ -106,15 +108,13 @@ class ParcelWFSFetcher(AbstractWFSFetcher): Args: geometry_operation (str): One of the WFS supported spatial filter operations (according to capabilities) - filter_srid (str): Used to transform the geometry into the spatial reference system identified by this srid Returns: _filter (str): A proper xml WFS filter """ start_index = str(start_index) spatial_filter = self._create_spatial_filter( - geometry_operation, - filter_srid + geometry_operation ) _filter = f'{spatial_filter}' return _filter @@ -144,7 +144,6 @@ class ParcelWFSFetcher(AbstractWFSFetcher): while start_index is not None: post_body = self._create_post_data( spatial_operator, - filter_srid, typenames, start_index ) diff --git a/templates/map/client/libs/netgis/MapOpenLayers.js b/templates/map/client/libs/netgis/MapOpenLayers.js index 807b057..392b1c7 100644 --- a/templates/map/client/libs/netgis/MapOpenLayers.js +++ b/templates/map/client/libs/netgis/MapOpenLayers.js @@ -396,7 +396,7 @@ netgis.MapOpenLayers.prototype.clearAll = function() { if(this.layers[i] === this.editLayer){ continue; - }; + } this.map.removeLayer( this.layers[ i ] ); } -- 2.38.5