Erste Version Verfahrensgebiet aus ALKIS laden
This commit is contained in:
85
logic/alkis_verfahrensgebiet.py
Normal file
85
logic/alkis_verfahrensgebiet.py
Normal file
@@ -0,0 +1,85 @@
|
|||||||
|
import os
|
||||||
|
from qgis.core import (
|
||||||
|
QgsVectorLayer, QgsProject, QgsFeature, QgsField,
|
||||||
|
QgsFeatureRequest, QgsGeometry
|
||||||
|
)
|
||||||
|
from qgis.PyQt.QtWidgets import QMessageBox
|
||||||
|
from qgis.PyQt.QtCore import QVariant
|
||||||
|
from sn_basis import get_variable
|
||||||
|
|
||||||
|
alkis_NAS_url = "https://geodienste.sachsen.de/aaa/public_alkis/nas/wfs"
|
||||||
|
typename = "adv:AX_BauRaumOderBodenordnungsrecht"
|
||||||
|
|
||||||
|
|
||||||
|
def alkis_verfahrensgebiet(tab_widget):
|
||||||
|
verfahrensnummer = get_variable("verfahrensnummer")
|
||||||
|
if not verfahrensnummer:
|
||||||
|
QMessageBox.critical(tab_widget, "Fehler",
|
||||||
|
"Die Projektvariable 'sn_verfahrensnummer' ist nicht gesetzt.")
|
||||||
|
tab_widget.setze_haken(tab_widget.haken1, False)
|
||||||
|
return None, False
|
||||||
|
|
||||||
|
project = QgsProject.instance()
|
||||||
|
existing_layers = project.mapLayersByName("Verfahrensgebiet")
|
||||||
|
if existing_layers:
|
||||||
|
reply = QMessageBox.question(
|
||||||
|
tab_widget,
|
||||||
|
"Layer bereits vorhanden",
|
||||||
|
"Der Layer 'Verfahrensgebiet' existiert bereits.\n"
|
||||||
|
"Möchten Sie ihn löschen und neu laden?",
|
||||||
|
QMessageBox.StandardButton.Yes | QMessageBox.StandardButton.No,
|
||||||
|
QMessageBox.StandardButton.No
|
||||||
|
)
|
||||||
|
if reply == QMessageBox.StandardButton.Yes:
|
||||||
|
for lyr in existing_layers:
|
||||||
|
project.removeMapLayer(lyr.id())
|
||||||
|
else:
|
||||||
|
# Vorhandenen Layer zurückgeben, kein Neu-Laden
|
||||||
|
return existing_layers[0], False
|
||||||
|
|
||||||
|
# WFS mit Filter laden
|
||||||
|
wfs_uri_find = (
|
||||||
|
f"url='{alkis_NAS_url}' typename='{typename}' srsname='EPSG:25833' "
|
||||||
|
f"sql=SELECT * FROM AX_BauRaumOderBodenordnungsrecht "
|
||||||
|
f"WHERE bezeichnung LIKE '{verfahrensnummer}%'"
|
||||||
|
)
|
||||||
|
temp_layer = QgsVectorLayer(wfs_uri_find, "TempVerfahrensgebiet", "WFS")
|
||||||
|
|
||||||
|
if not temp_layer.isValid():
|
||||||
|
QMessageBox.critical(tab_widget, "Fehler", "Layer konnte nicht geladen werden.")
|
||||||
|
return None, False
|
||||||
|
|
||||||
|
features = list(temp_layer.getFeatures())
|
||||||
|
if not features:
|
||||||
|
QMessageBox.critical(tab_widget, "Fehler",
|
||||||
|
f"Verfahrenskennzeichen {verfahrensnummer} nicht im WFS gefunden.")
|
||||||
|
return None, False
|
||||||
|
|
||||||
|
# Geometrie bestimmen
|
||||||
|
if len(features) == 1:
|
||||||
|
union_geom = features[0].geometry()
|
||||||
|
else:
|
||||||
|
geoms = [f.geometry() for f in features]
|
||||||
|
union_geom = QgsGeometry.unaryUnion(geoms)
|
||||||
|
|
||||||
|
if union_geom is None or union_geom.isEmpty():
|
||||||
|
QMessageBox.critical(tab_widget, "Fehler", "Keine Geometrien zum Verschmelzen gefunden.")
|
||||||
|
return None, False
|
||||||
|
|
||||||
|
# Memory-Layer mit festem Namen "Verfahrensgebiet"
|
||||||
|
crs = temp_layer.crs().authid()
|
||||||
|
memory_layer = QgsVectorLayer(f"Polygon?crs={crs}", "Verfahrensgebiet", "memory")
|
||||||
|
pr = memory_layer.dataProvider()
|
||||||
|
|
||||||
|
# Feld "VKZ" hinzufügen
|
||||||
|
pr.addAttributes([QgsField("VKZ", QVariant.String)])
|
||||||
|
memory_layer.updateFields()
|
||||||
|
|
||||||
|
# Feature mit Geometrie erstellen
|
||||||
|
feat_union = QgsFeature()
|
||||||
|
feat_union.setGeometry(union_geom)
|
||||||
|
feat_union.setAttributes([verfahrensnummer])
|
||||||
|
pr.addFeatures([feat_union])
|
||||||
|
memory_layer.updateExtents()
|
||||||
|
|
||||||
|
return memory_layer, True
|
||||||
@@ -5,4 +5,4 @@ from sn_basis.ui.base_dockwidget import BaseDockWidget
|
|||||||
|
|
||||||
|
|
||||||
class DockWidget(BaseDockWidget):
|
class DockWidget(BaseDockWidget):
|
||||||
tabs = [TabA, TabB, SettingsTab]
|
tabs = [TabA, SettingsTab]
|
||||||
|
|||||||
140
ui/tabs/Verfahrensgebiet.qml
Normal file
140
ui/tabs/Verfahrensgebiet.qml
Normal file
@@ -0,0 +1,140 @@
|
|||||||
|
<!DOCTYPE qgis PUBLIC 'http://mrcc.com/qgis.dtd' 'SYSTEM'>
|
||||||
|
<qgis version="3.40.7-Bratislava" styleCategories="Symbology">
|
||||||
|
<renderer-v2 referencescale="-1" forceraster="0" enableorderby="0" type="singleSymbol" symbollevels="0">
|
||||||
|
<symbols>
|
||||||
|
<symbol is_animated="0" frame_rate="10" clip_to_extent="1" type="fill" alpha="1" force_rhr="0" name="0">
|
||||||
|
<data_defined_properties>
|
||||||
|
<Option type="Map">
|
||||||
|
<Option type="QString" value="" name="name"/>
|
||||||
|
<Option name="properties"/>
|
||||||
|
<Option type="QString" value="collection" name="type"/>
|
||||||
|
</Option>
|
||||||
|
</data_defined_properties>
|
||||||
|
<layer locked="0" id="{feca00b2-500a-4c9a-b285-67ba2d99d8f6}" enabled="1" class="SimpleLine" pass="0">
|
||||||
|
<Option type="Map">
|
||||||
|
<Option type="QString" value="0" name="align_dash_pattern"/>
|
||||||
|
<Option type="QString" value="square" name="capstyle"/>
|
||||||
|
<Option type="QString" value="5;2" name="customdash"/>
|
||||||
|
<Option type="QString" value="3x:0,0,0,0,0,0" name="customdash_map_unit_scale"/>
|
||||||
|
<Option type="QString" value="MM" name="customdash_unit"/>
|
||||||
|
<Option type="QString" value="0" name="dash_pattern_offset"/>
|
||||||
|
<Option type="QString" value="3x:0,0,0,0,0,0" name="dash_pattern_offset_map_unit_scale"/>
|
||||||
|
<Option type="QString" value="MM" name="dash_pattern_offset_unit"/>
|
||||||
|
<Option type="QString" value="0" name="draw_inside_polygon"/>
|
||||||
|
<Option type="QString" value="round" name="joinstyle"/>
|
||||||
|
<Option type="QString" value="215,168,255,255,rgb:0.84313725490196079,0.6588235294117647,1,1" name="line_color"/>
|
||||||
|
<Option type="QString" value="solid" name="line_style"/>
|
||||||
|
<Option type="QString" value="1.5" name="line_width"/>
|
||||||
|
<Option type="QString" value="MM" name="line_width_unit"/>
|
||||||
|
<Option type="QString" value="-0.75" name="offset"/>
|
||||||
|
<Option type="QString" value="3x:0,0,0,0,0,0" name="offset_map_unit_scale"/>
|
||||||
|
<Option type="QString" value="MM" name="offset_unit"/>
|
||||||
|
<Option type="QString" value="0" name="ring_filter"/>
|
||||||
|
<Option type="QString" value="0" name="trim_distance_end"/>
|
||||||
|
<Option type="QString" value="3x:0,0,0,0,0,0" name="trim_distance_end_map_unit_scale"/>
|
||||||
|
<Option type="QString" value="MM" name="trim_distance_end_unit"/>
|
||||||
|
<Option type="QString" value="0" name="trim_distance_start"/>
|
||||||
|
<Option type="QString" value="3x:0,0,0,0,0,0" name="trim_distance_start_map_unit_scale"/>
|
||||||
|
<Option type="QString" value="MM" name="trim_distance_start_unit"/>
|
||||||
|
<Option type="QString" value="0" name="tweak_dash_pattern_on_corners"/>
|
||||||
|
<Option type="QString" value="0" name="use_custom_dash"/>
|
||||||
|
<Option type="QString" value="3x:0,0,0,0,0,0" name="width_map_unit_scale"/>
|
||||||
|
</Option>
|
||||||
|
<data_defined_properties>
|
||||||
|
<Option type="Map">
|
||||||
|
<Option type="QString" value="" name="name"/>
|
||||||
|
<Option name="properties"/>
|
||||||
|
<Option type="QString" value="collection" name="type"/>
|
||||||
|
</Option>
|
||||||
|
</data_defined_properties>
|
||||||
|
</layer>
|
||||||
|
<layer locked="0" id="{fdc4d6fd-0995-41df-bbfb-19970b4fc2cc}" enabled="1" class="SimpleLine" pass="0">
|
||||||
|
<Option type="Map">
|
||||||
|
<Option type="QString" value="0" name="align_dash_pattern"/>
|
||||||
|
<Option type="QString" value="square" name="capstyle"/>
|
||||||
|
<Option type="QString" value="5;2" name="customdash"/>
|
||||||
|
<Option type="QString" value="3x:0,0,0,0,0,0" name="customdash_map_unit_scale"/>
|
||||||
|
<Option type="QString" value="MM" name="customdash_unit"/>
|
||||||
|
<Option type="QString" value="0" name="dash_pattern_offset"/>
|
||||||
|
<Option type="QString" value="3x:0,0,0,0,0,0" name="dash_pattern_offset_map_unit_scale"/>
|
||||||
|
<Option type="QString" value="MM" name="dash_pattern_offset_unit"/>
|
||||||
|
<Option type="QString" value="0" name="draw_inside_polygon"/>
|
||||||
|
<Option type="QString" value="round" name="joinstyle"/>
|
||||||
|
<Option type="QString" value="204,174,137,255,rgb:0.80000000000000004,0.68235294117647061,0.53725490196078429,1" name="line_color"/>
|
||||||
|
<Option type="QString" value="solid" name="line_style"/>
|
||||||
|
<Option type="QString" value="0.5" name="line_width"/>
|
||||||
|
<Option type="QString" value="MM" name="line_width_unit"/>
|
||||||
|
<Option type="QString" value="0" name="offset"/>
|
||||||
|
<Option type="QString" value="3x:0,0,0,0,0,0" name="offset_map_unit_scale"/>
|
||||||
|
<Option type="QString" value="MM" name="offset_unit"/>
|
||||||
|
<Option type="QString" value="0" name="ring_filter"/>
|
||||||
|
<Option type="QString" value="0" name="trim_distance_end"/>
|
||||||
|
<Option type="QString" value="3x:0,0,0,0,0,0" name="trim_distance_end_map_unit_scale"/>
|
||||||
|
<Option type="QString" value="MM" name="trim_distance_end_unit"/>
|
||||||
|
<Option type="QString" value="0" name="trim_distance_start"/>
|
||||||
|
<Option type="QString" value="3x:0,0,0,0,0,0" name="trim_distance_start_map_unit_scale"/>
|
||||||
|
<Option type="QString" value="MM" name="trim_distance_start_unit"/>
|
||||||
|
<Option type="QString" value="0" name="tweak_dash_pattern_on_corners"/>
|
||||||
|
<Option type="QString" value="0" name="use_custom_dash"/>
|
||||||
|
<Option type="QString" value="3x:0,0,0,0,0,0" name="width_map_unit_scale"/>
|
||||||
|
</Option>
|
||||||
|
<data_defined_properties>
|
||||||
|
<Option type="Map">
|
||||||
|
<Option type="QString" value="" name="name"/>
|
||||||
|
<Option name="properties"/>
|
||||||
|
<Option type="QString" value="collection" name="type"/>
|
||||||
|
</Option>
|
||||||
|
</data_defined_properties>
|
||||||
|
</layer>
|
||||||
|
</symbol>
|
||||||
|
</symbols>
|
||||||
|
<rotation/>
|
||||||
|
<sizescale/>
|
||||||
|
<data-defined-properties>
|
||||||
|
<Option type="Map">
|
||||||
|
<Option type="QString" value="" name="name"/>
|
||||||
|
<Option name="properties"/>
|
||||||
|
<Option type="QString" value="collection" name="type"/>
|
||||||
|
</Option>
|
||||||
|
</data-defined-properties>
|
||||||
|
</renderer-v2>
|
||||||
|
<selection mode="Default">
|
||||||
|
<selectionColor invalid="1"/>
|
||||||
|
<selectionSymbol>
|
||||||
|
<symbol is_animated="0" frame_rate="10" clip_to_extent="1" type="fill" alpha="1" force_rhr="0" name="">
|
||||||
|
<data_defined_properties>
|
||||||
|
<Option type="Map">
|
||||||
|
<Option type="QString" value="" name="name"/>
|
||||||
|
<Option name="properties"/>
|
||||||
|
<Option type="QString" value="collection" name="type"/>
|
||||||
|
</Option>
|
||||||
|
</data_defined_properties>
|
||||||
|
<layer locked="0" id="{f18003f5-220a-487f-8a6d-b24facc4c1a5}" enabled="1" class="SimpleFill" pass="0">
|
||||||
|
<Option type="Map">
|
||||||
|
<Option type="QString" value="3x:0,0,0,0,0,0" name="border_width_map_unit_scale"/>
|
||||||
|
<Option type="QString" value="0,0,255,255,rgb:0,0,1,1" name="color"/>
|
||||||
|
<Option type="QString" value="bevel" name="joinstyle"/>
|
||||||
|
<Option type="QString" value="0,0" name="offset"/>
|
||||||
|
<Option type="QString" value="3x:0,0,0,0,0,0" name="offset_map_unit_scale"/>
|
||||||
|
<Option type="QString" value="MM" name="offset_unit"/>
|
||||||
|
<Option type="QString" value="35,35,35,255,rgb:0.13725490196078433,0.13725490196078433,0.13725490196078433,1" name="outline_color"/>
|
||||||
|
<Option type="QString" value="solid" name="outline_style"/>
|
||||||
|
<Option type="QString" value="0.26" name="outline_width"/>
|
||||||
|
<Option type="QString" value="MM" name="outline_width_unit"/>
|
||||||
|
<Option type="QString" value="solid" name="style"/>
|
||||||
|
</Option>
|
||||||
|
<data_defined_properties>
|
||||||
|
<Option type="Map">
|
||||||
|
<Option type="QString" value="" name="name"/>
|
||||||
|
<Option name="properties"/>
|
||||||
|
<Option type="QString" value="collection" name="type"/>
|
||||||
|
</Option>
|
||||||
|
</data_defined_properties>
|
||||||
|
</layer>
|
||||||
|
</symbol>
|
||||||
|
</selectionSymbol>
|
||||||
|
</selection>
|
||||||
|
<blendMode>0</blendMode>
|
||||||
|
<featureBlendMode>0</featureBlendMode>
|
||||||
|
<layerGeometryType>2</layerGeometryType>
|
||||||
|
</qgis>
|
||||||
@@ -1,12 +1,98 @@
|
|||||||
from qgis.PyQt.QtWidgets import QWidget, QVBoxLayout, QLabel, QLineEdit
|
from qgis.PyQt.QtWidgets import QWidget, QVBoxLayout, QHBoxLayout, QLabel, QPushButton, QMessageBox
|
||||||
|
from qgis.PyQt.QtGui import QIcon, QPixmap
|
||||||
|
from qgis.PyQt.QtCore import Qt, QTimer
|
||||||
|
from qgis.core import Qgis, QgsProject, QgsMessageLog
|
||||||
|
from qgis.utils import iface
|
||||||
|
import os
|
||||||
|
|
||||||
|
from sn_verfahrensgebiet.logic.alkis_verfahrensgebiet import alkis_verfahrensgebiet
|
||||||
|
from sn_basis.logic.utils import zoom_to_layer
|
||||||
|
|
||||||
class TabA(QWidget):
|
class TabA(QWidget):
|
||||||
tab_title = "Tab A"
|
tab_title = "Bearbeitung"
|
||||||
|
|
||||||
def __init__(self, parent=None):
|
def __init__(self, parent=None):
|
||||||
super().__init__(parent)
|
super().__init__(parent)
|
||||||
|
|
||||||
layout = QVBoxLayout()
|
layout = QVBoxLayout()
|
||||||
layout.addWidget(QLabel("Plugin1 – Tab A"))
|
layout.setAlignment(Qt.AlignmentFlag.AlignTop)
|
||||||
layout.addWidget(QLineEdit("Feld A1"))
|
|
||||||
layout.addWidget(QLineEdit("Feld A2"))
|
# Abschnitt 1: Verfahrensgebiet
|
||||||
|
row_verf_header = QHBoxLayout()
|
||||||
|
lbl_verf = QLabel("<b>Verfahrensgebiet</b>")
|
||||||
|
self.haken1 = self._haken_label()
|
||||||
|
row_verf_header.addWidget(lbl_verf)
|
||||||
|
row_verf_header.addWidget(self.haken1)
|
||||||
|
row_verf_header.addStretch()
|
||||||
|
layout.addLayout(row_verf_header)
|
||||||
|
|
||||||
|
row_verf_buttons = QHBoxLayout()
|
||||||
|
self.btn_verf_alkis = QPushButton("Aus ALKIS laden")
|
||||||
|
self.btn_verf_shape = QPushButton("Aus Shape laden")
|
||||||
|
row_verf_buttons.addWidget(self.btn_verf_alkis)
|
||||||
|
row_verf_buttons.addWidget(self.btn_verf_shape)
|
||||||
|
layout.addLayout(row_verf_buttons)
|
||||||
|
|
||||||
|
# Abschnitt 2: Flurstücke
|
||||||
|
row_flurst_header = QHBoxLayout()
|
||||||
|
lbl_flurst = QLabel("<b>Flurstücke</b>")
|
||||||
|
self.haken2 = self._haken_label()
|
||||||
|
row_flurst_header.addWidget(lbl_flurst)
|
||||||
|
row_flurst_header.addWidget(self.haken2)
|
||||||
|
row_flurst_header.addStretch()
|
||||||
|
layout.addLayout(row_flurst_header)
|
||||||
|
|
||||||
|
row_flurst_buttons = QHBoxLayout()
|
||||||
|
self.btn_flurst_alkis = QPushButton("Aus ALKIS laden")
|
||||||
|
self.btn_flurst_shape = QPushButton("Aus Shape laden")
|
||||||
|
row_flurst_buttons.addWidget(self.btn_flurst_alkis)
|
||||||
|
row_flurst_buttons.addWidget(self.btn_flurst_shape)
|
||||||
|
layout.addLayout(row_flurst_buttons)
|
||||||
|
|
||||||
|
layout.addStretch()
|
||||||
self.setLayout(layout)
|
self.setLayout(layout)
|
||||||
|
|
||||||
|
# Beispiel: Haken anzeigen nach Klick
|
||||||
|
# self.button1.clicked.connect(lambda: alkis_verfahrensgebiet(self))
|
||||||
|
self.btn_verf_alkis.clicked.connect(lambda: self.handle_button1())
|
||||||
|
|
||||||
|
#self.button2.clicked.connect(lambda: self.setze_haken(self.haken2, True))
|
||||||
|
|
||||||
|
def handle_button1(self):
|
||||||
|
layer, neu_geladen = alkis_verfahrensgebiet(self)
|
||||||
|
|
||||||
|
if not layer or not layer.isValid():
|
||||||
|
return
|
||||||
|
|
||||||
|
if neu_geladen:
|
||||||
|
QgsProject.instance().addMapLayer(layer)
|
||||||
|
iface.mapCanvas().setExtent(layer.extent())
|
||||||
|
iface.mapCanvas().refresh()
|
||||||
|
# Beispiel: Haken setzen oder Meldung ausgeben
|
||||||
|
self.setze_haken(self.haken1, True)
|
||||||
|
# QMessageBox.information(self, "Info", "Layer 'Verfahrensgebiet' wurde neu geladen.")
|
||||||
|
else:
|
||||||
|
# Kein Zoom, kein Neu-Laden
|
||||||
|
QgsMessageLog.logMessage("Vorhandener Layer behalten.", "sn_verfahrensgebiet", level=Qgis.Info)
|
||||||
|
|
||||||
|
|
||||||
|
def _haken_label(self):
|
||||||
|
label = QLabel()
|
||||||
|
label.setFixedSize(20, 20)
|
||||||
|
# label.setAlignment(Qt.AlignCenter)
|
||||||
|
label.setAlignment(Qt.AlignmentFlag.AlignCenter)
|
||||||
|
label.setScaledContents(False)
|
||||||
|
label.setText("")
|
||||||
|
return label
|
||||||
|
|
||||||
|
def setze_haken(self, label: QLabel, aktiv: bool):
|
||||||
|
"""Zeigt oder entfernt den grünen Haken."""
|
||||||
|
if aktiv:
|
||||||
|
# grünes Unicode-Häkchen
|
||||||
|
label.setPixmap(QPixmap())
|
||||||
|
label.setText("✓")
|
||||||
|
label.setStyleSheet("color: #2ea043; font-weight: bold;")
|
||||||
|
else:
|
||||||
|
label.setPixmap(QPixmap())
|
||||||
|
label.setText("")
|
||||||
|
label.setStyleSheet("")
|
||||||
|
|||||||
Reference in New Issue
Block a user