#50 Overlaying geometries KOM + OEK

* removes unused messages
* adds geometry conflict message rendering for KOM and OEK
* removes unused methods in GeoReferencedMixin
* generalizes geometrical lookup for conflicts from overlaps to intersects
This commit is contained in:
2021-12-15 15:10:35 +01:00
parent f4541abf20
commit 41af455d09
9 changed files with 70 additions and 37 deletions

View File

@@ -282,11 +282,13 @@ class SimpleGeomForm(BaseForm):
"""
try:
if self.instance is None or self.instance.geometry is None:
raise LookupError
geometry = self.instance.geometry
geometry.geom = self.cleaned_data.get("geom", MultiPolygon(srid=DEFAULT_SRID))
geometry.modified = action
geometry.save()
except AttributeError:
except LookupError:
# No geometry or linked instance holding a geometry exist --> create a new one!
geometry = Geometry.objects.create(
geom=self.cleaned_data.get("geom", MultiPolygon(srid=DEFAULT_SRID)),

View File

@@ -7,6 +7,7 @@ Created on: 15.11.21
"""
from django.contrib.gis.db.models import MultiPolygonField
from django.db import models
from django.db.models import Q
from konova.models import BaseResource, UuidModel
@@ -37,9 +38,12 @@ class Geometry(BaseResource):
check_timestamp_obj = self.modified or self.created
ts = check_timestamp_obj.timestamp
overlapping_geoms = Geometry.objects.filter(
modified__timestamp__lte=ts,
geom__overlaps=self.geom,
)
Q(modified__timestamp__lte=ts) |
Q(created__timestamp__lte=ts),
geom__intersects=self.geom,
).exclude(
id=self.id
).distinct()
# Drop known conflicts for this object to replace with new ones
self.conflicts_geometries.all().delete()

View File

@@ -21,8 +21,7 @@ from ema.settings import EMA_ACCOUNT_IDENTIFIER_LENGTH, EMA_ACCOUNT_IDENTIFIER_T
from intervention.settings import INTERVENTION_IDENTIFIER_LENGTH, INTERVENTION_IDENTIFIER_TEMPLATE
from konova.utils import generators
from konova.utils.generators import generate_random_string
from konova.utils.message_templates import CHECKED_RECORDED_RESET, GEOMETRY_OVERLAPS_WITH_TEMPLATE, \
GEOMETRY_OVERLAPPED_BY_TEMPLATE
from konova.utils.message_templates import CHECKED_RECORDED_RESET, GEOMETRY_CONFLICT_WITH_TEMPLATE
from user.models import UserActionLogEntry, UserAction
@@ -421,26 +420,21 @@ class GeoReferencedMixin(models.Model):
class Meta:
abstract = True
def _set_overlapping_message(self, request: HttpRequest):
geom_conflicts = self.geometry.conflicts_geometries.all()
if geom_conflicts:
data_objs = []
for conflict in geom_conflicts:
data_objs += conflict.existing_geometry.get_data_objects()
data_identifiers = [x.identifier for x in data_objs]
data_identifiers = ", ".join(data_identifiers)
message_str = GEOMETRY_OVERLAPS_WITH_TEMPLATE.format(data_identifiers)
def _set_geometry_conflict_message(self, request: HttpRequest):
instance_objs = []
add_message = False
conflicts = self.geometry.conflicts_geometries.all()
for conflict in conflicts:
instance_objs += conflict.existing_geometry.get_data_objects()
add_message = True
conflicts = self.geometry.conflicted_by_geometries.all()
for conflict in conflicts:
instance_objs += conflict.conflicting_geometry.get_data_objects()
add_message = True
if add_message:
instance_identifiers = [x.identifier for x in instance_objs]
instance_identifiers = ", ".join(instance_identifiers)
message_str = GEOMETRY_CONFLICT_WITH_TEMPLATE.format(instance_identifiers)
messages.info(request, message_str)
return request
def _set_overlapped_by_message(self, request: HttpRequest):
geom_conflicts = self.geometry.conflicted_by_geometries.all()
if geom_conflicts:
data_objs = []
for conflict in geom_conflicts:
data_objs += conflict.conflicting_geometry.get_data_objects()
data_identifiers = [x.identifier for x in data_objs]
data_identifiers = ", ".join(data_identifiers)
message_str = GEOMETRY_OVERLAPPED_BY_TEMPLATE.format(data_identifiers)
messages.info(request, message_str)
return request

View File

@@ -28,5 +28,4 @@ ADDED_DEADLINE = _("Added deadline")
ADDED_COMPENSATION_ACTION = _("Added compensation action")
# Geometry conflicts
GEOMETRY_OVERLAPS_WITH_TEMPLATE = _("Geometry overlaps {}")
GEOMETRY_OVERLAPPED_BY_TEMPLATE = _("Geometry overlapped by {}")
GEOMETRY_CONFLICT_WITH_TEMPLATE = _("Geometry conflict detected with {}")