Skip to content

Commit de3101f

Browse files
committed
change windows of sub-basin preprocessing, soil converter and land use mapping QMainWindow (no child)
1 parent eaacd65 commit de3101f

File tree

2 files changed

+28
-69
lines changed

2 files changed

+28
-69
lines changed

QTalsim/qtalsim.py

Lines changed: 20 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -808,10 +808,7 @@ def checkGaps(self, layer, extent):
808808
for feature in gapsLayer.getFeatures():
809809
feature['gapFeature'] = 1 # Set identifier
810810
gapsLayer.updateFeature(feature)
811-
gapsLayer.commitChanges()
812-
813-
self.log_to_qtalsim_tab("Existing gaps are represented in temporary layer 'Gaps'.",Qgis.Info)
814-
QgsProject.instance().addMapLayer(gapsLayer)
811+
gapsLayer.commitChanges()
815812

816813
return gapsLayer
817814

@@ -943,7 +940,7 @@ def clean_geometry(geom): #Function to clean the geometry as complex geometries
943940
'INPUT': merged_layer,
944941
'MODE': mode,
945942
'OUTPUT': 'TEMPORARY_OUTPUT'
946-
},feedback=self.feedback)
943+
}, feedback=self.feedback)
947944
layer_without_gaps = result_eliminate['OUTPUT']
948945

949946
layer_without_gaps, _ = self.make_geometries_valid(layer_without_gaps)
@@ -1739,7 +1736,9 @@ def checkGapsSoil(self):
17391736
self.log_to_qtalsim_tab("QTalsim is currently loading, checking for gaps in soil layer.", Qgis.Info)
17401737
self.start_operation()
17411738
self.soilGaps = self.checkGaps(self.soilLayerIntermediate, self.clippingEZG)
1742-
1739+
self.soilGaps.setName('GapsSoil')
1740+
QgsProject.instance().addMapLayer(self.soilGaps)
1741+
self.log_to_qtalsim_tab("Existing gaps are represented in temporary layer 'GapsSoil'.",Qgis.Info)
17431742
#Add checkmark when process is finished
17441743
current_text = self.dlg.onCheckGapsSoil.text()
17451744
if "✓" not in current_text: #Avoid duplicate checkmarks
@@ -2323,12 +2322,14 @@ def checkGapsLanduse(self):
23232322
Checks for gaps in the land use layer and adds a layer representing the gaps.
23242323
'''
23252324
try:
2326-
self.log_to_qtalsim_tab("QTalsim is currently loading, checking for gaps in soil layer.", Qgis.Info)
2325+
self.log_to_qtalsim_tab("QTalsim is currently loading, checking for gaps in land use layer.", Qgis.Info)
23272326
self.start_operation()
23282327
self.landuseGaps = self.checkGaps(self.landuseTalsim, self.clippingEZG)
2329-
2328+
self.landuseGaps.setName('GapsLanduse')
2329+
QgsProject.instance().addMapLayer(self.landuseGaps)
23302330
#Add checkmark when process is finished
23312331
current_text = self.dlg.onCheckGapsLanduse.text()
2332+
self.log_to_qtalsim_tab("Existing gaps are represented in temporary layer 'GapsLanduse'.", Qgis.Info)
23322333
if "✓" not in current_text: #Avoid duplicate checkmarks
23332334
self.dlg.onCheckGapsLanduse.setText(f"{current_text} ✓")
23342335
except Exception as e:
@@ -4409,55 +4410,10 @@ def run(self):
44094410
self.dlg.show()
44104411

44114412
#Run the dialog event loop
4412-
result = self.dlg.exec_()
4413+
#result = self.dlg.exec_()
44134414
if self.dialog_status == 'Reset':
44144415
return
44154416

4416-
#See if OK was pressed
4417-
'''
4418-
if result:
4419-
4420-
Saving to Geopackage.
4421-
4422-
try:
4423-
geopackage_name, ok = QInputDialog.getText(None, "GeoPackage Name", "Enter the name of the GeoPackage:")
4424-
self.geopackage_path = os.path.join(self.outputFolder, f"{geopackage_name}.gpkg")
4425-
self.start_operation()
4426-
self.log_to_qtalsim_tab(f"Saving the layers to {self.outputFolder}.", Qgis.Info)
4427-
def create_gpkg_save_layer(layer, gpkg_path, layer_name):
4428-
params = {
4429-
'INPUT': layer,
4430-
'OUTPUT': gpkg_path,
4431-
'LAYER_NAME': layer_name,
4432-
'OVERWRITE': True,
4433-
}
4434-
processing.run("native:savefeatures", params)
4435-
4436-
def add_layers_to_gpkg(layer, gpkg_path, layer_name):
4437-
params = {'INPUT': layer,
4438-
'OPTIONS': f'-update -nln {layer_name} -nlt MULTIPOLYGON', #added -nlt MULTIPOLYGON
4439-
'OUTPUT': gpkg_path}
4440-
processing.run("gdal:convertformat", params)
4441-
4442-
gpkg_path = self.geopackage_path
4443-
if os.path.exists(gpkg_path):
4444-
try:
4445-
os.remove(gpkg_path)
4446-
except Exception as e:
4447-
self.log_to_qtalsim_tab(f"Failed to delete existing GeoPackage: {e}",Qgis.Critical)
4448-
create_gpkg_save_layer(self.eflLayer, gpkg_path,'hru')
4449-
add_layers_to_gpkg(self.landuseFinal, gpkg_path, 'landuse')
4450-
add_layers_to_gpkg(self.soilTextureFinal, gpkg_path, 'soiltexture')
4451-
add_layers_to_gpkg(self.soilTypeFinal, gpkg_path, 'soiltype')
4452-
self.log_to_qtalsim_tab(f"File was saved to this folder: {self.outputFolder}", Qgis.Info)
4453-
4454-
except Exception as e:
4455-
self.log_to_qtalsim_tab(f"Error: {e}", Qgis.Critical)
4456-
4457-
finally:
4458-
self.end_operation()
4459-
'''
4460-
44614417
def open_sql_connect_dock(self):
44624418
'''
44634419
Method to open or show the SQL Connect dock.
@@ -4483,10 +4439,11 @@ def onDockDestroyed(self, obj=None):
44834439
def open_sub_basin_window(self):
44844440
if self.first_start:
44854441
self.first_start = False
4486-
if not hasattr(self, 'subBasinWindow'):
4487-
self.subBasinWindow = QMainWindow(self.iface.mainWindow())
4442+
if not hasattr(self, 'subBasinWindow') or self.subBasinWindow is None:
4443+
self.subBasinWindow = QMainWindow()
44884444
self.subBasinWindow.setWindowTitle("Sub-basin preprocessing")
4489-
self.subBasinDialog = SubBasinPreprocessingDialog(self.iface.mainWindow(), self)
4445+
self.subBasinWindow.setAttribute(Qt.WA_DeleteOnClose)
4446+
self.subBasinDialog = SubBasinPreprocessingDialog(self.subBasinWindow, self)
44904447
self.subBasinWindow.setCentralWidget(self.subBasinDialog)
44914448
else:
44924449
self.subBasinDialog.initialize_parameters()
@@ -4498,9 +4455,10 @@ def open_sub_basin_window(self):
44984455
def open_soil_window(self):
44994456
if self.first_start:
45004457
self.first_start = False
4501-
if not hasattr(self, 'soilWindow'):
4502-
self.soilWindow = QMainWindow(self.iface.mainWindow())
4458+
if not hasattr(self, 'soilWindow') or self.soilWindow is None:
4459+
self.soilWindow = QMainWindow()
45034460
self.soilWindow.setWindowTitle("ISRIC Soil Type Converter")
4461+
self.soilWindow.setAttribute(Qt.WA_DeleteOnClose)
45044462
self.soilDialog = SoilPreprocessingDialog(self.iface.mainWindow(), self)
45054463
self.soilWindow.setCentralWidget(self.soilDialog)
45064464
else:
@@ -4513,9 +4471,10 @@ def open_soil_window(self):
45134471
def open_landuse_window(self):
45144472
if self.first_start:
45154473
self.first_start = False
4516-
if not hasattr(self, 'landuseWindow'):
4517-
self.landuseWindow = QMainWindow(self.iface.mainWindow())
4474+
if not hasattr(self, 'landuseWindow') or self.landuseWindow is None:
4475+
self.landuseWindow = QMainWindow()
45184476
self.landuseWindow.setWindowTitle("Land use mapping")
4477+
self.landuseWindow.setAttribute(Qt.WA_DeleteOnClose)
45194478
self.landuseDialog = LanduseAssignmentDialog(self.iface.mainWindow(), self)
45204479
self.landuseWindow.setCentralWidget(self.landuseDialog)
45214480
else:

