Skip to content

Commit

Permalink
styling en views omzetten naar tabellen
Browse files Browse the repository at this point in the history
  • Loading branch information
leendertvanwolfswinkel committed May 17, 2022
1 parent 33cbfad commit ab3a869
Show file tree
Hide file tree
Showing 14 changed files with 2,251 additions and 33 deletions.
66 changes: 50 additions & 16 deletions afkoppelkansenkaart/afkoppelkansenkaart_dockwidget.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@

import db_manager.db_plugins.postgis.connector as con
from qgis.PyQt import QtGui, QtWidgets, uic
from qgis.PyQt.QtWidgets import QProgressBar, QFileDialog
from qgis.PyQt.QtWidgets import QApplication, QProgressBar, QFileDialog
from qgis.PyQt.QtCore import pyqtSignal, QSettings
from qgis.core import (
NULL,
Expand All @@ -50,7 +50,7 @@

FORM_CLASS, _ = uic.loadUiType(os.path.join(
os.path.dirname(__file__), 'afkoppelkansenkaart_dockwidget_base.ui'))

STYLE_DIR = Path(__file__).parent / "style"

class AfkoppelKansenKaartDockWidget(QtWidgets.QDockWidget,FORM_CLASS):
closingPlugin=pyqtSignal()
Expand All @@ -69,6 +69,7 @@ def __init__(self,parent, provider):

self.pushButton_Nieuw.clicked.connect(self.nieuw_clicked)
self.pushButton_Open.clicked.connect(self.open_clicked)
self.pushButton_Verwerk.clicked.connect(self.verwerk_clicked)
self.pushButton_PercelenWFS.clicked.connect(self.add_parcel_wfs)
self.comboBox_PostGISDatabases.currentIndexChanged.connect(self.update_postgis_connection_status)
self.populate_combobox_postgis_databases()
Expand Down Expand Up @@ -101,14 +102,14 @@ def parcel_layer_id(self, id: str):
@property
def layer_group(self):
root = QgsProject.instance().layerTreeRoot()
result = root.findGroup('Afkoppelkansenkaart')
result = root.findGroup('Afkoppelrendementskaart')
if not result:
result = root.insertGroup(0, 'Afkoppelkansenkaart')
result = root.insertGroup(0, 'Afkoppelrendementskaart')
return result

def add_to_layer_tree_group(self, layer):
"""
Add a layer to the Afkoppelkansenkaart layer tree group
Add a layer to the Afkoppelrendementskaart layer tree group
"""
project = QgsProject.instance()
project.addMapLayer(layer, addToLegend=False)
Expand Down Expand Up @@ -141,52 +142,85 @@ def populate_combobox_bewerkingen(self, algos):
self.update_bewerking(0)

def nieuw_clicked(self):
filename, _ = QFileDialog.getSaveFileName(self, "Nieuwe afkoppelkansenkaart", "", "GeoPackage (*.gpkg)")
filename, _ = QFileDialog.getSaveFileName(self, "Nieuwe afkoppelrendementskaart", "", "GeoPackage (*.gpkg)")
if filename:
iface.messageBar().pushMessage(
MESSAGE_CATEGORY,
f"Afkoppelkansenkaart geopackage aangemaakt! ({filename})",
f"Afkoppelrendementskaart geopackage aangemaakt! ({filename})",
level=Qgis.Success,
duration=10
)
self.db = AfkoppelKansenKaartDatabase()
self.db.create_datasource(filename)
self.db.epsg = 28992
self.db.create_schema_and_initialise()
self.add_afkoppelkansenkaart_layer()
self.add_layers_to_project()
self.check_bewerkingen_ui()

def open_clicked(self):
filename, _ = QFileDialog.getOpenFileName(self, "Nieuwe afkoppelkansenkaart", "", "GeoPackage (*.gpkg)")
filename, _ = QFileDialog.getOpenFileName(self, "Open afkoppelrendementskaart", "", "GeoPackage (*.gpkg)")
if filename:
if self.db:
if filename == self.db.gpkg_path:
iface.messageBar().pushMessage(
MESSAGE_CATEGORY,
f"Deze afkoppelkansenkaart was reeds geopend. ({filename})",
f"Deze afkoppelrendementskaart was reeds geopend. ({filename})",
level=Qgis.Info,
duration=10
)
return
self.db = AfkoppelKansenKaartDatabase()
self.db.set_datasource(filename)
self.db.epsg = 28992
iface.messageBar().pushMessage(
MESSAGE_CATEGORY,
f"Afkoppelkansenkaart geopend. ({filename})",
f"Afkoppelrendementskaart geopend. ({filename})",
level=Qgis.Info,
duration=10
)
self.add_afkoppelkansenkaart_layer()
self.add_layers_to_project()
self.check_bewerkingen_ui()

def add_afkoppelkansenkaart_layer(self):
def verwerk_clicked(self):
if self.db:
iface.messageBar().pushMessage(
MESSAGE_CATEGORY,
f"Wijzigingen verwerken... (dit kan enkele minuten duren)",
level=Qgis.Info,
duration=0
)
QApplication.processEvents()
self.db.process_changes()
iface.messageBar().clearWidgets()
iface.messageBar().pushMessage(
MESSAGE_CATEGORY,
f"Wijzigingen verwerkt!",
level=Qgis.Success,
duration=3
)
else:
iface.messageBar().pushMessage(
MESSAGE_CATEGORY,
f"Open eerst een afkoppelrendementskaart geopackage!",
level=Qgis.Warning,
duration=10
)


def add_layers_to_project(self):
if self.db.gpkg_path:
layer = QgsVectorLayer(str(self.db.gpkg_path) + "|layername=afkoppelkansenkaart", "Afkoppelkansenkaart")
self.add_to_layer_tree_group(layer=layer)
for sub_group in LAYERS_TO_LOAD.values():
for layer_name in sub_group:
layer = QgsVectorLayer(
str(self.db.gpkg_path) + f"|layername={layer_name}",
layer_name.replace("_", " ").capitalize()
)
layer.loadNamedStyle(str(STYLE_DIR / f"{layer_name}.qml"))
self.add_to_layer_tree_group(layer=layer)
else:
iface.messageBar().pushMessage(
MESSAGE_CATEGORY,
"Laad eerst een afkoppelkansenkaart in",
"Laad eerst een afkoppelrendementskaart in",
level=Qgis.Info,
duration=3
)
Expand Down
37 changes: 33 additions & 4 deletions afkoppelkansenkaart/afkoppelkansenkaart_dockwidget_base.ui
Original file line number Diff line number Diff line change
Expand Up @@ -98,11 +98,14 @@
<string notr="true">color: rgb(170, 255, 255);</string>
</property>
<property name="title">
<string>Afkoppelrendementskaart</string>
<string>Geopackage</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout_5">
<item>
<widget class="QPushButton" name="pushButton_Nieuw">
<property name="toolTip">
<string>Maak een nieuwe afkoppelrendementskaart geopackage aan</string>
</property>
<property name="styleSheet">
<string notr="true">background-color: rgb(170, 255, 255);
color: rgb(0, 0, 0);</string>
Expand All @@ -114,6 +117,9 @@ color: rgb(0, 0, 0);</string>
</item>
<item>
<widget class="QPushButton" name="pushButton_Open">
<property name="toolTip">
<string>Open een bestaande afkoppelrendementskaart geopackage</string>
</property>
<property name="styleSheet">
<string notr="true">background-color: rgb(170, 255, 255);
color: rgb(0, 0, 0);</string>
Expand All @@ -123,6 +129,20 @@ color: rgb(0, 0, 0);</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="pushButton_Verwerk">
<property name="toolTip">
<string>Genereer resultaten opnieuw na aanpassingen aan de criteria, weging, buurten en wijken</string>
</property>
<property name="styleSheet">
<string notr="true">background-color: rgb(170, 255, 255);
color: rgb(0, 0, 0);</string>
</property>
<property name="text">
<string>Verwerk aanpassingen</string>
</property>
</widget>
</item>
</layout>
</widget>
</item>
Expand Down Expand Up @@ -188,12 +208,12 @@ color: rgb(0, 0, 0);</string>
</size>
</property>
<property name="styleSheet">
<string notr="true">QgsCollapsibleGroupBoxBasic::title, QgsCollapsibleGroupBox::title { subcontrol-origin: margin; subcontrol-position: top left; margin-left: 20px; margin-right: 5px; left: 0px; top: 1px;color: rgb(170, 255, 255)}QgsCollapsibleGroupBoxBasic::title, QgsCollapsibleGroupBox::title { subcontrol-origin: margin; subcontrol-position: top left; margin-left: 20px; margin-right: 5px; left: 0px; top: 1px;}QgsCollapsibleGroupBoxBasic::title, QgsCollapsibleGroupBox::title { subcontrol-origin: margin; subcontrol-position: top left; margin-left: 20px; margin-right: 5px; left: 0px; top: 1px;}QgsCollapsibleGroupBoxBasic::title, QgsCollapsibleGroupBox::title { subcontrol-origin: margin; subcontrol-position: top left; margin-left: 20px; margin-right: 5px; left: 0px; top: 1px;}</string>
<string notr="true">QgsCollapsibleGroupBoxBasic::title, QgsCollapsibleGroupBox::title { subcontrol-origin: margin; subcontrol-position: top left; margin-left: 20px; margin-right: 5px; left: 0px; top: 1px;color: rgb(170, 255, 255)}QgsCollapsibleGroupBoxBasic::title, QgsCollapsibleGroupBox::title { subcontrol-origin: margin; subcontrol-position: top left; margin-left: 20px; margin-right: 5px; left: 0px; top: 1px;}QgsCollapsibleGroupBoxBasic::title, QgsCollapsibleGroupBox::title { subcontrol-origin: margin; subcontrol-position: top left; margin-left: 20px; margin-right: 5px; left: 0px; top: 1px;}QgsCollapsibleGroupBoxBasic::title, QgsCollapsibleGroupBox::title { subcontrol-origin: margin; subcontrol-position: top left; margin-left: 20px; margin-right: 5px; left: 0px; top: 1px;}QgsCollapsibleGroupBoxBasic::title, QgsCollapsibleGroupBox::title { subcontrol-origin: margin; subcontrol-position: top left; margin-left: 20px; margin-right: 5px; left: 0px; top: 1px;}</string>
</property>
<property name="title">
<string>PostGIS Database</string>
</property>
<property name="collapsed" stdset="0">
<property name="collapsed">
<bool>false</bool>
</property>
<layout class="QVBoxLayout" name="verticalLayout_3">
Expand All @@ -219,6 +239,9 @@ color: rgb(0, 0, 0);</string>
<height>16777215</height>
</size>
</property>
<property name="toolTip">
<string>Ververs de lijst met PostGIS databases</string>
</property>
<property name="styleSheet">
<string notr="true">background-color: rgb(170, 255, 255);
color: rgb(0, 0, 0);</string>
Expand Down Expand Up @@ -275,12 +298,15 @@ color: rgb(0, 0, 0);</string>
<height>28</height>
</size>
</property>
<property name="toolTip">
<string>Laad de 'perceel'-laag uit de PostGIS database (opnieuw) in</string>
</property>
<property name="styleSheet">
<string notr="true">background-color: rgb(170, 255, 255);
color: rgb(0, 0, 0);</string>
</property>
<property name="text">
<string>Reload</string>
<string>Ververs</string>
</property>
</widget>
</item>
Expand Down Expand Up @@ -350,6 +376,9 @@ color: rgb(0, 0, 0);</string>
<pointsize>14</pointsize>
</font>
</property>
<property name="toolTip">
<string>Voer de geselecteerde bewerking uit</string>
</property>
<property name="styleSheet">
<string notr="true">:enabled{background-color: rgb(170, 255, 255)}
:disabled{background-color: rgb(0, 128, 128)}</string>
Expand Down
Binary file removed afkoppelkansenkaart/afkoppelrendementskaart.zip
Binary file not shown.
24 changes: 22 additions & 2 deletions afkoppelkansenkaart/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
PARCELS_WFS_URL = "pagingEnabled='true' restrictToRequestBBOX='1' srsname='EPSG:28992' typename='kadastralekaartv4:perceel' url='https://geodata.nationaalgeoregister.nl/kadastralekaart/wfs/v4_0' version='2.0.0'"
PARCEL_WFS_LAYER_NAME = "Kadastraal perceel (PDOK)"
PARCEL_POSTGIS_LAYER_NAME = "Perceel (PostGIS)"
MESSAGE_CATEGORY = 'Afkoppelkansenkaart'
MESSAGE_CATEGORY = 'Afkoppelrendementskaart'
SQL_DIR = os.path.join(os.path.dirname(__file__), 'sql')
BEWERKINGEN = [
'Percelen toevoegen',
Expand All @@ -18,4 +18,24 @@
'Belasting oppervlaktewater',
'Afstand tot RWZI',
'Aantal keer verpompen'
]
]
LAYERS_TO_LOAD = {
"Brongegevens": [
"perceel",
"buurt",
"wijk"
],
"Multi-criteria analyse": [
"score_zoektabel",
"criterium",
"domein",
"hoofdonderdeel",
"weging",
],
"Resultaten": [
"resultaat_buurt_eindscore",
"resultaat_wijk_eindscore",
"resultaat_afkoppelrendementskaart"
]
}

Loading

0 comments on commit ab3a869

Please sign in to comment.