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