Compare commits
17
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
970343cd98 | ||
|
|
3d9bfdb316 | ||
|
|
15e48f58af | ||
|
|
933b3f9cb6 | ||
|
|
f6b62395dd | ||
|
|
025a5f5e13 | ||
|
|
e196a4896f | ||
|
|
63a2e8d63a | ||
|
|
79b827c009 | ||
|
|
0e695ba595 | ||
|
|
e11f84e89b | ||
|
|
171ebcbe4f | ||
|
|
b7dfac68f1 | ||
|
|
62e9bcee1e | ||
|
|
e9d9a2294d | ||
|
|
c8fde119b4 | ||
|
|
692f690fea |
@@ -1,3 +1,12 @@
|
||||
- VLN-API zum Laden der Plan41-Maßnahmen integriert
|
||||
---
|
||||
Version 26.5.2-testing:
|
||||
---
|
||||
Version 26.5.1-testing:
|
||||
---
|
||||
Version 26.5.1-unstable:
|
||||
---
|
||||
Version 26.4.8-unstable:
|
||||
---
|
||||
Version 26.4.7-unstable:
|
||||
---
|
||||
|
||||
@@ -20,7 +20,7 @@ from .ly_metadata_wrapper import (
|
||||
is_layer_editable,
|
||||
)
|
||||
from .ly_style_wrapper import apply_style
|
||||
from .dialog_wrapper import ask_yes_no, ask_overwrite_append_cancel_custom, ask_ergaenzen_entfernen_ersetzen_abbrechen
|
||||
from .dialog_wrapper import ask_yes_no, ask_overwrite_append_cancel_custom, ask_ergaenzen_entfernen_ersetzen_abbrechen, ask_detailpruefung_oder_vg_laden
|
||||
|
||||
from .message_wrapper import (
|
||||
_get_message_bar,
|
||||
|
||||
@@ -182,6 +182,56 @@ def ask_ergaenzen_entfernen_ersetzen_abbrechen(
|
||||
return "abbrechen"
|
||||
|
||||
|
||||
def ask_detailpruefung_oder_vg_laden(
|
||||
parent: Any,
|
||||
title: str,
|
||||
message: str,
|
||||
) -> Literal["detailpruefung", "als_vg_laden", "abbrechen"]:
|
||||
"""Zeigt Dialog mit drei Optionen nach erkannter Flächenabweichung.
|
||||
|
||||
Optionen:
|
||||
- **Detailprüfung starten**: Knickpunktbasierte Prüfung des BROR-Umrings
|
||||
- **Bodenordnungsobjekt als VG laden**: BROR direkt als Verfahrensgebiet übernehmen
|
||||
- **Abbrechen**: Vorgang beenden ohne weitere Aktion
|
||||
|
||||
Parameters
|
||||
----------
|
||||
parent :
|
||||
Eltern-Widget oder None.
|
||||
title : str
|
||||
Dialog-Titel.
|
||||
message : str
|
||||
Hauptmeldung mit Flächen-Informationen.
|
||||
|
||||
Returns
|
||||
-------
|
||||
Literal["detailpruefung", "als_vg_laden", "abbrechen"]
|
||||
Genaue Entscheidung des Nutzers.
|
||||
"""
|
||||
if QT_VERSION == 0: # Mock-Modus
|
||||
print(f"Mock-Modus: ask_detailpruefung_oder_vg_laden('{title}') → abbrechen")
|
||||
return "abbrechen"
|
||||
|
||||
msg = QMessageBox(parent)
|
||||
msg.setIcon(ICON_QUESTION)
|
||||
msg.setWindowTitle(title)
|
||||
msg.setText(message)
|
||||
|
||||
detail_btn = msg.addButton("Detailprüfung starten", QMessageBox.ButtonRole.AcceptRole)
|
||||
vg_btn = msg.addButton("Bodenordnungsobjekt als Verfahrensgebiet laden", QMessageBox.ButtonRole.ActionRole)
|
||||
msg.addButton("Abbrechen", QMessageBox.ButtonRole.RejectRole)
|
||||
|
||||
exec_dialog(msg)
|
||||
|
||||
clicked = msg.clickedButton()
|
||||
if clicked == detail_btn:
|
||||
return "detailpruefung"
|
||||
elif clicked == vg_btn:
|
||||
return "als_vg_laden"
|
||||
else:
|
||||
return "abbrechen"
|
||||
|
||||
|
||||
class ProgressDialog:
|
||||
def __init__(self, total: int, title: str = "Fortschritt", label: str = "Verarbeite..."):
|
||||
self.total = max(total, 1)
|
||||
@@ -274,7 +324,73 @@ class ProgressDialog:
|
||||
if self._dlg is not None:
|
||||
self._dlg.close()
|
||||
|
||||
def raise_to_front(self) -> None:
|
||||
"""Bringt den Fortschrittsdialog in den Vordergrund.
|
||||
|
||||
Wird aufgerufen, nachdem ein modaler Subdialog (z. B. Auswahlbox)
|
||||
geschlossen wurde und der Fortschrittsdialog wieder sichtbar sein soll.
|
||||
"""
|
||||
if QT_VERSION == 0:
|
||||
return
|
||||
if self._dlg is not None:
|
||||
try:
|
||||
self._dlg.raise_()
|
||||
self._dlg.activateWindow()
|
||||
QCoreApplication.processEvents()
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
|
||||
def create_progress_dialog(total: int, title: str = "Fortschritt", label: str = "Verarbeite...") -> ProgressDialog:
|
||||
return ProgressDialog(total, title, label)
|
||||
|
||||
|
||||
def ask_bror_kombination(
|
||||
parent: Any,
|
||||
kombinationen: list[tuple[str, str]],
|
||||
) -> Optional[tuple[str, str]]:
|
||||
"""Zeigt Dialog zur Auswahl einer BROR-Kombination (adv_name + bezeichnung).
|
||||
|
||||
Wird aufgerufen, wenn der WFS mehrere verschiedene Kombinationen aus
|
||||
``adv_name`` und ``bezeichnung`` zurückliefert, sodass der Nutzer
|
||||
entscheiden muss, welche Objekte in die Pipeline einfließen sollen.
|
||||
|
||||
Parameters
|
||||
----------
|
||||
parent :
|
||||
Eltern-Widget oder None.
|
||||
kombinationen :
|
||||
Sortierte Liste von ``(adv_name, bezeichnung)``-Tupeln.
|
||||
|
||||
Returns
|
||||
-------
|
||||
Optional[tuple[str, str]]
|
||||
Das gewählte ``(adv_name, bezeichnung)``-Tupel oder ``None`` bei
|
||||
Abbruch bzw. leerer Eingabe.
|
||||
"""
|
||||
if not kombinationen:
|
||||
return None
|
||||
|
||||
if QT_VERSION == 0: # Mock-Modus
|
||||
print(f"Mock-Modus: ask_bror_kombination → {kombinationen[0]}")
|
||||
return kombinationen[0]
|
||||
|
||||
items = [f"{adv} | {bez}" for adv, bez in kombinationen]
|
||||
item, ok = QInputDialog.getItem(
|
||||
parent,
|
||||
"BROR-Objekt auswählen",
|
||||
"Mehrere BauRaumOderBodenordnungsrecht-Objekte gefunden.\n"
|
||||
"Bitte wählen Sie die gewünschte Kombination\n"
|
||||
"aus ADV-Name und Bezeichnung:",
|
||||
items,
|
||||
0,
|
||||
False,
|
||||
)
|
||||
if not ok:
|
||||
return None
|
||||
try:
|
||||
idx = items.index(item)
|
||||
return kombinationen[idx]
|
||||
except ValueError:
|
||||
return None
|
||||
|
||||
|
||||
@@ -5,6 +5,25 @@ from sn_basis.functions.sys_wrapper import get_plugin_root, join_path
|
||||
from sn_basis.modules.stilpruefer import Stilpruefer
|
||||
from typing import Optional
|
||||
|
||||
def apply_style_from_path(layer, style_path: str) -> bool:
|
||||
"""
|
||||
Wendet einen Layerstil anhand eines vollständigen Pfades an.
|
||||
|
||||
Im Gegensatz zu :func:`apply_style` wird der Pfad extern bereitgestellt;
|
||||
es findet keine eigene Stilprüfung statt.
|
||||
"""
|
||||
if not layer_exists(layer):
|
||||
return False
|
||||
try:
|
||||
ok, _ = layer.loadNamedStyle(str(style_path))
|
||||
if ok:
|
||||
getattr(layer, "triggerRepaint", lambda: None)()
|
||||
return True
|
||||
except Exception:
|
||||
pass
|
||||
return False
|
||||
|
||||
|
||||
def apply_style(layer, style_name: str) -> bool:
|
||||
"""
|
||||
Wendet einen Layerstil an, sofern er gültig ist.
|
||||
|
||||
@@ -24,6 +24,7 @@ QgsFeature: Type[Any]
|
||||
QgsField: Type[Any]
|
||||
QgsGeometry: Type[Any]
|
||||
QgsFeatureRequest: Type[Any]
|
||||
QgsRectangle: Type[Any]
|
||||
QgsCoordinateTransform: Type[Any]
|
||||
QgsCoordinateReferenceSystem: Type[Any]
|
||||
QgsPrintLayout: Type[Any]
|
||||
@@ -37,6 +38,12 @@ QgsLayoutPoint: Type[Any]
|
||||
QgsLayoutSize: Type[Any]
|
||||
QgsUnitTypes: Type[Any]
|
||||
QgsLayoutItem: Type[Any]
|
||||
QgsBlockingNetworkRequest: Type[Any]
|
||||
QgsJsonExporter: Type[Any]
|
||||
QgsJsonUtils: Type[Any]
|
||||
GEOM_POINT: Any = None
|
||||
GEOM_LINE: Any = None
|
||||
GEOM_POLYGON: Any = None
|
||||
|
||||
MAP_GRID_STYLE_MARKERS: Any = None
|
||||
MAP_GRID_STYLE_FRAME_ANNOTATIONS: Any = None
|
||||
@@ -76,6 +83,7 @@ try:
|
||||
QgsField as _QgsField,
|
||||
QgsGeometry as _QgsGeometry,
|
||||
QgsFeatureRequest as _QgsFeatureRequest,
|
||||
QgsRectangle as _QgsRectangle,
|
||||
QgsCoordinateTransform as _QgsCoordinateTransform,
|
||||
QgsCoordinateReferenceSystem as _QgsCoordinateReferenceSystem,
|
||||
QgsPrintLayout as _QgsPrintLayout,
|
||||
@@ -89,6 +97,9 @@ try:
|
||||
QgsLayoutSize as _QgsLayoutSize,
|
||||
QgsUnitTypes as _QgsUnitTypes,
|
||||
QgsLayoutItem as _QgsLayoutItem,
|
||||
QgsBlockingNetworkRequest as _QgsBlockingNetworkRequest,
|
||||
QgsJsonExporter as _QgsJsonExporter,
|
||||
QgsJsonUtils as _QgsJsonUtils,
|
||||
)
|
||||
|
||||
QgsProject = _QgsProject
|
||||
@@ -102,6 +113,7 @@ try:
|
||||
QgsField = _QgsField
|
||||
QgsGeometry = _QgsGeometry
|
||||
QgsFeatureRequest = _QgsFeatureRequest
|
||||
QgsRectangle = _QgsRectangle
|
||||
QgsCoordinateTransform = _QgsCoordinateTransform
|
||||
QgsCoordinateReferenceSystem = _QgsCoordinateReferenceSystem
|
||||
QgsPrintLayout = _QgsPrintLayout
|
||||
@@ -115,6 +127,32 @@ try:
|
||||
QgsLayoutSize = _QgsLayoutSize
|
||||
QgsUnitTypes = _QgsUnitTypes
|
||||
QgsLayoutItem = _QgsLayoutItem
|
||||
QgsBlockingNetworkRequest = _QgsBlockingNetworkRequest
|
||||
QgsJsonExporter = _QgsJsonExporter
|
||||
QgsJsonUtils = _QgsJsonUtils
|
||||
|
||||
# Geometrietyp-Konstanten (QGIS 4 / QGIS 3.30+ vs. ältere QGIS-3)
|
||||
def _resolve_geom_type(*paths):
|
||||
for obj, *attrs in paths:
|
||||
val = obj
|
||||
for attr in attrs:
|
||||
val = getattr(val, attr, None)
|
||||
if val is None:
|
||||
break
|
||||
else:
|
||||
if val is not None:
|
||||
return val
|
||||
return None
|
||||
|
||||
GEOM_POINT = _resolve_geom_type(
|
||||
(_Qgis, "GeometryType", "Point"),
|
||||
) or getattr(__import__("qgis.core", fromlist=["QgsWkbTypes"]), "QgsWkbTypes", type("_", (), {"PointGeometry": 0})).PointGeometry
|
||||
GEOM_LINE = _resolve_geom_type(
|
||||
(_Qgis, "GeometryType", "Line"),
|
||||
) or getattr(__import__("qgis.core", fromlist=["QgsWkbTypes"]), "QgsWkbTypes", type("_", (), {"LineGeometry": 1})).LineGeometry
|
||||
GEOM_POLYGON = _resolve_geom_type(
|
||||
(_Qgis, "GeometryType", "Polygon"),
|
||||
) or getattr(__import__("qgis.core", fromlist=["QgsWkbTypes"]), "QgsWkbTypes", type("_", (), {"PolygonGeometry": 2})).PolygonGeometry
|
||||
|
||||
def _resolve_qgis_enum(*paths: tuple[Any, ...]) -> Any:
|
||||
for path in paths:
|
||||
@@ -774,6 +812,60 @@ except Exception:
|
||||
|
||||
QgsVectorFileWriter = _MockQgsVectorFileWriter
|
||||
|
||||
# Geometrietyp-Konstanten (Mock-Werte entsprechen QgsWkbTypes)
|
||||
GEOM_POINT = 0
|
||||
GEOM_LINE = 1
|
||||
GEOM_POLYGON = 2
|
||||
|
||||
class _MockQgsBlockingNetworkRequest:
|
||||
NoError = 0
|
||||
|
||||
def __init__(self):
|
||||
self._reply = None
|
||||
|
||||
def get(self, request: Any) -> int:
|
||||
return self.NoError
|
||||
|
||||
def post(self, request: Any, data: bytes) -> int:
|
||||
return self.NoError
|
||||
|
||||
def put(self, request: Any, data: bytes) -> int:
|
||||
return self.NoError
|
||||
|
||||
def reply(self) -> Any:
|
||||
return self._reply
|
||||
|
||||
def errorMessage(self) -> str:
|
||||
return ""
|
||||
|
||||
QgsBlockingNetworkRequest = _MockQgsBlockingNetworkRequest
|
||||
|
||||
class _MockQgsJsonUtils:
|
||||
@staticmethod
|
||||
def stringToFields(text: str) -> Any:
|
||||
return type("_Fields", (), {"toList": lambda self: []})()
|
||||
|
||||
@staticmethod
|
||||
def stringToFeatureList(text: str, fields: Any) -> list:
|
||||
return []
|
||||
|
||||
QgsJsonUtils = _MockQgsJsonUtils
|
||||
|
||||
class _MockQgsJsonExporter:
|
||||
def __init__(self, layer: Any = None):
|
||||
self._layer = layer
|
||||
|
||||
def setSourceCrs(self, crs: Any) -> None:
|
||||
pass
|
||||
|
||||
def setTransformGeometries(self, transform: bool) -> None:
|
||||
pass
|
||||
|
||||
def exportFeatures(self, features: list) -> str:
|
||||
return '{"type":"FeatureCollection","features":[]}'
|
||||
|
||||
QgsJsonExporter = _MockQgsJsonExporter
|
||||
|
||||
# ---------------------------------------------------------
|
||||
# Netzwerk
|
||||
# ---------------------------------------------------------
|
||||
@@ -951,3 +1043,79 @@ def layer_exists_in_gpkg(gpkg_path: str, layer_name: str) -> bool:
|
||||
pass
|
||||
|
||||
return False
|
||||
|
||||
|
||||
# ---------------------------------------------------------
|
||||
# QGIS-3/4-kompatible Geometrie-Hilfsfunktionen
|
||||
# ---------------------------------------------------------
|
||||
|
||||
def polygon_zu_linie(geom: Any) -> Optional[Any]:
|
||||
"""Konvertiert ein Polygon/MultiPolygon zur Umringslinie (QGIS 3 + 4).
|
||||
|
||||
In QGIS 3.x existiert ``QgsGeometry.boundary()``, in QGIS 4.x wurde sie
|
||||
entfernt. Diese Funktion kapselt die Versionsunterschiede und stellt dem
|
||||
Fachplugin eine stabile API bereit.
|
||||
|
||||
Strategie (dreistufig):
|
||||
1. ``geom.boundary()`` – funktioniert in QGIS 3.x
|
||||
2. ``geom.convertToType(1, False)`` – ``1`` = LineGeometry-Wert,
|
||||
identisch in ``QgsWkbTypes.LineGeometry`` (3.x) und
|
||||
``Qgis.GeometryType.Line`` (4.x)
|
||||
3. Manuelle Ring-Extraktion via ``asPolygon()`` / ``asMultiPolygon()``
|
||||
+ ``QgsGeometry.fromPolylineXY()``
|
||||
|
||||
Parameters
|
||||
----------
|
||||
geom :
|
||||
Polygon- oder MultiPolygon-``QgsGeometry``.
|
||||
|
||||
Returns
|
||||
-------
|
||||
Optional[QgsGeometry]
|
||||
Liniengeometrie (Umring) oder ``None`` bei Fehler / leerer Eingabe.
|
||||
"""
|
||||
if geom is None:
|
||||
return None
|
||||
try:
|
||||
if geom.isEmpty():
|
||||
return None
|
||||
except Exception:
|
||||
return None
|
||||
|
||||
# Stufe 1: QGIS 3.x – .boundary() existiert und liefert alle Ringe korrekt
|
||||
if hasattr(geom, "boundary"):
|
||||
try:
|
||||
result = geom.boundary()
|
||||
if result is not None and not result.isEmpty():
|
||||
return result
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
# Stufe 2: Manuelle Ring-Extraktion (primärer QGIS-4.x-Pfad).
|
||||
# convertToType(1, False) würde bei MultiPolygon nur den ersten Außenring
|
||||
# zurückgeben und alle weiteren Polygone sowie Innenringe verwerfen → daher
|
||||
# direkt die vollständige manuelle Extraktion als nächste Stufe.
|
||||
lines = []
|
||||
try:
|
||||
if geom.isMultipart():
|
||||
for polygon in geom.asMultiPolygon():
|
||||
for ring in polygon:
|
||||
lines.append(QgsGeometry.fromPolylineXY(ring))
|
||||
else:
|
||||
for ring in geom.asPolygon():
|
||||
lines.append(QgsGeometry.fromPolylineXY(ring))
|
||||
except Exception:
|
||||
pass
|
||||
if lines:
|
||||
return QgsGeometry.unaryUnion(lines)
|
||||
|
||||
# Stufe 3: Letzter Fallback – convertToType mit destMultipart=True, damit
|
||||
# zumindest alle Außenringe eines MultiPolygons erfasst werden.
|
||||
try:
|
||||
result = geom.convertToType(1, True)
|
||||
if result is not None and not result.isEmpty():
|
||||
return result
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
return None
|
||||
|
||||
+32
-2
@@ -45,6 +45,7 @@ QComboBox: Type[Any] = object
|
||||
QCheckBox: Type[Any] = object
|
||||
QHBoxLayout: Type[Any] = object
|
||||
QFont: Type[Any] = object
|
||||
QSettings: Type[Any] = object
|
||||
|
||||
|
||||
def exec_dialog(dialog: Any) -> Any:
|
||||
@@ -99,7 +100,8 @@ try:
|
||||
QUrl as _QUrl,
|
||||
QCoreApplication as _QCoreApplication,
|
||||
Qt as _Qt,
|
||||
QVariant as _QVariant
|
||||
QVariant as _QVariant,
|
||||
QSettings as _QSettings,
|
||||
)
|
||||
from qgis.PyQt.QtNetwork import (
|
||||
QNetworkRequest as _QNetworkRequest,
|
||||
@@ -140,6 +142,7 @@ try:
|
||||
QVariant = _QVariant
|
||||
QHBoxLayout = _QHBoxLayout
|
||||
QFont = _QFont
|
||||
QSettings = _QSettings
|
||||
# ✅ QT6 ENUMS
|
||||
YES = QMessageBox.StandardButton.Yes
|
||||
NO = QMessageBox.StandardButton.No
|
||||
@@ -199,7 +202,8 @@ except (ImportError, AttributeError):
|
||||
QUrl as _QUrl,
|
||||
QCoreApplication as _QCoreApplication,
|
||||
Qt as _Qt,
|
||||
QVariant as _QVariant
|
||||
QVariant as _QVariant,
|
||||
QSettings as _QSettings,
|
||||
)
|
||||
from PyQt5.QtNetwork import (
|
||||
QNetworkRequest as _QNetworkRequest,
|
||||
@@ -238,6 +242,7 @@ except (ImportError, AttributeError):
|
||||
QVariant = _QVariant
|
||||
QHBoxLayout= _QHBoxLayout
|
||||
QFont = _QFont
|
||||
QSettings = _QSettings
|
||||
|
||||
# ✅ PYQT5 ENUMS
|
||||
YES = QMessageBox.Yes
|
||||
@@ -560,6 +565,31 @@ except (ImportError, AttributeError):
|
||||
pass
|
||||
QHBoxLayout = _MockQHBoxLayout
|
||||
|
||||
class _MockQSettings:
|
||||
def __init__(self, *args, **kwargs):
|
||||
self._data: dict = {}
|
||||
self._group = ""
|
||||
|
||||
def beginGroup(self, group: str) -> None:
|
||||
self._group = group
|
||||
|
||||
def endGroup(self) -> None:
|
||||
self._group = ""
|
||||
|
||||
def setValue(self, key: str, value: Any) -> None:
|
||||
full = "%s/%s" % (self._group, key) if self._group else key
|
||||
self._data[full] = value
|
||||
|
||||
def value(self, key: str, default: Any = "") -> Any:
|
||||
full = "%s/%s" % (self._group, key) if self._group else key
|
||||
return self._data.get(full, default)
|
||||
|
||||
def remove(self, key: str) -> None:
|
||||
full = "%s/%s" % (self._group, key) if self._group else key
|
||||
self._data.pop(full, None)
|
||||
|
||||
QSettings = _MockQSettings
|
||||
|
||||
class _MockQCheckBox:
|
||||
def __init__(self, text: str = "", *args, **kwargs):
|
||||
self._text = text
|
||||
|
||||
+2
-2
@@ -1,11 +1,11 @@
|
||||
[general]
|
||||
version=26.4.7-unstable
|
||||
version=26.5.2-testing
|
||||
name=LNO Sachsen | Plugin Basisfunktionen
|
||||
description=Plugin mit Basisfunktionen
|
||||
author=Daniel Helbig, Michael Otto
|
||||
homepage=https://entwicklung.flurneuordnung-sachsen.de/AG_QGIS/Plugin_SN_Basis
|
||||
tracker=https://entwicklung.flurneuordnung-sachsen.de/AG_QGIS/Plugin_SN_Basis/issues
|
||||
repository=https://entwicklung.flurneuordnung-sachsen.de/AG_QGIS/Plugin_SN_Basis/src/branch/unstable/
|
||||
repository=https://entwicklung.flurneuordnung-sachsen.de/AG_QGIS/Plugin_SN_Basis/src/branch/testing/
|
||||
QGISMaximumVersion=4.99
|
||||
qgisMinimumVersion=3.40
|
||||
experimental=true
|
||||
|
||||
Reference in New Issue
Block a user