mirror of
https://github.com/qgis/QGIS.git
synced 2025-12-04 00:06:46 -05:00
[processing] Make gdaladdo optional parameters truly optional
This commit is contained in:
parent
2829f52d5f
commit
5385ae64d4
@ -51,7 +51,7 @@ class gdaladdo(GdalAlgorithm):
|
||||
super().__init__()
|
||||
|
||||
def initAlgorithm(self, config=None):
|
||||
self.methods = ((self.tr('Nearest Neighbour'), 'nearest'),
|
||||
self.methods = ((self.tr('Nearest Neighbour (default)'), 'nearest'),
|
||||
(self.tr('Average'), 'average'),
|
||||
(self.tr('Gaussian'), 'gauss'),
|
||||
(self.tr('Cubic Convolution'), 'cubic'),
|
||||
@ -67,19 +67,26 @@ class gdaladdo(GdalAlgorithm):
|
||||
|
||||
self.addParameter(QgsProcessingParameterRasterLayer(self.INPUT,
|
||||
self.tr('Input layer')))
|
||||
self.addParameter(QgsProcessingParameterString(self.LEVELS,
|
||||
self.tr('Overview levels'),
|
||||
defaultValue='2 4 8 16'))
|
||||
self.addParameter(QgsProcessingParameterBoolean(self.CLEAN,
|
||||
self.tr('Remove all existing overviews'),
|
||||
defaultValue=False))
|
||||
|
||||
if GdalUtils.version() < 230000:
|
||||
self.addParameter(QgsProcessingParameterString(self.LEVELS,
|
||||
self.tr('Overview levels'),
|
||||
defaultValue='2 4 8 16'))
|
||||
|
||||
params = []
|
||||
if GdalUtils.version() >= 230000:
|
||||
params.append(QgsProcessingParameterString(self.LEVELS,
|
||||
self.tr('Overview levels (e.g. 2 4 8 16)'),
|
||||
defaultValue=None,
|
||||
optional=True))
|
||||
params.append(QgsProcessingParameterEnum(self.RESAMPLING,
|
||||
self.tr('Resampling method'),
|
||||
options=[i[0] for i in self.methods],
|
||||
allowMultiple=False,
|
||||
defaultValue=0,
|
||||
defaultValue=None,
|
||||
optional=True))
|
||||
params.append(QgsProcessingParameterEnum(self.FORMAT,
|
||||
self.tr('Overviews format'),
|
||||
@ -125,8 +132,9 @@ class gdaladdo(GdalAlgorithm):
|
||||
arguments = []
|
||||
arguments.append(fileName)
|
||||
|
||||
arguments.append('-r')
|
||||
arguments.append(self.methods[self.parameterAsEnum(parameters, self.RESAMPLING, context)][1])
|
||||
if self.RESAMPLING in parameters and parameters[self.RESAMPLING] is not None:
|
||||
arguments.append('-r')
|
||||
arguments.append(self.methods[self.parameterAsEnum(parameters, self.RESAMPLING, context)][1])
|
||||
|
||||
ovrFormat = self.parameterAsEnum(parameters, self.FORMAT, context)
|
||||
if ovrFormat == 1:
|
||||
|
||||
@ -34,6 +34,7 @@ from qgis.testing import (start_app,
|
||||
unittest)
|
||||
|
||||
import AlgorithmsTestBase
|
||||
from processing.algs.gdal.GdalUtils import GdalUtils
|
||||
from processing.algs.gdal.AssignProjection import AssignProjection
|
||||
from processing.algs.gdal.ClipRasterByExtent import ClipRasterByExtent
|
||||
from processing.algs.gdal.ClipRasterByMask import ClipRasterByMask
|
||||
@ -2145,7 +2146,15 @@ class TestGdalRasterAlgorithms(unittest.TestCase, AlgorithmsTestBase.AlgorithmsT
|
||||
'CLEAN': False,
|
||||
'EXTRA': '--config COMPRESS_OVERVIEW JPEG'}, context, feedback),
|
||||
['gdaladdo',
|
||||
source + ' ' + '-r nearest --config COMPRESS_OVERVIEW JPEG 2 4 8 16'])
|
||||
source + ' ' + '--config COMPRESS_OVERVIEW JPEG 2 4 8 16'])
|
||||
|
||||
if GdalUtils.version() >= 230000:
|
||||
# without levels
|
||||
self.assertEqual(
|
||||
alg.getConsoleCommands({'INPUT': source,
|
||||
'CLEAN': False}, context, feedback),
|
||||
['gdaladdo',
|
||||
source])
|
||||
|
||||
# without advanced params
|
||||
self.assertEqual(
|
||||
@ -2153,7 +2162,7 @@ class TestGdalRasterAlgorithms(unittest.TestCase, AlgorithmsTestBase.AlgorithmsT
|
||||
'LEVELS': '2 4 8 16',
|
||||
'CLEAN': False}, context, feedback),
|
||||
['gdaladdo',
|
||||
source + ' ' + '-r nearest 2 4 8 16'])
|
||||
source + ' ' + '2 4 8 16'])
|
||||
|
||||
def testSieve(self):
|
||||
context = QgsProcessingContext()
|
||||
|
||||
Binary file not shown.
Loading…
x
Reference in New Issue
Block a user