2025-12-19 14:29:52 +01:00
|
|
|
# sn_basis/functions/ly_geometry_wrapper.py
|
|
|
|
|
|
2026-01-08 17:13:51 +01:00
|
|
|
from typing import Optional
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
GEOM_NONE = None
|
|
|
|
|
GEOM_POINT = "Point"
|
|
|
|
|
GEOM_LINE = "LineString"
|
|
|
|
|
GEOM_POLYGON = "Polygon"
|
2025-12-19 14:29:52 +01:00
|
|
|
|
2026-01-08 17:13:51 +01:00
|
|
|
|
|
|
|
|
def get_layer_geometry_type(layer) -> Optional[str]:
|
|
|
|
|
"""
|
|
|
|
|
Gibt den Geometrietyp eines Layers zurück.
|
|
|
|
|
|
|
|
|
|
Rückgabewerte:
|
|
|
|
|
- "Point"
|
|
|
|
|
- "LineString"
|
|
|
|
|
- "Polygon"
|
|
|
|
|
- None (nicht räumlich / ungültig / unbekannt)
|
|
|
|
|
"""
|
|
|
|
|
if layer is None:
|
|
|
|
|
return None
|
2025-12-19 14:29:52 +01:00
|
|
|
|
|
|
|
|
try:
|
2026-01-08 17:13:51 +01:00
|
|
|
is_spatial = getattr(layer, "isSpatial", None)
|
|
|
|
|
if callable(is_spatial) and not is_spatial():
|
|
|
|
|
return None
|
2025-12-19 14:29:52 +01:00
|
|
|
|
|
|
|
|
gtype = getattr(layer, "geometryType", None)
|
|
|
|
|
if callable(gtype):
|
|
|
|
|
value = gtype()
|
2026-01-08 17:13:51 +01:00
|
|
|
if value == 0:
|
|
|
|
|
return GEOM_POINT
|
|
|
|
|
if value == 1:
|
|
|
|
|
return GEOM_LINE
|
|
|
|
|
if value == 2:
|
|
|
|
|
return GEOM_POLYGON
|
2025-12-19 14:29:52 +01:00
|
|
|
except Exception:
|
|
|
|
|
pass
|
|
|
|
|
|
2026-01-08 17:13:51 +01:00
|
|
|
return None
|
2025-12-19 14:29:52 +01:00
|
|
|
|
|
|
|
|
|
|
|
|
|
def get_layer_feature_count(layer) -> int:
|
2026-01-08 17:13:51 +01:00
|
|
|
"""
|
|
|
|
|
Gibt die Anzahl der Features eines Layers zurück.
|
|
|
|
|
"""
|
2025-12-19 14:29:52 +01:00
|
|
|
if layer is None:
|
|
|
|
|
return 0
|
|
|
|
|
|
|
|
|
|
try:
|
2026-01-08 17:13:51 +01:00
|
|
|
is_spatial = getattr(layer, "isSpatial", None)
|
|
|
|
|
if callable(is_spatial) and not is_spatial():
|
2025-12-19 14:29:52 +01:00
|
|
|
return 0
|
|
|
|
|
|
|
|
|
|
fc = getattr(layer, "featureCount", None)
|
|
|
|
|
if callable(fc):
|
|
|
|
|
value = fc()
|
|
|
|
|
if isinstance(value, int):
|
|
|
|
|
return value
|
|
|
|
|
except Exception:
|
|
|
|
|
pass
|
|
|
|
|
|
|
|
|
|
return 0
|