diff --git a/api/tests/v1/update/test_api_update.py b/api/tests/v1/update/test_api_update.py index ff867e69..ffaa6870 100644 --- a/api/tests/v1/update/test_api_update.py +++ b/api/tests/v1/update/test_api_update.py @@ -12,6 +12,7 @@ from django.contrib.gis import geos from django.urls import reverse from api.tests.v1.share.test_api_sharing import BaseAPIV1TestCase +from konova.sub_settings.lanis_settings import DEFAULT_SRID_RLP class APIV1UpdateTestCase(BaseAPIV1TestCase): @@ -63,6 +64,7 @@ class APIV1UpdateTestCase(BaseAPIV1TestCase): put_props = put_body["properties"] put_geom = geos.fromstr(json.dumps(put_body)) + put_geom.transform(DEFAULT_SRID_RLP) self.assertEqual(put_geom, self.intervention.geometry.geom) self.assertEqual(put_props["title"], self.intervention.title) self.assertNotEqual(modified_on, self.intervention.modified) @@ -92,6 +94,7 @@ class APIV1UpdateTestCase(BaseAPIV1TestCase): put_props = put_body["properties"] put_geom = geos.fromstr(json.dumps(put_body)) + put_geom.transform(DEFAULT_SRID_RLP) self.assertEqual(put_geom, self.compensation.geometry.geom) self.assertEqual(put_props["title"], self.compensation.title) self.assertNotEqual(modified_on, self.compensation.modified) @@ -121,6 +124,7 @@ class APIV1UpdateTestCase(BaseAPIV1TestCase): put_props = put_body["properties"] put_geom = geos.fromstr(json.dumps(put_body)) + put_geom.transform(DEFAULT_SRID_RLP) self.assertEqual(put_geom, self.eco_account.geometry.geom) self.assertEqual(put_props["title"], self.eco_account.title) self.assertNotEqual(modified_on, self.eco_account.modified) @@ -152,6 +156,7 @@ class APIV1UpdateTestCase(BaseAPIV1TestCase): put_props = put_body["properties"] put_geom = geos.fromstr(json.dumps(put_body)) + put_geom.transform(DEFAULT_SRID_RLP) self.assertEqual(put_geom, self.ema.geometry.geom) self.assertEqual(put_props["title"], self.ema.title) self.assertNotEqual(modified_on, self.ema.modified) diff --git a/api/utils/serializer/serializer.py b/api/utils/serializer/serializer.py index 8d618e44..e0511b85 100644 --- a/api/utils/serializer/serializer.py +++ b/api/utils/serializer/serializer.py @@ -12,6 +12,7 @@ from django.contrib.gis import geos from django.contrib.gis.geos import GEOSGeometry from django.core.paginator import Paginator +from konova.sub_settings.lanis_settings import DEFAULT_SRID_RLP from konova.utils.message_templates import DATA_UNSHARED @@ -133,6 +134,8 @@ class AbstractModelAPISerializer: if isinstance(geojson, dict): geojson = json.dumps(geojson) geometry = geos.fromstr(geojson) + if geometry.srid != DEFAULT_SRID_RLP: + geometry.transform(DEFAULT_SRID_RLP) if geometry.empty: geometry = None return geometry diff --git a/konova/forms.py b/konova/forms.py index 0a341e0c..ced2bf10 100644 --- a/konova/forms.py +++ b/konova/forms.py @@ -369,14 +369,14 @@ class SimpleGeomForm(BaseForm): 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.geom = self.cleaned_data.get("geom", MultiPolygon(srid=DEFAULT_SRID_RLP)) geometry.modified = action geometry.save() 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)), + geom=self.cleaned_data.get("geom", MultiPolygon(srid=DEFAULT_SRID_RLP)), created=action, ) # Start the parcel update procedure in a background process diff --git a/konova/models/geometry.py b/konova/models/geometry.py index b996feb7..e55082ac 100644 --- a/konova/models/geometry.py +++ b/konova/models/geometry.py @@ -21,8 +21,7 @@ class Geometry(BaseResource): """ Geometry model """ - from konova.settings import DEFAULT_SRID - geom = MultiPolygonField(null=True, blank=True, srid=DEFAULT_SRID) + geom = MultiPolygonField(null=True, blank=True, srid=DEFAULT_SRID_RLP) def __str__(self): return str(self.id) diff --git a/konova/tests/test_views.py b/konova/tests/test_views.py index 73029f96..4037c6bf 100644 --- a/konova/tests/test_views.py +++ b/konova/tests/test_views.py @@ -430,15 +430,13 @@ class BaseTestCase(TestCase): self.assertTrue(True) return + tolerance = 0.001 if geom1.srid != geom2.srid: - tolerance = 0.001 # Due to prior possible transformation of any of these geometries, we need to make sure there exists a # transformation from one coordinate system into the other, which is valid - geom1_t = geom1.transform(geom2.srid, clone=True) - geom2_t = geom2.transform(geom1.srid, clone=True) - self.assertTrue(geom1_t.equals_exact(geom2, tolerance) or geom2_t.equals_exact(geom1, tolerance)) - else: - self.assertTrue(geom1.equals(geom2)) + geom1.transform(geom2.srid) + geom2.transform(geom1.srid) + self.assertTrue(geom1.equals_exact(geom2, tolerance) or geom2.equals_exact(geom1, tolerance)) class BaseViewTestCase(BaseTestCase):