Merge pull request '565 unify geometry quality checking' (#582) from 565_Unify_geometry_quality_checking into master
Reviewed-on: #582
This commit was merged in pull request #582.
This commit is contained in:
@@ -17,6 +17,8 @@ from django.db.models import Q
|
||||
|
||||
from api.models import ExternalIdentifier
|
||||
from konova.models import Geometry
|
||||
from konova.sub_settings.lanis_settings import DEFAULT_SRID
|
||||
from konova.utils.geometry.geometry_validator import GeoJsonValidator
|
||||
from konova.utils.message_templates import DATA_UNSHARED
|
||||
|
||||
|
||||
@@ -156,16 +158,20 @@ class AbstractModelAPISerializer:
|
||||
Returns:
|
||||
geometry (GEOSGeometry)
|
||||
"""
|
||||
if isinstance(geojson, dict):
|
||||
geojson = json.dumps(geojson)
|
||||
geometry = geos.fromstr(geojson)
|
||||
if not geometry.valid:
|
||||
raise ValueError(f"Invalid geometry: {geometry.valid_reason}")
|
||||
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)
|
||||
if isinstance(geojson, str):
|
||||
geojson = json.loads(geojson)
|
||||
|
||||
geojson_validator = GeoJsonValidator(geojson, DEFAULT_SRID)
|
||||
geojson_validator.validate()
|
||||
|
||||
if geojson_validator.errors:
|
||||
raise ValueError(geojson_validator.errors)
|
||||
|
||||
geometry = geojson_validator.validated_geometry
|
||||
is_input_geometry_too_small = geometry.area == 0.0 and geojson_validator.num_ignored_geometries > 0
|
||||
if is_input_geometry_too_small:
|
||||
raise ValueError(f"Your area was too small to be processed! Must be > 1m²!")
|
||||
|
||||
return geometry
|
||||
|
||||
def _get_obj_from_db(self, id, user):
|
||||
|
||||
Reference in New Issue
Block a user