Merge pull request '# Hotfix' (#559) from hotfix_API_error_msg_on_wrong_spatial_ref into master

Reviewed-on: #559
This commit was merged in pull request #559.
This commit is contained in:
2026-07-10 19:02:51 +02:00
2 changed files with 23 additions and 0 deletions
+3
View File
@@ -156,6 +156,9 @@ class AbstractModelAPISerializer:
if isinstance(geojson, dict):
geojson = json.dumps(geojson)
geometry = geos.fromstr(geojson)
is_4326 = Geometry.is_valid_4326(geometry)
if not is_4326:
raise ValueError("Geometry not in EPSG:4326 (WGS84). Unknown spatial reference system.")
geometry = Geometry.cast_to_rlp_srid(geometry)
geometry = Geometry.cast_to_multipolygon(geometry)
return geometry
+20
View File
@@ -462,6 +462,26 @@ class Geometry(BaseResource):
conflict_geoms = Geometry.objects.filter(id__in=conflict_geoms_id)
return conflict_geoms
@staticmethod
def is_valid_4326(geometry):
""" Checks whether a given geometry's coordinates are in a valid range to be of EPSG:4326
Args:
geometry: The geometry
Returns:
ret_val (bool): Whether the geometry is valid EPSG:4326
"""
if not geometry.centroid.coords:
# No coordinates at all found, therefore technically proper 4326
return True
try:
lat,lon = geometry.centroid.coords
return (-90.0 <= lat <= 90.0) and (-180.0 <= lon <= 180.0)
except IndexError:
return False
class GeometryConflict(UuidModel):
"""