# Hotfix #559
@@ -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
|
||||
|
||||
@@ -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):
|
||||
"""
|
||||
|
||||
Reference in New Issue
Block a user