mirror of
https://github.com/qgis/QGIS.git
synced 2025-04-15 00:04:00 -04:00
allow to pass additional parameters to the clip raster by mask algorithm
This commit is contained in:
parent
d40d040ebe
commit
0128135c64
@ -59,6 +59,7 @@ class ClipRasterByMask(GdalAlgorithm):
|
||||
OPTIONS = 'OPTIONS'
|
||||
DATA_TYPE = 'DATA_TYPE'
|
||||
MULTITHREADING = 'MULTITHREADING'
|
||||
EXTRA = 'EXTRA'
|
||||
OUTPUT = 'OUTPUT'
|
||||
|
||||
def __init__(self):
|
||||
@ -106,11 +107,13 @@ class ClipRasterByMask(GdalAlgorithm):
|
||||
type=QgsProcessingParameterNumber.Double,
|
||||
defaultValue=None,
|
||||
optional=True))
|
||||
|
||||
multithreading_param = QgsProcessingParameterBoolean(self.MULTITHREADING,
|
||||
self.tr('Use multithreaded warping implementation'),
|
||||
defaultValue=False)
|
||||
multithreading_param.setFlags(multithreading_param.flags() | QgsProcessingParameterDefinition.FlagAdvanced)
|
||||
self.addParameter(multithreading_param)
|
||||
|
||||
options_param = QgsProcessingParameterString(self.OPTIONS,
|
||||
self.tr('Additional creation options'),
|
||||
defaultValue='',
|
||||
@ -129,6 +132,13 @@ class ClipRasterByMask(GdalAlgorithm):
|
||||
dataType_param.setFlags(dataType_param.flags() | QgsProcessingParameterDefinition.FlagAdvanced)
|
||||
self.addParameter(dataType_param)
|
||||
|
||||
extra_param = QgsProcessingParameterString(self.EXTRA,
|
||||
self.tr('Additional command-line parameters'),
|
||||
defaultValue=None,
|
||||
optional=True)
|
||||
extra_param.setFlags(extra_param.flags() | QgsProcessingParameterDefinition.FlagAdvanced)
|
||||
self.addParameter(extra_param)
|
||||
|
||||
self.addParameter(QgsProcessingParameterRasterDestination(self.OUTPUT,
|
||||
self.tr('Clipped (mask)')))
|
||||
|
||||
@ -223,6 +233,10 @@ class ClipRasterByMask(GdalAlgorithm):
|
||||
if options:
|
||||
arguments.extend(GdalUtils.parseCreationOptions(options))
|
||||
|
||||
if self.EXTRA in parameters and parameters[self.EXTRA] not in (None, ''):
|
||||
extra = self.parameterAsString(parameters, self.EXTRA, context)
|
||||
arguments.append(extra)
|
||||
|
||||
arguments.append(inLayer.source())
|
||||
arguments.append(out)
|
||||
|
||||
|
@ -649,6 +649,29 @@ class TestGdalAlgorithms(unittest.TestCase, AlgorithmsTestBase.AlgorithmsTest):
|
||||
'-ot Float32 -of JPEG -cutline ' +
|
||||
mask + ' -crop_to_cutline -dstnodata 0.0 ' + source + ' ' +
|
||||
outdir + '/check.jpg'])
|
||||
# with creation options
|
||||
self.assertEqual(
|
||||
alg.getConsoleCommands({'INPUT': source,
|
||||
'MASK': mask,
|
||||
'OPTIONS': 'COMPRESS=DEFLATE|PREDICTOR=2|ZLEVEL=9',
|
||||
'OUTPUT': outdir + '/check.jpg'}, context, feedback),
|
||||
['gdalwarp',
|
||||
'-of JPEG -cutline ' +
|
||||
mask + ' -crop_to_cutline -co COMPRESS=DEFLATE -co PREDICTOR=2 -co ZLEVEL=9 ' +
|
||||
source + ' ' +
|
||||
outdir + '/check.jpg'])
|
||||
# with multothreading and additional parameters
|
||||
self.assertEqual(
|
||||
alg.getConsoleCommands({'INPUT': source,
|
||||
'MASK': mask,
|
||||
'MULTITHREADING': True,
|
||||
'EXTRA': '-nosrcalpha -wm 2048 -nomd',
|
||||
'OUTPUT': outdir + '/check.jpg'}, context, feedback),
|
||||
['gdalwarp',
|
||||
'-of JPEG -cutline ' +
|
||||
mask + ' -crop_to_cutline -multi -nosrcalpha -wm 2048 -nomd ' +
|
||||
source + ' ' +
|
||||
outdir + '/check.jpg'])
|
||||
|
||||
def testContour(self):
|
||||
context = QgsProcessingContext()
|
||||
|
Loading…
x
Reference in New Issue
Block a user