docs/hrus_step_by_step.rst

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -145,15 +145,15 @@ Select and Edit Land use layer
145145

146146
The table below shows the necessary types for these parameters. Additionally, it also shows the required unit and restrictions of the parameters. If the user-mapped field has a different datatype, the plugin, where possible, converts the field’s values to the parameter’s type.
147147

148-
If ‘Parameter not available’ is selected, the plugin is trying to fill those parameters with Talsim parameters using the "Name"-field. The list with land use names and their parameters can be found here: :download:`Land use parameters file <_static/landuseParameterValues.csv>`. If the land use name is not found, that parameter will be added with null values. Only for pTAW 0,5 is used as default value, if the user does not insert a parameter.
148+
If ‘Parameter not available’ is selected, the plugin is trying to fill those parameters with Talsim parameters using the "Name"-field. If you used QTalsim "Land Use Mapping" for creating the land use layer, the name is stored in the field "OBJART_NEU" The list with land use names and their parameters can be found here: :download:`Land use parameters file <_static/landuseParameterValues.csv>`. If the land use name is not found, that parameter will be added with null values. Only for pTAW 0,5 is used as default value, if the user does not insert a parameter.
149149

150-
After completing the mapping, click ‘Confirm Landuse Mapping’ to create a new
151-
layer containing the input fields from your layer and the
152-
Talsim parameter values. If the user defines area/percentage thresholds, land use features below these thresholds are
153-
deleted during this step. The user can set a minimum size of
154-
the land use features [m²] and a minimum percentage of the land use features relative to the
155-
corresponding sub-basin's area. Land use features that fall below the specified size or
156-
percentage share are deleted and filled using the ‘Eliminate’-tool.
150+
After completing the mapping, click ‘Confirm Landuse Mapping’ to create a new
151+
layer containing the input fields from your layer and the
152+
Talsim parameter values. If the user defines area/percentage thresholds, land use features below these thresholds are
153+
deleted during this step. The user can set a minimum size of
154+
the land use features [m²] and a minimum percentage of the land use features relative to the
155+
corresponding sub-basin's area. Land use features that fall below the specified size or
156+
percentage share are deleted and filled using the ‘Eliminate’-tool.
157157

158158

159159
============================== ====== ===== =====================

0 commit comments

Comments
 (0)