Files
Plugin_SN_Basis/functions/ly_metadata_wrapper.py

98 lines
1.9 KiB
Python
Raw Permalink Blame History

This file contains invisible Unicode characters
This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# sn_basis/functions/ly_metadata_wrapper.py
from typing import Optional, List
LAYER_TYPE_VECTOR = "vector"
LAYER_TYPE_TABLE = "table"
def get_layer_type(layer) -> Optional[str]:
"""
Gibt den Layer-Typ zurück.
Rückgabewerte:
- "vector"
- "table"
- None (unbekannt / nicht bestimmbar)
"""
if layer is None:
return None
try:
is_spatial = getattr(layer, "isSpatial", None)
if callable(is_spatial):
return LAYER_TYPE_VECTOR if is_spatial() else LAYER_TYPE_TABLE
except Exception:
pass
return None
def get_layer_crs(layer) -> Optional[str]:
"""
Gibt das CRS als AuthID zurück (z.B. 'EPSG:25833').
"""
if layer is None:
return None
try:
crs = layer.crs()
authid = getattr(crs, "authid", None)
if callable(authid):
value = authid()
if isinstance(value, str):
return value
except Exception:
pass
return None
def get_layer_fields(layer) -> List[str]:
"""
Gibt die Feldnamen eines Layers zurück.
"""
if layer is None:
return []
try:
return list(layer.fields().names())
except Exception:
return []
def get_layer_source(layer) -> Optional[str]:
"""
Gibt die Datenquelle eines Layers zurück.
"""
if layer is None:
return None
try:
value = layer.source()
if isinstance(value, str) and value:
return value
except Exception:
pass
return None
def is_layer_editable(layer) -> bool:
"""
Prüft, ob ein Layer editierbar ist.
"""
if layer is None:
return False
try:
is_editable = getattr(layer, "isEditable", None)
if callable(is_editable):
return bool(is_editable())
except Exception:
pass
return False