Skip to content
Permalink
Browse files

[processing][gdal] Expose no data options for gdal merge algorithm

  • Loading branch information
nyalldawson committed Mar 21, 2018
1 parent 1d8ecaf commit b17feaaa97d379ec317b0ea93a05566f368cb9ca
Showing with 29 additions and 0 deletions.
  1. +29 −0 python/plugins/processing/algs/gdal/merge.py
@@ -36,6 +36,7 @@
QgsProcessingParameterEnum,
QgsProcessingParameterString,
QgsProcessingParameterBoolean,
QgsProcessingParameterNumber,
QgsProcessingParameterRasterDestination,
QgsProcessingUtils)
from processing.algs.gdal.GdalAlgorithm import GdalAlgorithm
@@ -53,6 +54,8 @@ class merge(GdalAlgorithm):
SEPARATE = 'SEPARATE'
OPTIONS = 'OPTIONS'
DATA_TYPE = 'DATA_TYPE'
NODATA_INPUT = 'NODATA_INPUT'
NODATA_OUTPUT = 'NODATA_OUTPUT'
OUTPUT = 'OUTPUT'

TYPES = ['Byte', 'Int16', 'UInt16', 'UInt32', 'Int32', 'Float32', 'Float64', 'CInt16', 'CInt32', 'CFloat32', 'CFloat64']
@@ -71,6 +74,22 @@ def initAlgorithm(self, config=None):
self.tr('Place each input file into a separate band'),
defaultValue=False))

nodata_param = QgsProcessingParameterNumber(self.NODATA_INPUT,
self.tr('Input pixel value to treat as "nodata"'),
type=QgsProcessingParameterNumber.Integer,
defaultValue=None,
optional=True)
nodata_param.setFlags(nodata_param.flags() | QgsProcessingParameterDefinition.FlagAdvanced)
self.addParameter(nodata_param)

nodata_out_param = QgsProcessingParameterNumber(self.NODATA_OUTPUT,
self.tr('Assign specified "nodata" value to output'),
type=QgsProcessingParameterNumber.Integer,
defaultValue=None,
optional=True)
nodata_out_param.setFlags(nodata_out_param.flags() | QgsProcessingParameterDefinition.FlagAdvanced)
self.addParameter(nodata_out_param)

options_param = QgsProcessingParameterString(self.OPTIONS,
self.tr('Additional creation parameters'),
defaultValue='',
@@ -115,6 +134,16 @@ def getConsoleCommands(self, parameters, context, feedback, executing=True):
if self.parameterAsBool(parameters, self.SEPARATE, context):
arguments.append('-separate')

if self.NODATA_INPUT in parameters and parameters[self.NODATA_INPUT] is not None:
nodata_input = self.parameterAsInt(parameters, self.NODATA_INPUT, context)
arguments.append('-n')
arguments.append(str(nodata_input))

if self.NODATA_OUTPUT in parameters and parameters[self.NODATA_OUTPUT] is not None:
nodata_output = self.parameterAsInt(parameters, self.NODATA_OUTPUT, context)
arguments.append('-a_nodata')
arguments.append(str(nodata_output))

arguments.append('-ot')
arguments.append(self.TYPES[self.parameterAsEnum(parameters, self.DATA_TYPE, context)])

0 comments on commit b17feaa

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