Skip to content
Permalink
Browse files

[processing] add user-defined parameters to gdal_rasterize

  • Loading branch information
alexbruy authored and nyalldawson committed Jan 5, 2020
1 parent b511841 commit 5e62e60de99895e183db59d9d11ab43350a1be26
@@ -57,6 +57,7 @@ class rasterize(GdalAlgorithm):
ALL_TOUCH = 'ALL_TOUCH'
OPTIONS = 'OPTIONS'
DATA_TYPE = 'DATA_TYPE'
EXTRA = 'EXTRA'
OUTPUT = 'OUTPUT'

TYPES = ['Byte', 'Int16', 'UInt16', 'UInt32', 'Int32', 'Float32', 'Float64', 'CInt16', 'CInt32', 'CFloat32', 'CFloat64']
@@ -133,6 +134,13 @@ def initAlgorithm(self, config=None):
invert_param.setFlags(invert_param.flags() | QgsProcessingParameterDefinition.FlagAdvanced)
self.addParameter(invert_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('Rasterized')))

@@ -207,11 +215,15 @@ def getConsoleCommands(self, parameters, context, feedback, executing=True):
self.setOutputValue(self.OUTPUT, out)
arguments.append('-of')
arguments.append(QgsRasterFileWriter.driverForExtension(os.path.splitext(out)[1]))
options = self.parameterAsString(parameters, self.OPTIONS, context)

options = self.parameterAsString(parameters, self.OPTIONS, context)
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(ogrLayer)
arguments.append(out)

@@ -1507,6 +1507,16 @@ def testRasterize(self):
source + ' ' +
outdir + '/check.jpg'])

self.assertEqual(
alg.getConsoleCommands({'INPUT': source,
'FIELD': 'id',
'EXTRA': '-at -add',
'OUTPUT': outdir + '/check.jpg'}, context, feedback),
['gdal_rasterize',
'-l polys2 -a id -ts 0.0 0.0 -ot Float32 -of JPEG -at -add' +
source + ' ' +
outdir + '/check.jpg'])

def testRasterizeOver(self):
context = QgsProcessingContext()
feedback = QgsProcessingFeedback()

0 comments on commit 5e62e60

Please sign in to comment.
You can’t perform that action at this time.