# Coordinate validity check
* refactors coordinate validity check in generic base method * introduces specific check for epsg:25832 (RLP) * refactors check for epsg:4326 to use generic base method
This commit is contained in:
@@ -12,7 +12,7 @@ from django.contrib.gis.geos.prototypes.io import WKTWriter
|
||||
from django.utils.translation import gettext_lazy as _
|
||||
|
||||
from konova.settings import GEOM_MAX_VERTICES
|
||||
from konova.sub_settings.lanis_settings import DEFAULT_SRID_RLP
|
||||
from konova.sub_settings.lanis_settings import DEFAULT_SRID_RLP, DEFAULT_SRID
|
||||
|
||||
|
||||
class GeometryProcessor:
|
||||
@@ -50,7 +50,7 @@ class GeometryProcessor:
|
||||
return geometry.num_coords <= GEOM_MAX_VERTICES
|
||||
|
||||
@staticmethod
|
||||
def is_valid_4326(geometry):
|
||||
def is_valid_4326(geometry: MultiPolygon) -> bool:
|
||||
""" Checks whether a given geometry's coordinates are in a valid range to be of EPSG:4326
|
||||
|
||||
Args:
|
||||
@@ -59,13 +59,66 @@ class GeometryProcessor:
|
||||
Returns:
|
||||
ret_val (bool): Whether the geometry is valid EPSG:4326
|
||||
"""
|
||||
assert geometry.srid == DEFAULT_SRID
|
||||
return GeometryProcessor.is_valid_coord_area(
|
||||
geometry,
|
||||
-90.0,
|
||||
90.0,
|
||||
-180.0,
|
||||
180.0,
|
||||
)
|
||||
|
||||
@staticmethod
|
||||
def is_valid_25832(geometry: MultiPolygon) -> bool:
|
||||
""" Checks whether a given geometry's coordinates are in a valid range to be of EPSG:25832
|
||||
|
||||
Args:
|
||||
geometry: The geometry
|
||||
|
||||
Returns:
|
||||
ret_val (bool): Whether the geometry is valid EPSG:25832
|
||||
"""
|
||||
assert geometry.srid == DEFAULT_SRID_RLP
|
||||
return GeometryProcessor.is_valid_coord_area(
|
||||
geometry,
|
||||
166_000,
|
||||
834_000,
|
||||
0,
|
||||
9_329_000,
|
||||
)
|
||||
|
||||
@staticmethod
|
||||
def is_valid_coord_area(geometry: MultiPolygon,
|
||||
min_x:float|int,
|
||||
max_x:float|int,
|
||||
min_y:float|int,
|
||||
max_y: float|int) -> bool:
|
||||
""" Checks whether a given geometry's coordinates are in a valid range defined by input parameters
|
||||
|
||||
Args:
|
||||
geometry: The geometry
|
||||
min_x (float|int): The min x value
|
||||
max_x (float|int): The max x value
|
||||
min_y (float|int): The min y value
|
||||
max_y (float|int): The max y value
|
||||
|
||||
Returns:
|
||||
ret_val (bool): Whether the geometry's coordinates stays inside the defined range
|
||||
"""
|
||||
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)
|
||||
env_min_x, env_max_x, env_min_y, env_max_y = geometry.envelope
|
||||
|
||||
valid = (
|
||||
min_x <= env_min_x and
|
||||
env_max_x <= max_x and
|
||||
min_y <= env_min_y and
|
||||
env_max_y <= max_y
|
||||
)
|
||||
return valid
|
||||
except IndexError:
|
||||
return False
|
||||
|
||||
|
||||
Reference in New Issue
Block a user