Skip to content

Commit

Permalink
Add 'Int8' as raster data types to Processing GDAL algorithms (#51755)
Browse files Browse the repository at this point in the history
  • Loading branch information
DelazJ committed Jun 1, 2023
1 parent cc95fc0 commit 52ec601
Show file tree
Hide file tree
Showing 19 changed files with 112 additions and 38 deletions.
5 changes: 4 additions & 1 deletion python/plugins/processing/algs/gdal/ClipRasterByExtent.py
Expand Up @@ -54,7 +54,7 @@ def __init__(self):

def initAlgorithm(self, config=None):

self.TYPES = [self.tr('Use Input Layer Data Type'), 'Byte', 'Int16', 'UInt16', 'UInt32', 'Int32', 'Float32', 'Float64', 'CInt16', 'CInt32', 'CFloat32', 'CFloat64']
self.TYPES = [self.tr('Use Input Layer Data Type'), 'Byte', 'Int16', 'UInt16', 'UInt32', 'Int32', 'Float32', 'Float64', 'CInt16', 'CInt32', 'CFloat32', 'CFloat64', 'Int8']

self.addParameter(QgsProcessingParameterRasterLayer(self.INPUT,
self.tr('Input layer')))
Expand Down Expand Up @@ -147,6 +147,9 @@ def getConsoleCommands(self, parameters, context, feedback, executing=True):

data_type = self.parameterAsEnum(parameters, self.DATA_TYPE, context)
if data_type:
if self.TYPES[data_type] == 'Int8' and GdalUtils.version() < 3070000:
raise QgsProcessingException(self.tr('Int8 data type requires GDAL version 3.7 or later'))

arguments.append('-ot ' + self.TYPES[data_type])

arguments.append('-of')
Expand Down
5 changes: 4 additions & 1 deletion python/plugins/processing/algs/gdal/ClipRasterByMask.py
Expand Up @@ -66,7 +66,7 @@ def __init__(self):

def initAlgorithm(self, config=None):

self.TYPES = [self.tr('Use Input Layer Data Type'), 'Byte', 'Int16', 'UInt16', 'UInt32', 'Int32', 'Float32', 'Float64', 'CInt16', 'CInt32', 'CFloat32', 'CFloat64']
self.TYPES = [self.tr('Use Input Layer Data Type'), 'Byte', 'Int16', 'UInt16', 'UInt32', 'Int32', 'Float32', 'Float64', 'CInt16', 'CInt32', 'CFloat32', 'CFloat64', 'Int8']

self.addParameter(QgsProcessingParameterRasterLayer(self.INPUT,
self.tr('Input layer')))
Expand Down Expand Up @@ -204,6 +204,9 @@ def getConsoleCommands(self, parameters, context, feedback, executing=True):

data_type = self.parameterAsEnum(parameters, self.DATA_TYPE, context)
if data_type:
if self.TYPES[data_type] == 'Int8' and GdalUtils.version() < 3070000:
raise QgsProcessingException(self.tr('Int8 data type requires GDAL version 3.7 or later'))

arguments.append('-ot ' + self.TYPES[data_type])

arguments.append('-of')
Expand Down
11 changes: 8 additions & 3 deletions python/plugins/processing/algs/gdal/GridAverage.py
Expand Up @@ -25,6 +25,7 @@

from qgis.core import (QgsRasterFileWriter,
QgsProcessing,
QgsProcessingException,
QgsProcessingParameterDefinition,
QgsProcessingParameterFeatureSource,
QgsProcessingParameterEnum,
Expand All @@ -51,7 +52,7 @@ class GridAverage(GdalAlgorithm):
DATA_TYPE = 'DATA_TYPE'
OUTPUT = 'OUTPUT'

TYPES = ['Byte', 'Int16', 'UInt16', 'UInt32', 'Int32', 'Float32', 'Float64', 'CInt16', 'CInt32', 'CFloat32', 'CFloat64']
TYPES = ['Byte', 'Int16', 'UInt16', 'UInt32', 'Int32', 'Float32', 'Float64', 'CInt16', 'CInt32', 'CFloat32', 'CFloat64', 'Int8']

def __init__(self):
super().__init__()
Expand Down Expand Up @@ -162,8 +163,12 @@ def getConsoleCommands(self, parameters, context, feedback, executing=True):

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

data_type = self.parameterAsEnum(parameters, self.DATA_TYPE, context)
if self.TYPES[data_type] == 'Int8' and GdalUtils.version() < 3070000:
raise QgsProcessingException(self.tr('Int8 data type requires GDAL version 3.7 or later'))

arguments.append('-ot ' + self.TYPES[data_type])

out = self.parameterAsOutputLayer(parameters, self.OUTPUT, context)
self.setOutputValue(self.OUTPUT, out)
Expand Down
11 changes: 8 additions & 3 deletions python/plugins/processing/algs/gdal/GridDataMetrics.py
Expand Up @@ -25,6 +25,7 @@

from qgis.core import (QgsRasterFileWriter,
QgsProcessing,
QgsProcessingException,
QgsProcessingParameterDefinition,
QgsProcessingParameterFeatureSource,
QgsProcessingParameterEnum,
Expand Down Expand Up @@ -52,7 +53,7 @@ class GridDataMetrics(GdalAlgorithm):
DATA_TYPE = 'DATA_TYPE'
OUTPUT = 'OUTPUT'

TYPES = ['Byte', 'Int16', 'UInt16', 'UInt32', 'Int32', 'Float32', 'Float64', 'CInt16', 'CInt32', 'CFloat32', 'CFloat64']
TYPES = ['Byte', 'Int16', 'UInt16', 'UInt32', 'Int32', 'Float32', 'Float64', 'CInt16', 'CInt32', 'CFloat32', 'CFloat64', 'Int8']

def __init__(self):
super().__init__()
Expand Down Expand Up @@ -176,8 +177,12 @@ def getConsoleCommands(self, parameters, context, feedback, executing=True):

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

data_type = self.parameterAsEnum(parameters, self.DATA_TYPE, context)
if self.TYPES[data_type] == 'Int8' and GdalUtils.version() < 3070000:
raise QgsProcessingException(self.tr('Int8 data type requires GDAL version 3.7 or later'))

arguments.append('-ot ' + self.TYPES[data_type])

out = self.parameterAsOutputLayer(parameters, self.OUTPUT, context)
self.setOutputValue(self.OUTPUT, out)
Expand Down
11 changes: 8 additions & 3 deletions python/plugins/processing/algs/gdal/GridInverseDistance.py
Expand Up @@ -25,6 +25,7 @@

from qgis.core import (QgsRasterFileWriter,
QgsProcessing,
QgsProcessingException,
QgsProcessingParameterDefinition,
QgsProcessingParameterFeatureSource,
QgsProcessingParameterEnum,
Expand Down Expand Up @@ -54,7 +55,7 @@ class GridInverseDistance(GdalAlgorithm):
DATA_TYPE = 'DATA_TYPE'
OUTPUT = 'OUTPUT'

TYPES = ['Byte', 'Int16', 'UInt16', 'UInt32', 'Int32', 'Float32', 'Float64', 'CInt16', 'CInt32', 'CFloat32', 'CFloat64']
TYPES = ['Byte', 'Int16', 'UInt16', 'UInt32', 'Int32', 'Float32', 'Float64', 'CInt16', 'CInt32', 'CFloat32', 'CFloat64', 'Int8']

def __init__(self):
super().__init__()
Expand Down Expand Up @@ -185,8 +186,12 @@ def getConsoleCommands(self, parameters, context, feedback, executing=True):

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

data_type = self.parameterAsEnum(parameters, self.DATA_TYPE, context)
if self.TYPES[data_type] == 'Int8' and GdalUtils.version() < 3070000:
raise QgsProcessingException(self.tr('Int8 data type requires GDAL version 3.7 or later'))

arguments.append('-ot ' + self.TYPES[data_type])

out = self.parameterAsOutputLayer(parameters, self.OUTPUT, context)
self.setOutputValue(self.OUTPUT, out)
Expand Down
Expand Up @@ -25,6 +25,7 @@

from qgis.core import (QgsRasterFileWriter,
QgsProcessing,
QgsProcessingException,
QgsProcessingParameterDefinition,
QgsProcessingParameterFeatureSource,
QgsProcessingParameterEnum,
Expand Down Expand Up @@ -52,7 +53,7 @@ class GridInverseDistanceNearestNeighbor(GdalAlgorithm):
DATA_TYPE = 'DATA_TYPE'
OUTPUT = 'OUTPUT'

TYPES = ['Byte', 'Int16', 'UInt16', 'UInt32', 'Int32', 'Float32', 'Float64', 'CInt16', 'CInt32', 'CFloat32', 'CFloat64']
TYPES = ['Byte', 'Int16', 'UInt16', 'UInt32', 'Int32', 'Float32', 'Float64', 'CInt16', 'CInt32', 'CFloat32', 'CFloat64', 'Int8']

def __init__(self):
super().__init__()
Expand Down Expand Up @@ -170,8 +171,12 @@ def getConsoleCommands(self, parameters, context, feedback, executing=True):

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

data_type = self.parameterAsEnum(parameters, self.DATA_TYPE, context)
if self.TYPES[data_type] == 'Int8' and GdalUtils.version() < 3070000:
raise QgsProcessingException(self.tr('Int8 data type requires GDAL version 3.7 or later'))

arguments.append('-ot ' + self.TYPES[data_type])

out = self.parameterAsOutputLayer(parameters, self.OUTPUT, context)
self.setOutputValue(self.OUTPUT, out)
Expand Down
11 changes: 8 additions & 3 deletions python/plugins/processing/algs/gdal/GridLinear.py
Expand Up @@ -25,6 +25,7 @@

from qgis.core import (QgsRasterFileWriter,
QgsProcessing,
QgsProcessingException,
QgsProcessingParameterDefinition,
QgsProcessingParameterFeatureSource,
QgsProcessingParameterEnum,
Expand All @@ -49,7 +50,7 @@ class GridLinear(GdalAlgorithm):
DATA_TYPE = 'DATA_TYPE'
OUTPUT = 'OUTPUT'

TYPES = ['Byte', 'Int16', 'UInt16', 'UInt32', 'Int32', 'Float32', 'Float64', 'CInt16', 'CInt32', 'CFloat32', 'CFloat64']
TYPES = ['Byte', 'Int16', 'UInt16', 'UInt32', 'Int32', 'Float32', 'Float64', 'CInt16', 'CInt32', 'CFloat32', 'CFloat64', 'Int8']

def __init__(self):
super().__init__()
Expand Down Expand Up @@ -142,8 +143,12 @@ def getConsoleCommands(self, parameters, context, feedback, executing=True):

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

data_type = self.parameterAsEnum(parameters, self.DATA_TYPE, context)
if self.TYPES[data_type] == 'Int8' and GdalUtils.version() < 3070000:
raise QgsProcessingException(self.tr('Int8 data type requires GDAL version 3.7 or later'))

arguments.append('-ot ' + self.TYPES[data_type])

out = self.parameterAsOutputLayer(parameters, self.OUTPUT, context)
self.setOutputValue(self.OUTPUT, out)
Expand Down
11 changes: 8 additions & 3 deletions python/plugins/processing/algs/gdal/GridNearestNeighbor.py
Expand Up @@ -25,6 +25,7 @@

from qgis.core import (QgsRasterFileWriter,
QgsProcessing,
QgsProcessingException,
QgsProcessingParameterDefinition,
QgsProcessingParameterFeatureSource,
QgsProcessingParameterEnum,
Expand All @@ -50,7 +51,7 @@ class GridNearestNeighbor(GdalAlgorithm):
DATA_TYPE = 'DATA_TYPE'
OUTPUT = 'OUTPUT'

TYPES = ['Byte', 'Int16', 'UInt16', 'UInt32', 'Int32', 'Float32', 'Float64', 'CInt16', 'CInt32', 'CFloat32', 'CFloat64']
TYPES = ['Byte', 'Int16', 'UInt16', 'UInt32', 'Int32', 'Float32', 'Float64', 'CInt16', 'CInt32', 'CFloat32', 'CFloat64', 'Int8']

def __init__(self):
super().__init__()
Expand Down Expand Up @@ -156,8 +157,12 @@ def getConsoleCommands(self, parameters, context, feedback, executing=True):

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

data_type = self.parameterAsEnum(parameters, self.DATA_TYPE, context)
if self.TYPES[data_type] == 'Int8' and GdalUtils.version() < 3070000:
raise QgsProcessingException(self.tr('Int8 data type requires GDAL version 3.7 or later'))

arguments.append('-ot ' + self.TYPES[data_type])

out = self.parameterAsOutputLayer(parameters, self.OUTPUT, context)
self.setOutputValue(self.OUTPUT, out)
Expand Down
13 changes: 10 additions & 3 deletions python/plugins/processing/algs/gdal/gdalcalc.py
Expand Up @@ -58,7 +58,8 @@ class gdalcalc(GdalAlgorithm):
OPTIONS = 'OPTIONS'
EXTRA = 'EXTRA'
RTYPE = 'RTYPE'
TYPE = ['Byte', 'Int16', 'UInt16', 'UInt32', 'Int32', 'Float32', 'Float64']

TYPE = ['Byte', 'Int16', 'UInt16', 'UInt32', 'Int32', 'Float32', 'Float64', 'CInt16', 'CInt32', 'CFloat32', 'CFloat64', 'Int8']

def __init__(self):
super().__init__()
Expand Down Expand Up @@ -218,10 +219,16 @@ def getConsoleCommands(self, parameters, context, feedback, executing=True):
f'--calc "{formula}"',
'--format',
GdalUtils.getFormatShortNameFromFilename(out),
'--type',
self.TYPE[self.parameterAsEnum(parameters, self.RTYPE, context)]
]

rtype = self.parameterAsEnum(parameters, self.RTYPE, context)
if self.TYPE[rtype] in ['CInt16', 'CInt32', 'CFloat32', 'CFloat64'] and GdalUtils.version() < 3050300:
raise QgsProcessingException(self.tr('{} data type requires GDAL version 3.5.3 or later').format(self.TYPE[rtype]))
if self.TYPE[rtype] == 'Int8' and GdalUtils.version() < 3070000:
raise QgsProcessingException(self.tr('Int8 data type requires GDAL version 3.7 or later'))

arguments.append('--type ' + self.TYPE[rtype])

if noData is not None:
arguments.append('--NoDataValue')
arguments.append(noData)
Expand Down
10 changes: 7 additions & 3 deletions python/plugins/processing/algs/gdal/merge.py
Expand Up @@ -25,6 +25,7 @@

from qgis.core import (QgsRasterFileWriter,
QgsProcessing,
QgsProcessingException,
QgsProcessingParameterDefinition,
QgsProcessingParameterMultipleLayers,
QgsProcessingParameterEnum,
Expand All @@ -51,7 +52,7 @@ class merge(GdalAlgorithm):
NODATA_OUTPUT = 'NODATA_OUTPUT'
OUTPUT = 'OUTPUT'

TYPES = ['Byte', 'Int16', 'UInt16', 'UInt32', 'Int32', 'Float32', 'Float64', 'CInt16', 'CInt32', 'CFloat32', 'CFloat64']
TYPES = ['Byte', 'Int16', 'UInt16', 'UInt32', 'Int32', 'Float32', 'Float64', 'CInt16', 'CInt32', 'CFloat32', 'CFloat64', 'Int8']

def __init__(self):
super().__init__()
Expand Down Expand Up @@ -148,8 +149,11 @@ def getConsoleCommands(self, parameters, context, feedback, executing=True):
arguments.append('-a_nodata')
arguments.append(str(nodata_output))

arguments.append('-ot')
arguments.append(self.TYPES[self.parameterAsEnum(parameters, self.DATA_TYPE, context)])
data_type = self.parameterAsEnum(parameters, self.DATA_TYPE, context)
if self.TYPES[data_type] == 'Int8' and GdalUtils.version() < 3070000:
raise QgsProcessingException(self.tr('Int8 data type requires GDAL version 3.7 or later'))

arguments.append('-ot ' + self.TYPES[data_type])

arguments.append('-of')
arguments.append(QgsRasterFileWriter.driverForExtension(os.path.splitext(out)[1]))
Expand Down
9 changes: 6 additions & 3 deletions python/plugins/processing/algs/gdal/proximity.py
Expand Up @@ -53,7 +53,7 @@ class proximity(GdalAlgorithm):
DATA_TYPE = 'DATA_TYPE'
OUTPUT = 'OUTPUT'

TYPES = ['Byte', 'Int16', 'UInt16', 'UInt32', 'Int32', 'Float32', 'Float64', 'CInt16', 'CInt32', 'CFloat32', 'CFloat64']
TYPES = ['Byte', 'Int16', 'UInt16', 'UInt32', 'Int32', 'Float32', 'Float64', 'CInt16', 'CInt32', 'CFloat32', 'CFloat64', 'Int8']

def icon(self):
return QIcon(os.path.join(pluginPath, 'images', 'gdaltools', 'proximity.png'))
Expand Down Expand Up @@ -179,8 +179,11 @@ def getConsoleCommands(self, parameters, context, feedback, executing=True):
arguments.append('-fixed-buf-val')
arguments.append(str(replaceValue))

arguments.append('-ot')
arguments.append(self.TYPES[self.parameterAsEnum(parameters, self.DATA_TYPE, context)])
data_type = self.parameterAsEnum(parameters, self.DATA_TYPE, context)
if self.TYPES[data_type] == 'Int8' and GdalUtils.version() < 3070000:
raise QgsProcessingException(self.tr('Int8 data type requires GDAL version 3.7 or later'))

arguments.append('-ot ' + self.TYPES[data_type])

arguments.append('-of')
arguments.append(QgsRasterFileWriter.driverForExtension(os.path.splitext(out)[1]))
Expand Down
9 changes: 6 additions & 3 deletions python/plugins/processing/algs/gdal/rasterize.py
Expand Up @@ -60,7 +60,7 @@ class rasterize(GdalAlgorithm):
EXTRA = 'EXTRA'
OUTPUT = 'OUTPUT'

TYPES = ['Byte', 'Int16', 'UInt16', 'UInt32', 'Int32', 'Float32', 'Float64', 'CInt16', 'CInt32', 'CFloat32', 'CFloat64']
TYPES = ['Byte', 'Int16', 'UInt16', 'UInt32', 'Int32', 'Float32', 'Float64', 'CInt16', 'CInt32', 'CFloat32', 'CFloat64', 'Int8']

def __init__(self):
super().__init__()
Expand Down Expand Up @@ -221,8 +221,11 @@ def getConsoleCommands(self, parameters, context, feedback, executing=True):
arguments.append(extent.xMaximum())
arguments.append(extent.yMaximum())

arguments.append('-ot')
arguments.append(self.TYPES[self.parameterAsEnum(parameters, self.DATA_TYPE, context)])
data_type = self.parameterAsEnum(parameters, self.DATA_TYPE, context)
if self.TYPES[data_type] == 'Int8' and GdalUtils.version() < 3070000:
raise QgsProcessingException(self.tr('Int8 data type requires GDAL version 3.7 or later'))

arguments.append('-ot ' + self.TYPES[data_type])

out = self.parameterAsOutputLayer(parameters, self.OUTPUT, context)
self.setOutputValue(self.OUTPUT, out)
Expand Down
5 changes: 4 additions & 1 deletion python/plugins/processing/algs/gdal/rearrange_bands.py
Expand Up @@ -50,7 +50,7 @@ def __init__(self):

def initAlgorithm(self, config=None):

self.TYPES = [self.tr('Use Input Layer Data Type'), 'Byte', 'Int16', 'UInt16', 'UInt32', 'Int32', 'Float32', 'Float64', 'CInt16', 'CInt32', 'CFloat32', 'CFloat64']
self.TYPES = [self.tr('Use Input Layer Data Type'), 'Byte', 'Int16', 'UInt16', 'UInt32', 'Int32', 'Float32', 'Float64', 'CInt16', 'CInt32', 'CFloat32', 'CFloat64', 'Int8']

self.addParameter(QgsProcessingParameterRasterLayer(self.INPUT, self.tr('Input layer')))
self.addParameter(QgsProcessingParameterBand(self.BANDS,
Expand Down Expand Up @@ -118,6 +118,9 @@ def getConsoleCommands(self, parameters, context, feedback, executing=True):

data_type = self.parameterAsEnum(parameters, self.DATA_TYPE, context)
if data_type:
if self.TYPES[data_type] == 'Int8' and GdalUtils.version() < 3070000:
raise QgsProcessingException(self.tr('Int8 data type requires GDAL version 3.7 or later'))

arguments.append('-ot ' + self.TYPES[data_type])

arguments.append('-of')
Expand Down
10 changes: 7 additions & 3 deletions python/plugins/processing/algs/gdal/retile.py
Expand Up @@ -20,6 +20,7 @@
__copyright__ = '(C) 2016, Médéric Ribreux'

from qgis.core import (QgsProcessing,
QgsProcessingException,
QgsProcessingParameterDefinition,
QgsProcessingParameterMultipleLayers,
QgsProcessingParameterCrs,
Expand Down Expand Up @@ -53,7 +54,7 @@ class retile(GdalAlgorithm):
OUTPUT = 'OUTPUT'
OUTPUT_CSV = 'OUTPUT_CSV'

TYPES = ['Byte', 'Int16', 'UInt16', 'UInt32', 'Int32', 'Float32', 'Float64', 'CInt16', 'CInt32', 'CFloat32', 'CFloat64']
TYPES = ['Byte', 'Int16', 'UInt16', 'UInt32', 'Int32', 'Float32', 'Float64', 'CInt16', 'CInt32', 'CFloat32', 'CFloat64', 'Int8']

def __init__(self):
super().__init__()
Expand Down Expand Up @@ -182,8 +183,11 @@ def getConsoleCommands(self, parameters, context, feedback, executing=True):
arguments.append('-r')
arguments.append(self.methods[self.parameterAsEnum(parameters, self.RESAMPLING, context)][1])

arguments.append('-ot')
arguments.append(self.TYPES[self.parameterAsEnum(parameters, self.DATA_TYPE, context)])
data_type = self.parameterAsEnum(parameters, self.DATA_TYPE, context)
if self.TYPES[data_type] == 'Int8' and GdalUtils.version() < 3070000:
raise QgsProcessingException(self.tr('Int8 data type requires GDAL version 3.7 or later'))

arguments.append('-ot ' + self.TYPES[data_type])

options = self.parameterAsString(parameters, self.OPTIONS, context)
if options:
Expand Down

0 comments on commit 52ec601

Please sign in to comment.