Skip to content
Permalink
Browse files

[needs-docs][processing] Use input layer data type for gdal algorithms

when appropriate:
- warp (i.e. reproject)
- translate (i.e. file format conversion)
- rearrange bands
- clip by extent/mask
  • Loading branch information
nirvn committed Sep 4, 2018
1 parent 8bae311 commit 8398aae04b30722f11aa70d153fb6f0546beead5
@@ -54,7 +54,7 @@ class ClipRasterByExtent(GdalAlgorithm):
DATA_TYPE = 'DATA_TYPE'
OUTPUT = 'OUTPUT'

TYPES = ['Byte', 'Int16', 'UInt16', 'UInt32', 'Int32', 'Float32', 'Float64', 'CInt16', 'CInt32', 'CFloat32', 'CFloat64']
TYPES = ['Use input layer data type', 'Byte', 'Int16', 'UInt16', 'UInt32', 'Int32', 'Float32', 'Float64', 'CInt16', 'CInt32', 'CFloat32', 'CFloat64']

def __init__(self):
super().__init__()
@@ -84,7 +84,7 @@ def initAlgorithm(self, config=None):
self.tr('Output data type'),
self.TYPES,
allowMultiple=False,
defaultValue=5)
defaultValue=0)
dataType_param.setFlags(dataType_param.flags() | QgsProcessingParameterDefinition.FlagAdvanced)
self.addParameter(dataType_param)

@@ -132,8 +132,9 @@ def getConsoleCommands(self, parameters, context, feedback, executing=True):
if nodata is not None:
arguments.append('-a_nodata {}'.format(nodata))

arguments.append('-ot')
arguments.append(self.TYPES[self.parameterAsEnum(parameters, self.DATA_TYPE, context)])
data_type = self.parameterAsEnum(parameters, self.DATA_TYPE, context)
if data_type:
arguments.append('-ot ' + self.TYPES[data_type])

arguments.append('-of')
arguments.append(QgsRasterFileWriter.driverForExtension(os.path.splitext(out)[1]))
@@ -58,7 +58,7 @@ class ClipRasterByMask(GdalAlgorithm):
DATA_TYPE = 'DATA_TYPE'
OUTPUT = 'OUTPUT'

TYPES = ['Byte', 'Int16', 'UInt16', 'UInt32', 'Int32', 'Float32', 'Float64', 'CInt16', 'CInt32', 'CFloat32', 'CFloat64']
TYPES = ['Use input layer data type', 'Byte', 'Int16', 'UInt16', 'UInt32', 'Int32', 'Float32', 'Float64', 'CInt16', 'CInt32', 'CFloat32', 'CFloat64']

def __init__(self):
super().__init__()
@@ -98,7 +98,7 @@ def initAlgorithm(self, config=None):
self.tr('Output data type'),
self.TYPES,
allowMultiple=False,
defaultValue=5)
defaultValue=0)
dataType_param.setFlags(dataType_param.flags() | QgsProcessingParameterDefinition.FlagAdvanced)
self.addParameter(dataType_param)

@@ -138,8 +138,10 @@ def getConsoleCommands(self, parameters, context, feedback, executing=True):
out = self.parameterAsOutputLayer(parameters, self.OUTPUT, context)

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

data_type = self.parameterAsEnum(parameters, self.DATA_TYPE, context)
if data_type:
arguments.append('-ot ' + self.TYPES[data_type])

arguments.append('-of')
arguments.append(QgsRasterFileWriter.driverForExtension(os.path.splitext(out)[1]))
@@ -52,7 +52,7 @@ class rearrange_bands(GdalAlgorithm):
DATA_TYPE = 'DATA_TYPE'
OUTPUT = 'OUTPUT'

TYPES = ['Byte', 'Int16', 'UInt16', 'UInt32', 'Int32', 'Float32', 'Float64', 'CInt16', 'CInt32', 'CFloat32', 'CFloat64']
TYPES = ['Use input layer data type', 'Byte', 'Int16', 'UInt16', 'UInt32', 'Int32', 'Float32', 'Float64', 'CInt16', 'CInt32', 'CFloat32', 'CFloat64']

