Skip to content

Commit

Permalink
Add new feature: Calculation of LongestFlowPath for sub-basins
Browse files Browse the repository at this point in the history
  • Loading branch information
lorenz3tla committed Aug 15, 2024
1 parent 6a58db6 commit 484dd45
Show file tree
Hide file tree
Showing 5 changed files with 739 additions and 5 deletions.
23 changes: 22 additions & 1 deletion QTalsim/qtalsim.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,14 @@
"""
from qgis.PyQt.QtCore import QSettings, QTranslator, QCoreApplication, Qt
from qgis.PyQt.QtGui import QIcon, QCursor, QMovie
from qgis.PyQt.QtWidgets import QAction, QTableWidgetItem, QComboBox, QFileDialog, QInputDialog, QDialogButtonBox, QCompleter, QAbstractItemView, QRadioButton, QMenu, QToolButton, QDockWidget, QMessageBox, QApplication, QDialog
from qgis.PyQt.QtWidgets import QMainWindow, QAction, QTableWidgetItem, QComboBox, QFileDialog, QInputDialog, QDialogButtonBox, QCompleter, QAbstractItemView, QRadioButton, QMenu, QToolButton, QDockWidget, QMessageBox, QApplication, QDialog
from qgis.PyQt.QtCore import QVariant, QTimer, pyqtSignal
# Initialize Qt resources from file resources.py
from .resources import *
# Import the code for the dialog
from .qtalsim_dialog import QTalsimDialog
from .qtalsim_sqllite_dialog import SQLConnectDialog
from .qtalsim_subbasin_dialog import SubBasinPreprocessingDialog
import os.path
from qgis.core import QgsProject, QgsField, QgsVectorLayer, QgsRasterLayer, QgsFeature, QgsGeometry, QgsSpatialIndex, Qgis, QgsMessageLog, QgsLayerTreeGroup, QgsLayerTreeLayer, QgsProcessingFeedback, QgsWkbTypes, QgsFeatureRequest, QgsMapLayer, QgsFields, QgsTask, QgsTaskManager, QgsApplication, QgsExpression
from qgis.analysis import QgsGeometrySnapper
Expand Down Expand Up @@ -269,6 +270,8 @@ def initGui(self):
self.add_action(icon_path, text=self.tr(u'HRU calculation'), callback=self.run, parent=self.iface.mainWindow(), add_to_toolbar=True)
#self.add_action(icon_path, text=self.tr(u'Connect to Talsim DB'), callback=self.open_secondary_window, parent=self.iface.mainWindow(), add_to_toolbar=True)
self.add_action(icon_path, text=self.tr(u'Connect to Talsim DB'), callback=self.open_sql_connect_dock, parent=self.iface.mainWindow(), add_to_toolbar=True)
self.add_action(icon_path, text=self.tr(u'Sub-basin preprocessing'), callback=self.open_sub_basin_window, parent=self.iface.mainWindow(), add_to_toolbar=True)

self.first_start = True
self.initialize_parameters()

Expand Down Expand Up @@ -3552,7 +3555,25 @@ def open_sql_connect_dock(self):

def onDockDestroyed(self, obj=None):
self.sqlConnectDock = None

def open_sub_basin_window(self):
if self.first_start:
self.first_start = False
if not hasattr(self, 'subBasinWindow'):
self.subBasinWindow = QMainWindow(self.iface.mainWindow())

self.subBasinDialog = SubBasinPreprocessingDialog(self.iface.mainWindow(), self)
self.subBasinWindow.setCentralWidget(self.subBasinDialog)
#self.iface.mainWindow().addDockWidget(Qt.RightDockWidgetArea, self.subBasinWindow)
else:
self.subBasinDialog.initialize_parameters()

self.subBasinWindow.raise_()
self.subBasinWindow.show()
self.subBasinWindow.destroyed.connect(self.onWindowDestroyed)

def onWindowDestroyed(self, obj=None):
self.subBasinWindow = None
'''
Custom Dock Widget for 'Connect to Talsim DB' to overwrite the closeEvent-Action with a custom function.
'''
Expand Down
2 changes: 1 addition & 1 deletion QTalsim/qtalsim_sqllite_dialog.py
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ def fillPolygonsCombobox(self):
Fills the combobox of external sub-basins with all polygon layers in the project.
'''
#Get Layers
polygonLayers = self.getAllLayers(QgsProject.instance().layerTreeRoot())
polygonLayers, _ = self.getAllLayers(QgsProject.instance().layerTreeRoot())

self.comboboxPolygonLayer.clear() #clear combobox EZG from previous runs

Expand Down
296 changes: 296 additions & 0 deletions QTalsim/qtalsim_subbasin.ui
Original file line number Diff line number Diff line change
@@ -0,0 +1,296 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>Dialog</class>
<widget class="QDialog" name="Dialog">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>539</width>
<height>301</height>
</rect>
</property>
<property name="windowTitle">
<string>Dialog</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<layout class="QVBoxLayout" name="verticalLayout_2">
<item>
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<widget class="QLabel" name="labelSubBasin">
<property name="minimumSize">
<size>
<width>200</width>
<height>0</height>
</size>
</property>
<property name="maximumSize">
<size>
<width>200</width>
<height>200</height>
</size>
</property>
<property name="text">
<string>Select Sub-basin Layer</string>
</property>
</widget>
</item>
<item>
<widget class="QComboBox" name="comboboxSubBasinLayer">
<property name="sizePolicy">
<sizepolicy hsizetype="MinimumExpanding" vsizetype="Fixed">
<horstretch>10</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="minimumSize">
<size>
<width>0</width>
<height>0</height>
</size>
</property>
<property name="sizeIncrement">
<size>
<width>500</width>
<height>0</height>
</size>
</property>
<property name="baseSize">
<size>
<width>500</width>
<height>0</height>
</size>
</property>
</widget>
</item>
</layout>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_4">
<item>
<spacer name="horizontalSpacer_2">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeType">
<enum>QSizePolicy::Minimum</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>10</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QLabel" name="label">
<property name="sizePolicy">
<sizepolicy hsizetype="MinimumExpanding" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="minimumSize">
<size>
<width>200</width>
<height>0</height>
</size>
</property>
<property name="font">
<font>
<pointsize>7</pointsize>
</font>
</property>
<property name="text">
<string>Select Unique Identifier Field</string>
</property>
</widget>
</item>
<item>
<widget class="QComboBox" name="comboboxUISubBasin">
<property name="sizePolicy">
<sizepolicy hsizetype="MinimumExpanding" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
</widget>
</item>
</layout>
</item>
</layout>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_2">
<item>
<widget class="QLabel" name="labelDEM">
<property name="minimumSize">
<size>
<width>200</width>
<height>0</height>
</size>
</property>
<property name="text">
<string>Select DEM Layer</string>
</property>
</widget>
</item>
<item>
<widget class="QComboBox" name="comboboxDEMLayer">
<property name="sizePolicy">
<sizepolicy hsizetype="MinimumExpanding" vsizetype="Fixed">
<horstretch>10</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
</widget>
</item>
</layout>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_3">
<item>
<widget class="QLabel" name="labelWaterNetwork">
<property name="minimumSize">
<size>
<width>200</width>
<height>0</height>
</size>
</property>
<property name="text">
<string>Select Water Network Layer</string>
</property>
</widget>
</item>
<item>
<widget class="QComboBox" name="comboboxWaterNetwork">
<property name="sizePolicy">
<sizepolicy hsizetype="MinimumExpanding" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
</widget>
</item>
</layout>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_5">
<item>
<widget class="QTextEdit" name="outputPath">
<property name="sizePolicy">
<sizepolicy hsizetype="MinimumExpanding" vsizetype="MinimumExpanding">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="minimumSize">
<size>
<width>0</width>
<height>40</height>
</size>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="onOutputFolder">
<property name="text">
<string>Select Output-Folder</string>
</property>
</widget>
</item>
</layout>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_6">
<item>
<spacer name="horizontalSpacer">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QPushButton" name="onRun">
<property name="sizePolicy">
<sizepolicy hsizetype="MinimumExpanding" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>Run</string>
</property>
</widget>
</item>
<item>
<widget class="QDialogButtonBox" name="finalButtonBox">
<property name="sizePolicy">
<sizepolicy hsizetype="MinimumExpanding" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="minimumSize">
<size>
<width>20</width>
<height>0</height>
</size>
</property>
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="standardButtons">
<set>QDialogButtonBox::Help</set>
</property>
</widget>
</item>
</layout>
</item>
</layout>
</widget>
<resources/>
<connections>
<connection>
<sender>finalButtonBox</sender>
<signal>accepted()</signal>
<receiver>Dialog</receiver>
<slot>accept()</slot>
<hints>
<hint type="sourcelabel">
<x>248</x>
<y>254</y>
</hint>
<hint type="destinationlabel">
<x>157</x>
<y>274</y>
</hint>
</hints>
</connection>
<connection>
<sender>finalButtonBox</sender>
<signal>rejected()</signal>
<receiver>Dialog</receiver>
<slot>reject()</slot>
<hints>
<hint type="sourcelabel">
<x>316</x>
<y>260</y>
</hint>
<hint type="destinationlabel">
<x>286</x>
<y>274</y>
</hint>
</hints>
</connection>
</connections>
</ui>
Loading

0 comments on commit 484dd45

Please sign in to comment.