Files
Plugin_SN_Basis/functions/ly_geometry_wrapper.py

66 lines
1.4 KiB
Python

# sn_basis/functions/ly_geometry_wrapper.py
from typing import Optional
GEOM_NONE = None
GEOM_POINT = "Point"
GEOM_LINE = "LineString"
GEOM_POLYGON = "Polygon"
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
try:
is_spatial = getattr(layer, "isSpatial", None)
if callable(is_spatial) and not is_spatial():
return None
gtype = getattr(layer, "geometryType", None)
if callable(gtype):
value = gtype()
if value == 0:
return GEOM_POINT
if value == 1:
return GEOM_LINE
if value == 2:
return GEOM_POLYGON
except Exception:
pass
return None
def get_layer_feature_count(layer) -> int:
"""
Gibt die Anzahl der Features eines Layers zurück.
"""
if layer is None:
return 0
try:
is_spatial = getattr(layer, "isSpatial", None)
if callable(is_spatial) and not is_spatial():
return 0
fc = getattr(layer, "featureCount", None)
if callable(fc):
value = fc()
if isinstance(value, int):
return value
except Exception:
pass
return 0