Skip to content

Commit 3768e48

Browse files
author
Daniel
committed
v.2.0.2
1 parent 219134f commit 3768e48

File tree

7 files changed

+43
-37
lines changed

7 files changed

+43
-37
lines changed

__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
__date__ = '2024-01-17'
2727
__copyright__ = '(C) 2024 by DPE'
2828

29-
__version__ = "2.0.1"
29+
__version__ = "2.0.2"
3030

3131
import sys
3232
from pathlib import Path

algorithms/BegrensSkadeExcavation.py

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -420,6 +420,12 @@ def processAlgorithm(self, parameters, context, feedback):
420420
)
421421
self.logger.info(f"PROCESS - bLongterm value: {bLongterm}")
422422

423+
if not bShortterm and not bLongterm:
424+
error_msg = "Please choose Short term or Long term settlements, or both"
425+
self.logger.error(error_msg)
426+
feedback.reportError(error_msg)
427+
return {}
428+
423429
bVulnerability = self.parameterAsBoolean(
424430
parameters,
425431
self.VULNERABILITY_ANALYSIS[0],
@@ -490,13 +496,7 @@ def processAlgorithm(self, parameters, context, feedback):
490496
#source_excavation_poly_as_json = Utils.getShapefileAsJson(path_source_excavation_poly, logger)
491497
self.logger.info(f"PROCESS - JSON structure: {source_excavation_poly_as_json}")
492498

493-
feedback.setProgress(30)
494-
if not bShortterm and not bLongterm:
495-
error_msg = "Please choose Short term or Long term settlements, or both"
496-
self.logger.error(error_msg)
497-
feedback.reportError(error_msg)
498-
return {}
499-
499+
feedback.setProgress(30)
500500
if bShortterm:
501501
self.logger.info(f"PROCESS - ######## SHORTTERM ########")
502502
self.logger.info(f"PROCESS - Defining short term input")
@@ -514,14 +514,14 @@ def processAlgorithm(self, parameters, context, feedback):
514514
else:
515515
excavation_depth = None
516516
short_term_curve = None
517-
517+
518+
source_raster_rock_surface = self.parameterAsRasterLayer(parameters, self.RASTER_ROCK_SURFACE[0], context )
519+
self.logger.info(f"PROCESS - Rock raster DTM: {source_raster_rock_surface}")
518520
if bLongterm:
519521
self.logger.info(f"PROCESS - ######## LONGTERM ########")
520522
self.logger.info(f"PROCESS - Defining long term input")
521523

522524
############### HANDELING OF INPUT RASTER ################
523-
source_raster_rock_surface = self.parameterAsRasterLayer(parameters, self.RASTER_ROCK_SURFACE[0], context )
524-
self.logger.info(f"PROCESS - Rock raster DTM: {source_raster_rock_surface}")
525525
if source_raster_rock_surface is not None:
526526
############### RASTER REPROJECT ################
527527
if reproject_is_needed(source_raster_rock_surface, output_proj):
@@ -596,7 +596,8 @@ def processAlgorithm(self, parameters, context, feedback):
596596
################# LOG PROJECTIONS #################
597597
feedback.pushInfo(f"PROCESS - CRS BUILDINGS-vector: {source_building_poly.crs().postgisSrid()}")
598598
feedback.pushInfo(f"PROCESS - CRS EXCAVATION-vector: {source_excavation_poly.crs().postgisSrid()}")
599-
feedback.pushInfo(f"PROCESS - CRS DTB-raster: {source_raster_rock_surface.crs().postgisSrid()}")
599+
if source_raster_rock_surface is not None:
600+
feedback.pushInfo(f"PROCESS - CRS DTB-raster: {source_raster_rock_surface.crs().postgisSrid()}")
600601

601602
###### FEEDBACK ALL PARAMETERS #########
602603
feedback.pushInfo("PROCESS - Running mainBegrensSkade_Excavation...")

algorithms/BegrensSkadeTunnel.py

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -382,11 +382,17 @@ def initAlgorithm(self, config):
382382
def processAlgorithm(self, parameters, context, feedback):
383383
"""
384384
Here is where the processing itself takes place.
385-
"""
385+
"""
386386
bShortterm = self.parameterAsBoolean(parameters, self.SHORT_TERM_SETTLEMENT[0], context)
387387
self.logger.info(f"PROCESS - bShortterm value: {bShortterm}")
388388
bLongterm = self.parameterAsBoolean(parameters, self.LONG_TERM_SETTLEMENT[0], context)
389389
self.logger.info(f"PROCESS - bLongterm value: {bLongterm}")
390+
if not bShortterm and not bLongterm:
391+
error_msg = "Please choose Short term or Long term settlements, or both"
392+
self.logger.error(error_msg)
393+
feedback.reportError(error_msg)
394+
return {}
395+
390396
bVulnerability = self.parameterAsBoolean(parameters, self.VULNERABILITY_ANALYSIS[0], context)
391397
self.logger.info(f"PROCESS - bVulnerability value: {bVulnerability}")
392398
bIntermediate = self.parameterAsBoolean(parameters, self.INTERMEDIATE_LAYERS[0], context)
@@ -446,13 +452,6 @@ def processAlgorithm(self, parameters, context, feedback):
446452
self.logger.info(f"PROCESS - JSON structure: {source_tunnel_poly_as_json}")
447453

448454
feedback.setProgress(30)
449-
450-
if not bShortterm and not bLongterm:
451-
error_msg = "Please choose Short term or Long term settlements, or both"
452-
self.logger.error(error_msg)
453-
feedback.reportError(error_msg)
454-
return {}
455-
456455
if bShortterm:
457456
tunnel_depth = self.parameterAsDouble(parameters, self.TUNNEL_DEPTH[0], context)
458457
tunnel_diameter = self.parameterAsDouble(parameters, self.TUNNEL_DIAM[0], context)
@@ -463,14 +462,14 @@ def processAlgorithm(self, parameters, context, feedback):
463462
tunnel_diameter = None
464463
volume_loss = None
465464
trough_width = None
466-
465+
466+
source_raster_rock_surface = self.parameterAsRasterLayer(parameters, self.RASTER_ROCK_SURFACE[0], context )
467+
self.logger.info(f"PROCESS - Rock raster DTM: {source_raster_rock_surface}")
467468
if bLongterm:
468469
self.logger.info(f"PROCESS - ######## LONGTERM ########")
469470
self.logger.info(f"PROCESS - Defining long term input")
470471

471472
############### HANDELING OF INPUT RASTER ################
472-
source_raster_rock_surface = self.parameterAsRasterLayer(parameters, self.RASTER_ROCK_SURFACE[0], context )
473-
self.logger.info(f"PROCESS - Rock raster DTM: {source_raster_rock_surface}")
474473
if source_raster_rock_surface is not None:
475474
############### RASTER REPROJECT ################
476475
if reproject_is_needed(source_raster_rock_surface, output_proj):
@@ -499,7 +498,7 @@ def processAlgorithm(self, parameters, context, feedback):
499498
porewp_calc_type_english = self.CURVES_enum_porepressure[porepressure_index]
500499
porewp_calc_type = map_porepressure_curve_names(porewp_calc_type_english)
501500
tunnel_leakage = self.parameterAsDouble(parameters, self.TUNNEL_LEAKAGE[0], context)
502-
porewp_red_at_site = self.parameterAsDouble(parameters, self.POREPRESSURE_REDUCTION[0], context)
501+
porewp_red_at_site = self.parameterAsInt(parameters, self.POREPRESSURE_REDUCTION[0], context)
503502
dry_crust_thk = self.parameterAsDouble(parameters, self.DRY_CRUST_THICKNESS[0], context)
504503
dep_groundwater = self.parameterAsDouble(parameters, self.DEPTH_GROUNDWATER[0], context)
505504
density_sat = self.parameterAsDouble(parameters, self.SOIL_DENSITY[0], context)
@@ -543,7 +542,8 @@ def processAlgorithm(self, parameters, context, feedback):
543542
################# LOG PROJECTIONS #################
544543
feedback.pushInfo(f"PROCESS - CRS BUILDINGS-vector: {source_building_poly.crs().postgisSrid()}")
545544
feedback.pushInfo(f"PROCESS - CRS EXCAVATION-vector: {source_tunnel_poly.crs().postgisSrid()}")
546-
feedback.pushInfo(f"PROCESS - CRS DTB-raster: {source_raster_rock_surface.crs().postgisSrid()}")
545+
if source_raster_rock_surface is not None:
546+
feedback.pushInfo(f"PROCESS - CRS DTB-raster: {source_raster_rock_surface.crs().postgisSrid()}")
547547

548548
###### FEEDBACK ALL PARAMETERS #########
549549
feedback.pushInfo("PROCESS - Running mainBegrensSkade_Excavation...")

help/source/index.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
contain the root `toctree` directive.
55
66
Welcome to GeovitaProcessingPlugin's documentation!
7-
============================================
7+
===================================================
88

99
Contents:
1010

metadata.txt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ name=Geovita GIS Processing provider
77
qgisMinimumVersion=3.28
88
qgisMaximumVersion=3.99
99
description=This plugin adds different Geovita custom processing algorithms to QGIS
10-
version=2.0.1
10+
version=2.0.2
1111
author=DPE
1212
1313

@@ -28,7 +28,8 @@ repository=https://github.com/danpejobo/geovita_processing_plugin
2828

2929
hasProcessingProvider=yes
3030
# Uncomment the following line and add your changelog:
31-
changelog=v.2.0.1 (30.01.2024)
31+
changelog=v.2.0.2 (01.02.2024)
32+
- Fix unbound local reference to DTB-raster
3233
- Fix bug with checking version. Undefined variable if version < 33200
3334

3435
v.2.0.0 (29.01.2024)

requirements.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ charset-normalizer==3.3.2
55
click==8.1.7
66
colorama==0.4.6
77
docutils==0.20.1
8-
GDAL==3.4.3
98
idna==3.6
109
imagesize==1.4.1
1110
Jinja2==3.1.3

utils/methodslib.py

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -91,14 +91,16 @@ def process_raster_for_impactmap(source_excavation_poly, dtb_raster_layer, clipp
9191
Returns:
9292
- Path: Path object of the processed raster in TIFF format.
9393
"""
94-
# Check if the running version of QGIS is lower than the requirement, and create temp_folder based on that
95-
temp_folder = create_temp_folder_for_version(Qgis.QGIS_VERSION_INT, context if context else None)
94+
9695

9796
# Prepare processing context and feedback
9897
if not context:
9998
context = QgsProcessingContext()
10099
feedback = context.feedback() if context else QgsProcessingFeedback()
101100

101+
# Check if the running version of QGIS is lower than the requirement, and create temp_folder based on that
102+
temp_folder = create_temp_folder_for_version(Qgis.QGIS_VERSION_INT, context)
103+
102104
for feature in source_excavation_poly.getFeatures():
103105
geom = feature.geometry()
104106
polygon_extent = geom.boundingBox() # Returns a QgsRectangle of the polygon feature
@@ -259,14 +261,14 @@ def reproject_layers(keep_interm_layer: bool,
259261
Returns:
260262
- Tuple: (reprojected_vector_path, reprojected_raster_path) Paths to the reprojected layers.
261263
"""
262-
# Check if the running version of QGIS is lower than the requirement, and create temp_folder based on that
263-
temp_folder = create_temp_folder_for_version(Qgis.QGIS_VERSION_INT, context if context else None)
264-
265264
# Prepare processing context and feedback
266265
if not context:
267266
context = QgsProcessingContext()
268267
feedback = context.feedback() if context else QgsProcessingFeedback()
269268

269+
# Check if the running version of QGIS is lower than the requirement, and create temp_folder based on that
270+
temp_folder = create_temp_folder_for_version(Qgis.QGIS_VERSION_INT, context)
271+
270272
# Initialize reprojected layer variables
271273
reprojected_vector_layer = None
272274
reprojected_raster_layer = None
@@ -359,8 +361,11 @@ def create_temp_folder_for_version(qgis_version_int : int, context: QgsProcessin
359361
# Check if the running version of QGIS is lower than the requirement
360362
if qgis_version_int >= 33200 and context is not None:
361363
# For QGIS versions 3.32.0 and above
362-
temp_folder = context.temporaryFolder()
364+
temp_folder = Path(context.temporaryFolder())
365+
temp_folder.mkdir(parents=True, exist_ok=True)
363366
else:
364367
# For older versions, or if no context is provided, use the global Processing temporary folder
365-
temp_folder = QgsProcessingUtils.tempFolder()
366-
return Path(temp_folder)
368+
temp_folder = Path(QgsProcessingUtils.tempFolder())
369+
temp_folder.mkdir(parents=True, exist_ok=True)
370+
371+
return temp_folder

0 commit comments

Comments
 (0)