From 2d27784cee40589f0db2d00b646eecf7d164fdb7 Mon Sep 17 00:00:00 2001 From: Nyall Dawson Date: Thu, 27 Jun 2024 08:39:22 +1000 Subject: [PATCH] Raise exceptions if open options not supported by GDAL version --- .../processing/algs/gdal/GridAverage.py | 3 + .../processing/algs/gdal/GridDataMetrics.py | 3 + .../algs/gdal/GridInverseDistance.py | 3 + .../GridInverseDistanceNearestNeighbor.py | 3 + .../processing/algs/gdal/GridLinear.py | 3 + .../algs/gdal/GridNearestNeighbor.py | 3 + .../plugins/processing/algs/gdal/rasterize.py | 5 + .../processing/algs/gdal/rasterize_over.py | 5 + .../algs/gdal/rasterize_over_fixed_value.py | 5 + .../tests/GdalAlgorithmsRasterTest.py | 159 +++++++++--------- 10 files changed, 117 insertions(+), 75 deletions(-) diff --git a/python/plugins/processing/algs/gdal/GridAverage.py b/python/plugins/processing/algs/gdal/GridAverage.py index 17ea0f78c53..167ccdd0965 100644 --- a/python/plugins/processing/algs/gdal/GridAverage.py +++ b/python/plugins/processing/algs/gdal/GridAverage.py @@ -181,6 +181,9 @@ class GridAverage(GdalAlgorithm): arguments.append(output_format) if input_details.open_options: + if GdalUtils.version() < 3070000: + raise QgsProcessingException(self.tr('Open options are not supported by gdal_grid version {} (requires GDAL version 3.7 or later)'.format(GdalUtils.readableVersion()))) + arguments.extend(input_details.open_options_as_arguments()) options = self.parameterAsString(parameters, self.OPTIONS, context) diff --git a/python/plugins/processing/algs/gdal/GridDataMetrics.py b/python/plugins/processing/algs/gdal/GridDataMetrics.py index 8ee2d9f76e5..7eb60403326 100644 --- a/python/plugins/processing/algs/gdal/GridDataMetrics.py +++ b/python/plugins/processing/algs/gdal/GridDataMetrics.py @@ -195,6 +195,9 @@ class GridDataMetrics(GdalAlgorithm): arguments.append(output_format) if input_details.open_options: + if GdalUtils.version() < 3070000: + raise QgsProcessingException(self.tr('Open options are not supported by gdal_grid version {} (requires GDAL version 3.7 or later)'.format(GdalUtils.readableVersion()))) + arguments.extend(input_details.open_options_as_arguments()) options = self.parameterAsString(parameters, self.OPTIONS, context) diff --git a/python/plugins/processing/algs/gdal/GridInverseDistance.py b/python/plugins/processing/algs/gdal/GridInverseDistance.py index 5cc437f5e0d..77e2e57fd5a 100644 --- a/python/plugins/processing/algs/gdal/GridInverseDistance.py +++ b/python/plugins/processing/algs/gdal/GridInverseDistance.py @@ -204,6 +204,9 @@ class GridInverseDistance(GdalAlgorithm): arguments.append(output_format) if input_details.open_options: + if GdalUtils.version() < 3070000: + raise QgsProcessingException(self.tr('Open options are not supported by gdal_grid version {} (requires GDAL version 3.7 or later)'.format(GdalUtils.readableVersion()))) + arguments.extend(input_details.open_options_as_arguments()) options = self.parameterAsString(parameters, self.OPTIONS, context) diff --git a/python/plugins/processing/algs/gdal/GridInverseDistanceNearestNeighbor.py b/python/plugins/processing/algs/gdal/GridInverseDistanceNearestNeighbor.py index 2441319cda5..26e13f00b2b 100644 --- a/python/plugins/processing/algs/gdal/GridInverseDistanceNearestNeighbor.py +++ b/python/plugins/processing/algs/gdal/GridInverseDistanceNearestNeighbor.py @@ -189,6 +189,9 @@ class GridInverseDistanceNearestNeighbor(GdalAlgorithm): arguments.append(output_format) if input_details.open_options: + if GdalUtils.version() < 3070000: + raise QgsProcessingException(self.tr('Open options are not supported by gdal_grid version {} (requires GDAL version 3.7 or later)'.format(GdalUtils.readableVersion()))) + arguments.extend(input_details.open_options_as_arguments()) options = self.parameterAsString(parameters, self.OPTIONS, context) diff --git a/python/plugins/processing/algs/gdal/GridLinear.py b/python/plugins/processing/algs/gdal/GridLinear.py index 5738d5d8d68..f3ec203d896 100644 --- a/python/plugins/processing/algs/gdal/GridLinear.py +++ b/python/plugins/processing/algs/gdal/GridLinear.py @@ -161,6 +161,9 @@ class GridLinear(GdalAlgorithm): arguments.append(output_format) if input_details.open_options: + if GdalUtils.version() < 3070000: + raise QgsProcessingException(self.tr('Open options are not supported by gdal_grid version {} (requires GDAL version 3.7 or later)'.format(GdalUtils.readableVersion()))) + arguments.extend(input_details.open_options_as_arguments()) options = self.parameterAsString(parameters, self.OPTIONS, context) diff --git a/python/plugins/processing/algs/gdal/GridNearestNeighbor.py b/python/plugins/processing/algs/gdal/GridNearestNeighbor.py index 354a60060cd..fd43b9f8eba 100644 --- a/python/plugins/processing/algs/gdal/GridNearestNeighbor.py +++ b/python/plugins/processing/algs/gdal/GridNearestNeighbor.py @@ -173,6 +173,9 @@ class GridNearestNeighbor(GdalAlgorithm): arguments.append(output_format) if input_details.open_options: + if GdalUtils.version() < 3070000: + raise QgsProcessingException(self.tr('Open options are not supported by gdal_grid version {} (requires GDAL version 3.7 or later)'.format(GdalUtils.readableVersion()))) + arguments.extend(input_details.open_options_as_arguments()) options = self.parameterAsString(parameters, self.OPTIONS, context) diff --git a/python/plugins/processing/algs/gdal/rasterize.py b/python/plugins/processing/algs/gdal/rasterize.py index 66b6f7e3c94..cacd5369b32 100644 --- a/python/plugins/processing/algs/gdal/rasterize.py +++ b/python/plugins/processing/algs/gdal/rasterize.py @@ -234,6 +234,11 @@ class rasterize(GdalAlgorithm): arguments.append(output_format) if input_details.open_options: + if GdalUtils.version() < 3070000: + raise QgsProcessingException(self.tr( + 'Open options are not supported by gdal_rasterize version {} (requires GDAL version 3.7 or later)'.format( + GdalUtils.readableVersion()))) + arguments.extend(input_details.open_options_as_arguments()) if input_details.credential_options: diff --git a/python/plugins/processing/algs/gdal/rasterize_over.py b/python/plugins/processing/algs/gdal/rasterize_over.py index be5e520f10c..dce80ad423a 100644 --- a/python/plugins/processing/algs/gdal/rasterize_over.py +++ b/python/plugins/processing/algs/gdal/rasterize_over.py @@ -120,6 +120,11 @@ class rasterize_over(GdalAlgorithm): arguments.append(extra) if input_details.open_options: + if GdalUtils.version() < 3070000: + raise QgsProcessingException(self.tr( + 'Open options are not supported by gdal_rasterize version {} (requires GDAL version 3.7 or later)'.format( + GdalUtils.readableVersion()))) + arguments.extend(input_details.open_options_as_arguments()) if input_details.credential_options: diff --git a/python/plugins/processing/algs/gdal/rasterize_over_fixed_value.py b/python/plugins/processing/algs/gdal/rasterize_over_fixed_value.py index e1088a0f335..5767596a2d3 100644 --- a/python/plugins/processing/algs/gdal/rasterize_over_fixed_value.py +++ b/python/plugins/processing/algs/gdal/rasterize_over_fixed_value.py @@ -113,6 +113,11 @@ class rasterize_over_fixed_value(GdalAlgorithm): arguments.append('-add') if input_details.open_options: + if GdalUtils.version() < 3070000: + raise QgsProcessingException(self.tr( + 'Open options are not supported by gdal_rasterize version {} (requires GDAL version 3.7 or later)'.format( + GdalUtils.readableVersion()))) + arguments.extend(input_details.open_options_as_arguments()) if input_details.credential_options: diff --git a/python/plugins/processing/tests/GdalAlgorithmsRasterTest.py b/python/plugins/processing/tests/GdalAlgorithmsRasterTest.py index 928ce161fc2..7971a36179a 100644 --- a/python/plugins/processing/tests/GdalAlgorithmsRasterTest.py +++ b/python/plugins/processing/tests/GdalAlgorithmsRasterTest.py @@ -1030,14 +1030,15 @@ class TestGdalRasterAlgorithms(QgisTestCase, AlgorithmsTestBase.AlgorithmsTest): source + ' ' + outdir + '/check.jpg']) - self.assertEqual( - alg.getConsoleCommands({'INPUT': source + '|option:X_POSSIBLE_NAMES=geom_x|option:Y_POSSIBLE_NAMES=geom_y', - 'EXTRA': '-z_multiply 1.5 -outsize 1754 1394', - 'OUTPUT': outdir + '/check.jpg'}, context, feedback), - ['gdal_grid', - '-l points -a average:radius1=0.0:radius2=0.0:angle=0.0:min_points=0:nodata=0.0 -ot Float32 -of JPEG -oo X_POSSIBLE_NAMES=geom_x -oo Y_POSSIBLE_NAMES=geom_y -z_multiply 1.5 -outsize 1754 1394 ' + - source + ' ' + - outdir + '/check.jpg']) + if GdalUtils.version() >= 3070000: + self.assertEqual( + alg.getConsoleCommands({'INPUT': source + '|option:X_POSSIBLE_NAMES=geom_x|option:Y_POSSIBLE_NAMES=geom_y', + 'EXTRA': '-z_multiply 1.5 -outsize 1754 1394', + 'OUTPUT': outdir + '/check.jpg'}, context, feedback), + ['gdal_grid', + '-l points -a average:radius1=0.0:radius2=0.0:angle=0.0:min_points=0:nodata=0.0 -ot Float32 -of JPEG -oo X_POSSIBLE_NAMES=geom_x -oo Y_POSSIBLE_NAMES=geom_y -z_multiply 1.5 -outsize 1754 1394 ' + + source + ' ' + + outdir + '/check.jpg']) self.assertEqual( alg.getConsoleCommands({'INPUT': source + '|credential:X=Y|credential:Z=A', @@ -1102,15 +1103,16 @@ class TestGdalRasterAlgorithms(QgisTestCase, AlgorithmsTestBase.AlgorithmsTest): source + ' ' + outdir + '/check.tif']) - self.assertEqual( - alg.getConsoleCommands({'INPUT': source + '|option:X_POSSIBLE_NAMES=geom_x|option:Y_POSSIBLE_NAMES=geom_y', - 'EXTRA': '-z_multiply 1.5 -outsize 1754 1394', - 'OUTPUT': outdir + '/check.tif'}, context, feedback), - ['gdal_grid', - '-l points -a minimum:radius1=0.0:radius2=0.0:angle=0.0:min_points=0:nodata=0.0 ' + - '-ot Float32 -of GTiff -oo X_POSSIBLE_NAMES=geom_x -oo Y_POSSIBLE_NAMES=geom_y -z_multiply 1.5 -outsize 1754 1394 ' + - source + ' ' + - outdir + '/check.tif']) + if GdalUtils.version() >= 3070000: + self.assertEqual( + alg.getConsoleCommands({'INPUT': source + '|option:X_POSSIBLE_NAMES=geom_x|option:Y_POSSIBLE_NAMES=geom_y', + 'EXTRA': '-z_multiply 1.5 -outsize 1754 1394', + 'OUTPUT': outdir + '/check.tif'}, context, feedback), + ['gdal_grid', + '-l points -a minimum:radius1=0.0:radius2=0.0:angle=0.0:min_points=0:nodata=0.0 ' + + '-ot Float32 -of GTiff -oo X_POSSIBLE_NAMES=geom_x -oo Y_POSSIBLE_NAMES=geom_y -z_multiply 1.5 -outsize 1754 1394 ' + + source + ' ' + + outdir + '/check.tif']) self.assertEqual( alg.getConsoleCommands({'INPUT': source + '|credential:X=Y|credential:Z=A', @@ -1167,15 +1169,16 @@ class TestGdalRasterAlgorithms(QgisTestCase, AlgorithmsTestBase.AlgorithmsTest): source + ' ' + outdir + '/check.tif']) - self.assertEqual( - alg.getConsoleCommands({'INPUT': source + '|option:X_POSSIBLE_NAMES=geom_x|option:Y_POSSIBLE_NAMES=geom_y', - 'EXTRA': '-z_multiply 1.5 -outsize 1754 1394', - 'OUTPUT': outdir + '/check.tif'}, context, feedback), - ['gdal_grid', - '-l points -a invdist:power=2.0:smoothing=0.0:radius1=0.0:radius2=0.0:angle=0.0:max_points=0:min_points=0:nodata=0.0 ' + - '-ot Float32 -of GTiff -oo X_POSSIBLE_NAMES=geom_x -oo Y_POSSIBLE_NAMES=geom_y -z_multiply 1.5 -outsize 1754 1394 ' + - source + ' ' + - outdir + '/check.tif']) + if GdalUtils.version() >= 3070000: + self.assertEqual( + alg.getConsoleCommands({'INPUT': source + '|option:X_POSSIBLE_NAMES=geom_x|option:Y_POSSIBLE_NAMES=geom_y', + 'EXTRA': '-z_multiply 1.5 -outsize 1754 1394', + 'OUTPUT': outdir + '/check.tif'}, context, feedback), + ['gdal_grid', + '-l points -a invdist:power=2.0:smoothing=0.0:radius1=0.0:radius2=0.0:angle=0.0:max_points=0:min_points=0:nodata=0.0 ' + + '-ot Float32 -of GTiff -oo X_POSSIBLE_NAMES=geom_x -oo Y_POSSIBLE_NAMES=geom_y -z_multiply 1.5 -outsize 1754 1394 ' + + source + ' ' + + outdir + '/check.tif']) self.assertEqual( alg.getConsoleCommands({'INPUT': source + '|credential:X=Y|credential:Z=A', @@ -1232,15 +1235,16 @@ class TestGdalRasterAlgorithms(QgisTestCase, AlgorithmsTestBase.AlgorithmsTest): source + ' ' + outdir + '/check.tif']) - self.assertEqual( - alg.getConsoleCommands({'INPUT': source + '|option:X_POSSIBLE_NAMES=geom_x|option:Y_POSSIBLE_NAMES=geom_y', - 'EXTRA': '-z_multiply 1.5 -outsize 1754 1394', - 'OUTPUT': outdir + '/check.tif'}, context, feedback), - ['gdal_grid', - '-l points -a invdistnn:power=2.0:smoothing=0.0:radius=1.0:max_points=12:min_points=0:nodata=0.0 ' + - '-ot Float32 -of GTiff -oo X_POSSIBLE_NAMES=geom_x -oo Y_POSSIBLE_NAMES=geom_y -z_multiply 1.5 -outsize 1754 1394 ' + - source + ' ' + - outdir + '/check.tif']) + if GdalUtils.version() >= 3070000: + self.assertEqual( + alg.getConsoleCommands({'INPUT': source + '|option:X_POSSIBLE_NAMES=geom_x|option:Y_POSSIBLE_NAMES=geom_y', + 'EXTRA': '-z_multiply 1.5 -outsize 1754 1394', + 'OUTPUT': outdir + '/check.tif'}, context, feedback), + ['gdal_grid', + '-l points -a invdistnn:power=2.0:smoothing=0.0:radius=1.0:max_points=12:min_points=0:nodata=0.0 ' + + '-ot Float32 -of GTiff -oo X_POSSIBLE_NAMES=geom_x -oo Y_POSSIBLE_NAMES=geom_y -z_multiply 1.5 -outsize 1754 1394 ' + + source + ' ' + + outdir + '/check.tif']) self.assertEqual( alg.getConsoleCommands({'INPUT': source + '|credential:X=Y|credential:Z=A', @@ -1297,15 +1301,16 @@ class TestGdalRasterAlgorithms(QgisTestCase, AlgorithmsTestBase.AlgorithmsTest): source + ' ' + outdir + '/check.tif']) - self.assertEqual( - alg.getConsoleCommands({'INPUT': source + '|option:X_POSSIBLE_NAMES=geom_x|option:Y_POSSIBLE_NAMES=geom_y', - 'EXTRA': '-z_multiply 1.5 -outsize 1754 1394', - 'OUTPUT': outdir + '/check.tif'}, context, feedback), - ['gdal_grid', - '-l points -a linear:radius=-1.0:nodata=0.0 -ot Float32 -of GTiff -oo X_POSSIBLE_NAMES=geom_x -oo Y_POSSIBLE_NAMES=geom_y ' + - '-z_multiply 1.5 -outsize 1754 1394 ' + - source + ' ' + - outdir + '/check.tif']) + if GdalUtils.version() >= 3070000: + self.assertEqual( + alg.getConsoleCommands({'INPUT': source + '|option:X_POSSIBLE_NAMES=geom_x|option:Y_POSSIBLE_NAMES=geom_y', + 'EXTRA': '-z_multiply 1.5 -outsize 1754 1394', + 'OUTPUT': outdir + '/check.tif'}, context, feedback), + ['gdal_grid', + '-l points -a linear:radius=-1.0:nodata=0.0 -ot Float32 -of GTiff -oo X_POSSIBLE_NAMES=geom_x -oo Y_POSSIBLE_NAMES=geom_y ' + + '-z_multiply 1.5 -outsize 1754 1394 ' + + source + ' ' + + outdir + '/check.tif']) self.assertEqual( alg.getConsoleCommands({'INPUT': source + '|credential:X=Y|credential:Z=A', @@ -1362,15 +1367,16 @@ class TestGdalRasterAlgorithms(QgisTestCase, AlgorithmsTestBase.AlgorithmsTest): source + ' ' + outdir + '/check.tif']) - self.assertEqual( - alg.getConsoleCommands({'INPUT': source + '|option:X_POSSIBLE_NAMES=geom_x|option:Y_POSSIBLE_NAMES=geom_y', - 'EXTRA': '-z_multiply 1.5 -outsize 1754 1394', - 'OUTPUT': outdir + '/check.tif'}, context, feedback), - ['gdal_grid', - '-l points -a nearest:radius1=0.0:radius2=0.0:angle=0.0:nodata=0.0 -ot Float32 -of GTiff -oo X_POSSIBLE_NAMES=geom_x -oo Y_POSSIBLE_NAMES=geom_y ' + - '-z_multiply 1.5 -outsize 1754 1394 ' + - source + ' ' + - outdir + '/check.tif']) + if GdalUtils.version() >= 3070000: + self.assertEqual( + alg.getConsoleCommands({'INPUT': source + '|option:X_POSSIBLE_NAMES=geom_x|option:Y_POSSIBLE_NAMES=geom_y', + 'EXTRA': '-z_multiply 1.5 -outsize 1754 1394', + 'OUTPUT': outdir + '/check.tif'}, context, feedback), + ['gdal_grid', + '-l points -a nearest:radius1=0.0:radius2=0.0:angle=0.0:nodata=0.0 -ot Float32 -of GTiff -oo X_POSSIBLE_NAMES=geom_x -oo Y_POSSIBLE_NAMES=geom_y ' + + '-z_multiply 1.5 -outsize 1754 1394 ' + + source + ' ' + + outdir + '/check.tif']) self.assertEqual( alg.getConsoleCommands({'INPUT': source + '|credential:X=Y|credential:Z=A', @@ -1987,14 +1993,15 @@ class TestGdalRasterAlgorithms(QgisTestCase, AlgorithmsTestBase.AlgorithmsTest): source + ' ' + outdir + '/check.jpg']) - self.assertEqual( - alg.getConsoleCommands({'INPUT': source + '|option:X_POSSIBLE_NAMES=geom_x|option:Y_POSSIBLE_NAMES=geom_y', - 'FIELD': 'id', - 'OUTPUT': outdir + '/check.jpg'}, context, feedback), - ['gdal_rasterize', - '-l polys2 -a id -ts 0.0 0.0 -ot Float32 -of JPEG -oo X_POSSIBLE_NAMES=geom_x -oo Y_POSSIBLE_NAMES=geom_y ' + - source + ' ' + - outdir + '/check.jpg']) + if GdalUtils.version() >= 3070000: + self.assertEqual( + alg.getConsoleCommands({'INPUT': source + '|option:X_POSSIBLE_NAMES=geom_x|option:Y_POSSIBLE_NAMES=geom_y', + 'FIELD': 'id', + 'OUTPUT': outdir + '/check.jpg'}, context, feedback), + ['gdal_rasterize', + '-l polys2 -a id -ts 0.0 0.0 -ot Float32 -of JPEG -oo X_POSSIBLE_NAMES=geom_x -oo Y_POSSIBLE_NAMES=geom_y ' + + source + ' ' + + outdir + '/check.jpg']) self.assertEqual( alg.getConsoleCommands({'INPUT': source + '|credential:X=Y|credential:Z=A', @@ -2040,13 +2047,14 @@ class TestGdalRasterAlgorithms(QgisTestCase, AlgorithmsTestBase.AlgorithmsTest): '-l polys2 -a id -i ' + vector + ' ' + raster]) - self.assertEqual( - alg.getConsoleCommands({'INPUT': vector + '|option:X_POSSIBLE_NAMES=geom_x|option:Y_POSSIBLE_NAMES=geom_y', - 'FIELD': 'id', - 'INPUT_RASTER': raster}, context, feedback), - ['gdal_rasterize', - '-l polys2 -a id -oo X_POSSIBLE_NAMES=geom_x -oo Y_POSSIBLE_NAMES=geom_y ' + - vector + ' ' + raster]) + if GdalUtils.version() >= 3070000: + self.assertEqual( + alg.getConsoleCommands({'INPUT': vector + '|option:X_POSSIBLE_NAMES=geom_x|option:Y_POSSIBLE_NAMES=geom_y', + 'FIELD': 'id', + 'INPUT_RASTER': raster}, context, feedback), + ['gdal_rasterize', + '-l polys2 -a id -oo X_POSSIBLE_NAMES=geom_x -oo Y_POSSIBLE_NAMES=geom_y ' + + vector + ' ' + raster]) self.assertEqual( alg.getConsoleCommands({'INPUT': vector + '|credential:X=Y|credential:Z=A', @@ -2091,13 +2099,14 @@ class TestGdalRasterAlgorithms(QgisTestCase, AlgorithmsTestBase.AlgorithmsTest): '-l polys2 -burn 100.0 -i ' + vector + ' ' + raster]) - self.assertEqual( - alg.getConsoleCommands({'INPUT': vector + '|option:X_POSSIBLE_NAMES=geom_x|option:Y_POSSIBLE_NAMES=geom_y', - 'BURN': 100, - 'INPUT_RASTER': raster}, context, feedback), - ['gdal_rasterize', - '-l polys2 -burn 100.0 -oo X_POSSIBLE_NAMES=geom_x -oo Y_POSSIBLE_NAMES=geom_y ' + - vector + ' ' + raster]) + if GdalUtils.version() >= 3070000: + self.assertEqual( + alg.getConsoleCommands({'INPUT': vector + '|option:X_POSSIBLE_NAMES=geom_x|option:Y_POSSIBLE_NAMES=geom_y', + 'BURN': 100, + 'INPUT_RASTER': raster}, context, feedback), + ['gdal_rasterize', + '-l polys2 -burn 100.0 -oo X_POSSIBLE_NAMES=geom_x -oo Y_POSSIBLE_NAMES=geom_y ' + + vector + ' ' + raster]) self.assertEqual( alg.getConsoleCommands({'INPUT': vector + '|credential:X=Y|credential:Z=A',