def __init__(self):
super().__init__()
@@ -79,7 +79,7 @@ def initAlgorithm(self, config=None):
self.tr('Output data type'),
self.TYPES,
allowMultiple=False,
defaultValue=5)
defaultValue=0)
dataType_param.setFlags(dataType_param.flags() | QgsProcessingParameterDefinition.FlagAdvanced)
self.addParameter(dataType_param)

@@ -121,8 +121,9 @@ def getConsoleCommands(self, parameters, context, feedback, executing=True):
for band in bands:
arguments.append('-b {}'.format(band))

arguments.append('-ot')
arguments.append(self.TYPES[self.parameterAsEnum(parameters, self.DATA_TYPE, context)])
data_type = self.parameterAsEnum(parameters, self.DATA_TYPE, context)
if data_type:
arguments.append('-ot ' + self.TYPES[data_type])

arguments.append('-of')
arguments.append(QgsRasterFileWriter.driverForExtension(os.path.splitext(out)[1]))
@@ -55,7 +55,7 @@ class translate(GdalAlgorithm):
DATA_TYPE = 'DATA_TYPE'
OUTPUT = 'OUTPUT'

TYPES = ['Byte', 'Int16', 'UInt16', 'UInt32', 'Int32', 'Float32', 'Float64', 'CInt16', 'CInt32', 'CFloat32', 'CFloat64']
TYPES = ['Use input layer data type', 'Byte', 'Int16', 'UInt16', 'UInt32', 'Int32', 'Float32', 'Float64', 'CInt16', 'CInt32', 'CFloat32', 'CFloat64']

def __init__(self):
super().__init__()
@@ -89,7 +89,7 @@ def initAlgorithm(self, config=None):
self.tr('Output data type'),
self.TYPES,
allowMultiple=False,
defaultValue=5)
defaultValue=0)
dataType_param.setFlags(dataType_param.flags() | QgsProcessingParameterDefinition.FlagAdvanced)
self.addParameter(dataType_param)

@@ -139,8 +139,9 @@ def getConsoleCommands(self, parameters, context, feedback, executing=True):
if self.parameterAsBool(parameters, self.COPY_SUBDATASETS, context):
arguments.append('-sds')

arguments.append('-ot')
arguments.append(self.TYPES[self.parameterAsEnum(parameters, self.DATA_TYPE, context)])
data_type = self.parameterAsEnum(parameters, self.DATA_TYPE, context)
if data_type:
arguments.append('-ot ' + self.TYPES[data_type])

arguments.append('-of')
arguments.append(QgsRasterFileWriter.driverForExtension(os.path.splitext(out)[1]))
@@ -61,7 +61,7 @@ class warp(GdalAlgorithm):
MULTITHREADING = 'MULTITHREADING'
OUTPUT = 'OUTPUT'

TYPES = ['Byte', 'Int16', 'UInt16', 'UInt32', 'Int32', 'Float32', 'Float64', 'CInt16', 'CInt32', 'CFloat32', 'CFloat64']
TYPES = ['Use input layer data type', 'Byte', 'Int16', 'UInt16', 'UInt32', 'Int32', 'Float32', 'Float64', 'CInt16', 'CInt32', 'CFloat32', 'CFloat64']

def __init__(self):
super().__init__()
@@ -117,7 +117,7 @@ def initAlgorithm(self, config=None):
self.tr('Output data type'),
self.TYPES,
allowMultiple=False,
defaultValue=5)
defaultValue=0)
dataType_param.setFlags(dataType_param.flags() | QgsProcessingParameterDefinition.FlagAdvanced)
self.addParameter(dataType_param)

@@ -216,8 +216,9 @@ def getConsoleCommands(self, parameters, context, feedback, executing=True):
if self.parameterAsBool(parameters, self.MULTITHREADING, context):
arguments.append('-multi')

arguments.append('-ot')
arguments.append(self.TYPES[self.parameterAsEnum(parameters, self.DATA_TYPE, context)])
data_type = self.parameterAsEnum(parameters, self.DATA_TYPE, context)
if data_type:
arguments.append('-ot ' + self.TYPES[data_type])

out = self.parameterAsOutputLayer(parameters, self.OUTPUT, context)
arguments.append('-of')

0 comments on commit 8398aae

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