Files
Plugin_SN_Basis/functions/ly_geometry_wrapper.py

58 lines
1.3 KiB
Python
Raw Normal View History

# sn_basis/functions/ly_geometry_wrapper.py
def get_layer_geometry_type(layer) -> str:
if layer is None:
return "None"
geometry_type = getattr(layer, "geometry_type", None)
if geometry_type is not None:
return str(geometry_type)
try:
if callable(getattr(layer, "isSpatial", None)) and not layer.isSpatial():
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")
except Exception:
pass
return "None"
def get_layer_feature_count(layer) -> int:
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():
return 0
fc = getattr(layer, "featureCount", None)
if callable(fc):
value = fc()
if isinstance(value, int):
return value
except Exception:
pass
return 0