forked from AG_QGIS/Plugin_SN_Basis
Anpassung an den Wrappern für sn_plan41
This commit is contained in:
@@ -1,48 +1,57 @@
|
||||
# sn_basis/functions/ly_geometry_wrapper.py
|
||||
|
||||
def get_layer_geometry_type(layer) -> str:
|
||||
if layer is None:
|
||||
return "None"
|
||||
from typing import Optional
|
||||
|
||||
geometry_type = getattr(layer, "geometry_type", None)
|
||||
if geometry_type is not None:
|
||||
return str(geometry_type)
|
||||
|
||||
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:
|
||||
if callable(getattr(layer, "isSpatial", None)) and not layer.isSpatial():
|
||||
return "None"
|
||||
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 not isinstance(value, int):
|
||||
return "None"
|
||||
|
||||
return {
|
||||
0: "Point",
|
||||
1: "LineString",
|
||||
2: "Polygon",
|
||||
}.get(value, "None")
|
||||
if value == 0:
|
||||
return GEOM_POINT
|
||||
if value == 1:
|
||||
return GEOM_LINE
|
||||
if value == 2:
|
||||
return GEOM_POLYGON
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
return "None"
|
||||
|
||||
|
||||
return None
|
||||
|
||||
|
||||
def get_layer_feature_count(layer) -> int:
|
||||
"""
|
||||
Gibt die Anzahl der Features eines Layers zurück.
|
||||
"""
|
||||
if layer is None:
|
||||
return 0
|
||||
|
||||
count = getattr(layer, "feature_count", None)
|
||||
if count is not None:
|
||||
if isinstance(count, int):
|
||||
return count
|
||||
return 0
|
||||
|
||||
try:
|
||||
if callable(getattr(layer, "isSpatial", None)) and not layer.isSpatial():
|
||||
is_spatial = getattr(layer, "isSpatial", None)
|
||||
if callable(is_spatial) and not is_spatial():
|
||||
return 0
|
||||
|
||||
fc = getattr(layer, "featureCount", None)
|
||||
@@ -54,4 +63,3 @@ def get_layer_feature_count(layer) -> int:
|
||||
pass
|
||||
|
||||
return 0
|
||||
|
||||
|
||||
Reference in New Issue
Block a user