Skip to content

Commit 38cbcc8

Browse files
author
Daniel
committed
v.2.0.1 - bug with checking version
1 parent a842f9a commit 38cbcc8

File tree

3 files changed

+31
-22
lines changed

3 files changed

+31
-22
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.0"
29+
__version__ = "2.0.1"
3030

3131
import sys
3232
from pathlib import Path

metadata.txt

Lines changed: 5 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.0
10+
version=2.0.1
1111
author=DPE
1212
1313

@@ -28,7 +28,10 @@ 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.0 (29.01.2024)
31+
changelog=v.2.0.1 (30.01.2024)
32+
- Fix bug with checking version. Undefined variable if version < 33200
33+
34+
v.2.0.0 (29.01.2024)
3235
- Add reproject functionality
3336
- Fix: Access violation error due to maipulating GUI from process thread
3437
- Fix: Group/layers in TOC updates correctly

utils/methodslib.py

Lines changed: 25 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,6 @@
2929
from typing import Union
3030
import shutil
3131

32-
if Qgis.QGIS_VERSION_INT < 33200:
33-
import tempfile
34-
QGIS_VERSION = Qgis.QGIS_VERSION_INT
35-
3632
def get_shapefile_as_json_pyqgis(layer, logger=None):
3733
if logger is not None:
3834
logger.debug("@get_shapefile_as_json_pyqgis@: ShapeFN id: {}".format(layer.id()))
@@ -95,13 +91,8 @@ def process_raster_for_impactmap(source_excavation_poly, dtb_raster_layer, clipp
9591
Returns:
9692
- Path: Path object of the processed raster in TIFF format.
9793
"""
98-
# Check if the running version of QGIS is lower than the requirement
99-
if QGIS_VERSION < 33200:
100-
# Create a temporary directory using Python's tempfile module
101-
temp_dir = tempfile.mkdtemp()
102-
temp_folder = Path(temp_dir)
103-
else:
104-
temp_folder = Path(QgsProcessingContext.temporaryFolder(context) if context else QgsProcessingUtils.tempFolder())
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)
10596

10697
# Prepare processing context and feedback
10798
if not context:
@@ -268,13 +259,8 @@ def reproject_layers(keep_interm_layer: bool,
268259
Returns:
269260
- Tuple: (reprojected_vector_path, reprojected_raster_path) Paths to the reprojected layers.
270261
"""
271-
# Check if the running version of QGIS is lower than the requirement
272-
if QGIS_VERSION < 33200:
273-
# Create a temporary directory using Python's tempfile module
274-
temp_dir = tempfile.mkdtemp()
275-
temp_folder = Path(temp_dir)
276-
else:
277-
temp_folder = Path(QgsProcessingContext.temporaryFolder(context) if context else QgsProcessingUtils.tempFolder())
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)
278264

279265
# Prepare processing context and feedback
280266
if not context:
@@ -357,4 +343,24 @@ def move_file_components(original_file_path: Path, destination_file_path: Path):
357343
src_file = original_file_path.with_suffix(ext)
358344
dest_file = destination_folder / (destination_base_name + ext)
359345
if src_file.exists():
360-
shutil.move(str(src_file), str(dest_file))
346+
shutil.move(str(src_file), str(dest_file))
347+
348+
def create_temp_folder_for_version(qgis_version_int : int, context: QgsProcessingContext = None) -> Path:
349+
"""
350+
Creates a temporary folder based on the QGIS version.
351+
352+
Args:
353+
qgis_version_int (int): The integer representation of the QGIS version.
354+
context (QgsProcessingContext, optional): The context for processing. Default is None.
355+
356+
Returns:
357+
Path: The path to the temporary folder.
358+
"""
359+
# Check if the running version of QGIS is lower than the requirement
360+
if qgis_version_int >= 33200 and context is not None:
361+
# For QGIS versions 3.32.0 and above
362+
temp_folder = context.temporaryFolder()
363+
else:
364+
# 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)

0 commit comments

Comments
 (0)