Further fixes
* fixes race condition on geometry conflict calculation if performed in background process * simplifies access to smaller buffered geometry * adds mapping of "qm"->"m2" for UnitChoice in API usage for backwards compatibility
This commit is contained in:
@@ -8,13 +8,11 @@ Created on: 15.11.21
|
||||
import json
|
||||
|
||||
from django.contrib.gis.db.models import MultiPolygonField
|
||||
from django.contrib.gis.geos import Polygon
|
||||
from django.db import models, transaction
|
||||
from django.utils import timezone
|
||||
|
||||
from konova.models import BaseResource, UuidModel
|
||||
from konova.sub_settings.lanis_settings import DEFAULT_SRID_RLP
|
||||
from konova.tasks import celery_check_for_geometry_conflicts
|
||||
from konova.utils.wfs.spatial import ParcelWFSFetcher
|
||||
|
||||
|
||||
@@ -29,7 +27,18 @@ class Geometry(BaseResource):
|
||||
|
||||
def save(self, *args, **kwargs):
|
||||
super().save(*args, **kwargs)
|
||||
celery_check_for_geometry_conflicts.delay(self.id)
|
||||
|
||||
@property
|
||||
def geom_small_buffered(self):
|
||||
"""
|
||||
Returns a smaller buffered version of the geometry.
|
||||
Can be used to shrink the geometry used for intersection purposes to avoid intersection detection on
|
||||
neighbouring geometries.
|
||||
|
||||
Returns:
|
||||
|
||||
"""
|
||||
return self.geom.buffer(-0.001)
|
||||
|
||||
def check_for_conflicts(self):
|
||||
""" Checks for new geometry overlaps
|
||||
@@ -44,9 +53,8 @@ class Geometry(BaseResource):
|
||||
return None
|
||||
|
||||
self.recheck_existing_conflicts()
|
||||
|
||||
overlapping_geoms = Geometry.objects.filter(
|
||||
geom__intersects=self.geom,
|
||||
geom__intersects=self.geom_small_buffered,
|
||||
).exclude(
|
||||
id=self.id
|
||||
).distinct()
|
||||
@@ -68,14 +76,14 @@ class Geometry(BaseResource):
|
||||
"""
|
||||
all_conflicts_as_conflicting = self.conflicts_geometries.all()
|
||||
still_conflicting_conflicts = all_conflicts_as_conflicting.filter(
|
||||
affected_geometry__geom__intersects=self.geom
|
||||
affected_geometry__geom__intersects=self.geom_small_buffered
|
||||
)
|
||||
resolved_conflicts = all_conflicts_as_conflicting.exclude(id__in=still_conflicting_conflicts)
|
||||
resolved_conflicts.delete()
|
||||
|
||||
all_conflicted_by_conflicts = self.conflicted_by_geometries.all()
|
||||
still_conflicting_conflicts = all_conflicted_by_conflicts.filter(
|
||||
conflicting_geometry__geom__intersects=self.geom
|
||||
conflicting_geometry__geom__intersects=self.geom_small_buffered
|
||||
)
|
||||
resolved_conflicts = all_conflicted_by_conflicts.exclude(id__in=still_conflicting_conflicts)
|
||||
resolved_conflicts.delete()
|
||||
|
||||
Reference in New Issue
Block a user