Skip to content

Commit 3ec1ce3

Browse files
committed
Enable any valid Gdal file format for inputs and outputs for the different algorithms
1 parent b92d082 commit 3ec1ce3

4 files changed

+12
-5
lines changed

automated_global_coregistration_algorithm.py

+4-1
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@
2727
QgsProcessingParameterNumber, QgsProcessingParameterDefinition, QgsProcessingParameterEnum,
2828
QgsProcessingParameterPoint, QgsProcessingParameterBoolean)
2929

30+
from Coregistration.utils.system_utils import get_raster_driver_name_by_extension
31+
3032

3133
class AutomatedGlobalCoregistrationAlgorithm(QgsProcessingAlgorithm):
3234
"""
@@ -257,6 +259,7 @@ def get_inputfilepath(layer):
257259
resampling_method = self.resampling_methods[self.parameterAsEnum(parameters, self.RESAMPLING, context)][1]
258260

259261
output_file = self.parameterAsOutputLayer(parameters, self.OUTPUT, context)
262+
output_driver_name = get_raster_driver_name_by_extension(output_file)
260263

261264
feedback.pushInfo("Image to image Co-Registration:")
262265
feedback.pushInfo("\nProcessing file: " + img_tgt)
@@ -265,7 +268,7 @@ def get_inputfilepath(layer):
265268
feedback.pushInfo("\n(To check the complete log of the process, open the Python Console)...\n")
266269
CR = COREG(img_ref, img_tgt, path_out=output_file, align_grids=align_grids, match_gsd=match_gsd,
267270
wp=(wp_x, wp_y), ws=(ws_x, ws_y), resamp_alg_deshift=resampling_method,
268-
max_shift=max_shift, max_iter=15, fmt_out="GTiff", out_crea_options=["WRITE_METADATA=NO"],
271+
max_shift=max_shift, max_iter=15, fmt_out=output_driver_name, out_crea_options=["WRITE_METADATA=NO"],
269272
CPUs=1 if platform.system() == "Windows" else None)
270273
CR.correct_shifts()
271274

automated_local_coregistration_algorithm.py

+4-1
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@
2727
QgsProcessingParameterNumber, QgsProcessingParameterDefinition, QgsProcessingParameterEnum,
2828
QgsProcessingParameterBoolean)
2929

30+
from Coregistration.utils.system_utils import get_raster_driver_name_by_extension
31+
3032

3133
class AutomatedLocalCoregistrationAlgorithm(QgsProcessingAlgorithm):
3234
"""
@@ -252,6 +254,7 @@ def get_inputfilepath(layer):
252254
resampling_method = self.resampling_methods[self.parameterAsEnum(parameters, self.RESAMPLING, context)][1]
253255

254256
output_file = self.parameterAsOutputLayer(parameters, self.OUTPUT, context)
257+
output_driver_name = get_raster_driver_name_by_extension(output_file)
255258

256259
feedback.pushInfo("Image to image Co-Registration:")
257260
feedback.pushInfo("\nProcessing file: " + img_tgt)
@@ -264,7 +267,7 @@ def get_inputfilepath(layer):
264267
CRL = COREG_LOCAL(img_ref, img_tgt, path_out=output_file, align_grids=align_grids, match_gsd=match_gsd,
265268
grid_res=grid_res, window_size=(window_size, window_size),
266269
resamp_alg_deshift=resampling_method, max_shift=max_shift, max_iter=15,
267-
fmt_out="GTiff", out_crea_options=["WRITE_METADATA=NO"],
270+
fmt_out=output_driver_name, out_crea_options=["WRITE_METADATA=NO"],
268271
CPUs=1 if platform.system() == "Windows" else None)
269272
CRL.correct_shifts()
270273

panning_pixel_adjustment_algorithm.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,7 @@ def get_inputfilepath(layer):
187187
output_file = file_in_path
188188

189189
# gdal driver based on the output file
190-
gdal_driver = gdal.GetDriverByName(get_raster_driver_name_by_extension(output_file.split(".")[-1]))
190+
gdal_driver = gdal.GetDriverByName(get_raster_driver_name_by_extension(output_file))
191191
gdal_driver.CreateCopy(output_file, input_ds)
192192
input_ds = None
193193

utils/system_utils.py

+3-2
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,11 @@
1818
* *
1919
***************************************************************************/
2020
"""
21+
import os
2122

2223

23-
def get_raster_driver_name_by_extension(file_extension):
24-
# Normalize the extension by removing leading dot and converting to lowercase
24+
def get_raster_driver_name_by_extension(file_path):
25+
file_extension = os.path.splitext(file_path)[1]
2526
ext = file_extension.lower().lstrip('.')
2627

2728
# Dictionary mapping file extensions to GDAL driver names

0 commit comments

Comments
 (0)