Skip to content

Commit

Permalink
Merge pull request #1648 from gioman/processing_gdal_output_type
Browse files Browse the repository at this point in the history
Add raster data type output option to some Processing/GDAL tools otherwise output is always Float64
  • Loading branch information
alexbruy committed Oct 21, 2014
2 parents 338e138 + eea6c6b commit b24572a
Show file tree
Hide file tree
Showing 8 changed files with 69 additions and 18 deletions.
10 changes: 8 additions & 2 deletions python/plugins/processing/algs/gdal/GridAverage.py
Expand Up @@ -32,6 +32,7 @@
from processing.core.parameters import ParameterVector
from processing.core.parameters import ParameterTableField
from processing.core.parameters import ParameterNumber
from processing.core.parameters import ParameterSelection
from processing.core.outputs import OutputRaster
from processing.algs.gdal.GdalUtils import GdalUtils
from processing.tools.system import *
Expand All @@ -47,6 +48,9 @@ class GridAverage(GdalAlgorithm):
ANGLE = 'ANGLE'
NODATA = 'NODATA'
OUTPUT = 'OUTPUT'
RTYPE = 'RTYPE'

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

def commandLineName(self):
return "gdalogr:gridaverage"
Expand All @@ -69,7 +73,8 @@ def defineCharacteristics(self):
0.0, 359.0, 0.0))
self.addParameter(ParameterNumber(self.NODATA, 'Nodata',
0.0, 99999999.999999, 0.0))

self.addParameter(ParameterSelection(self.RTYPE, 'Output raster type',
self.TYPE, 5))
self.addOutput(OutputRaster(self.OUTPUT, 'Output file'))

def processAlgorithm(self, progress):
Expand All @@ -92,7 +97,8 @@ def processAlgorithm(self, progress):

arguments.append('-a')
arguments.append(params)

arguments.append('-ot')
arguments.append(self.TYPE[self.getParameterValue(self.RTYPE)])
arguments.append(unicode(self.getParameterValue(self.INPUT)))
arguments.append(unicode(self.getOutputValue(self.OUTPUT)))

Expand Down
11 changes: 8 additions & 3 deletions python/plugins/processing/algs/gdal/GridDataMetrics.py
Expand Up @@ -49,7 +49,10 @@ class GridDataMetrics(GdalAlgorithm):
ANGLE = 'ANGLE'
NODATA = 'NODATA'
OUTPUT = 'OUTPUT'

RTYPE = 'RTYPE'

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

DATA_METRICS = ['Minimum', 'Maximum', 'Range', 'Count', 'Average distance',
'Average distance between points']

Expand All @@ -76,7 +79,8 @@ def defineCharacteristics(self):
0.0, 359.0, 0.0))
self.addParameter(ParameterNumber(self.NODATA, 'Nodata',
0.0, 99999999.999999, 0.0))

self.addParameter(ParameterSelection(self.RTYPE, 'Output raster type',
self.TYPE, 5))
self.addOutput(OutputRaster(self.OUTPUT, 'Output file'))

def processAlgorithm(self, progress):
Expand Down Expand Up @@ -112,7 +116,8 @@ def processAlgorithm(self, progress):

arguments.append('-a')
arguments.append(params)

arguments.append('-ot')
arguments.append(self.TYPE[self.getParameterValue(self.RTYPE)])
arguments.append(unicode(self.getParameterValue(self.INPUT)))
arguments.append(unicode(self.getOutputValue(self.OUTPUT)))

Expand Down
12 changes: 9 additions & 3 deletions python/plugins/processing/algs/gdal/GridInvDist.py
Expand Up @@ -32,6 +32,7 @@
from processing.core.parameters import ParameterVector
from processing.core.parameters import ParameterTableField
from processing.core.parameters import ParameterNumber
from processing.core.parameters import ParameterSelection
from processing.core.outputs import OutputRaster
from processing.algs.gdal.GdalUtils import GdalUtils
from processing.tools.system import *
Expand All @@ -50,7 +51,10 @@ class GridInvDist(GdalAlgorithm):
ANGLE = 'ANGLE'
NODATA = 'NODATA'
OUTPUT = 'OUTPUT'

RTYPE = 'RTYPE'

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

def commandLineName(self):
return "gdalogr:gridinvdist"

Expand All @@ -77,7 +81,8 @@ def defineCharacteristics(self):
0.0, 359.0, 0.0))
self.addParameter(ParameterNumber(self.NODATA, 'Nodata',
-99999999.999999, 99999999.999999, 0.0))

self.addParameter(ParameterSelection(self.RTYPE, 'Output raster type',
self.TYPE, 5))
self.addOutput(OutputRaster(self.OUTPUT, 'Output file'))

def processAlgorithm(self, progress):
Expand All @@ -103,7 +108,8 @@ def processAlgorithm(self, progress):

arguments.append('-a')
arguments.append(params)

arguments.append('-ot')
arguments.append(self.TYPE[self.getParameterValue(self.RTYPE)])
arguments.append(unicode(self.getParameterValue(self.INPUT)))
arguments.append(unicode(self.getOutputValue(self.OUTPUT)))

Expand Down
12 changes: 9 additions & 3 deletions python/plugins/processing/algs/gdal/GridNearest.py
Expand Up @@ -32,6 +32,7 @@
from processing.core.parameters import ParameterVector
from processing.core.parameters import ParameterTableField
from processing.core.parameters import ParameterNumber
from processing.core.parameters import ParameterSelection
from processing.core.outputs import OutputRaster
from processing.algs.gdal.GdalUtils import GdalUtils
from processing.tools.system import *
Expand All @@ -46,7 +47,10 @@ class GridNearest(GdalAlgorithm):
ANGLE = 'ANGLE'
NODATA = 'NODATA'
OUTPUT = 'OUTPUT'

RTYPE = 'RTYPE'

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

def commandLineName(self):
return "gdalogr:gridnearestneighbor"

Expand All @@ -66,7 +70,8 @@ def defineCharacteristics(self):
0.0, 359.0, 0.0))
self.addParameter(ParameterNumber(self.NODATA, 'Nodata',
0.0, 99999999.999999, 0.0))

self.addParameter(ParameterSelection(self.RTYPE, 'Output raster type',
self.TYPE, 5))
self.addOutput(OutputRaster(self.OUTPUT, 'Output file'))

def processAlgorithm(self, progress):
Expand All @@ -88,7 +93,8 @@ def processAlgorithm(self, progress):

arguments.append('-a')
arguments.append(params)

arguments.append('-ot')
arguments.append(self.TYPE[self.getParameterValue(self.RTYPE)])
arguments.append(unicode(self.getParameterValue(self.INPUT)))
arguments.append(unicode(self.getOutputValue(self.OUTPUT)))

Expand Down
12 changes: 10 additions & 2 deletions python/plugins/processing/algs/gdal/merge.py
Expand Up @@ -30,6 +30,7 @@
from processing.core.outputs import OutputRaster
from processing.core.parameters import ParameterBoolean
from processing.core.parameters import ParameterMultipleInput
from processing.core.parameters import ParameterSelection
from processing.tools.system import *
from processing.algs.gdal.GdalUtils import GdalUtils

Expand All @@ -40,7 +41,10 @@ class merge(GdalAlgorithm):
OUTPUT = 'OUTPUT'
PCT = 'PCT'
SEPARATE = 'SEPARATE'

RTYPE = 'RTYPE'

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

def defineCharacteristics(self):
self.name = 'Merge'
self.group = '[GDAL] Miscellaneous'
Expand All @@ -50,10 +54,14 @@ def defineCharacteristics(self):
'Grab pseudocolor table from first layer', False))
self.addParameter(ParameterBoolean(merge.SEPARATE, 'Layer stack',
False))
self.addParameter(ParameterSelection(self.RTYPE, 'Output raster type',
self.TYPE, 5))
self.addOutput(OutputRaster(merge.OUTPUT, 'Output layer'))

def processAlgorithm(self, progress):
arguments = []
arguments.append('-ot')
arguments.append(self.TYPE[self.getParameterValue(self.RTYPE)])
if self.getParameterValue(merge.SEPARATE):
arguments.append('-separate')
if self.getParameterValue(merge.PCT):
Expand All @@ -72,4 +80,4 @@ def processAlgorithm(self, progress):
else:
commands = ['gdal_merge.py', GdalUtils.escapeAndJoin(arguments)]

GdalUtils.runGdal(commands, progress)
GdalUtils.runGdal(commands, progress)
10 changes: 8 additions & 2 deletions python/plugins/processing/algs/gdal/proximity.py
Expand Up @@ -44,6 +44,9 @@ class proximity(GdalAlgorithm):
NODATA = 'NODATA'
BUF_VAL = 'BUF_VAL'
OUTPUT = 'OUTPUT'
RTYPE = 'RTYPE'

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

DISTUNITS = ['GEO', 'PIXEL']

Expand All @@ -64,13 +67,16 @@ def defineCharacteristics(self):
self.addParameter(ParameterNumber(self.BUF_VAL,
'Fixed buf val (negative value to ignore)', -1,
9999, -1))

self.addParameter(ParameterSelection(self.RTYPE, 'Output raster type',
self.TYPE, 5))
self.addOutput(OutputRaster(self.OUTPUT, 'Output layer'))

def processAlgorithm(self, progress):
output = self.getOutputValue(self.OUTPUT)

arguments = []
arguments.append('-ot')
arguments.append(self.TYPE[self.getParameterValue(self.RTYPE)])
arguments.append(self.getParameterValue(self.INPUT))
arguments.append(output)

Expand Down Expand Up @@ -108,4 +114,4 @@ def processAlgorithm(self, progress):
commands = ['gdal_proximity.py',
GdalUtils.escapeAndJoin(arguments)]

GdalUtils.runGdal(commands, progress)
GdalUtils.runGdal(commands, progress)
9 changes: 8 additions & 1 deletion python/plugins/processing/algs/gdal/translate.py
Expand Up @@ -51,6 +51,9 @@ class translate(GdalAlgorithm):
SRS = 'SRS'
SDS = 'SDS'
EXTRA = 'EXTRA'
RTYPE = 'RTYPE'

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

def commandLineName(self):
return "gdalogr:translate"
Expand Down Expand Up @@ -79,6 +82,8 @@ def defineCharacteristics(self):
False))
self.addParameter(ParameterString(self.EXTRA,
'Additional creation parameters', '', optional=True))
self.addParameter(ParameterSelection(self.RTYPE, 'Output raster type',
self.TYPE, 5))
self.addOutput(OutputRaster(self.OUTPUT, 'Output layer'))

def processAlgorithm(self, progress):
Expand All @@ -96,6 +101,8 @@ def processAlgorithm(self, progress):
arguments = []
arguments.append('-of')
arguments.append(GdalUtils.getFormatShortNameFromFilename(out))
arguments.append('-ot')
arguments.append(self.TYPE[self.getParameterValue(self.RTYPE)])
if outsizePerc == 'True':
arguments.append('-outsize')
arguments.append(outsize + '%')
Expand Down Expand Up @@ -126,4 +133,4 @@ def processAlgorithm(self, progress):
arguments.append(out)

GdalUtils.runGdal(['gdal_translate',
GdalUtils.escapeAndJoin(arguments)], progress)
GdalUtils.escapeAndJoin(arguments)], progress)
11 changes: 9 additions & 2 deletions python/plugins/processing/algs/gdal/warp.py
Expand Up @@ -46,7 +46,10 @@ class warp(GdalAlgorithm):
METHOD_OPTIONS = ['near', 'bilinear', 'cubic', 'cubicspline', 'lanczos']
TR = 'TR'
EXTRA = 'EXTRA'

RTYPE = 'RTYPE'

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

def defineCharacteristics(self):
self.name = 'Warp (reproject)'
self.group = '[GDAL] Projections'
Expand All @@ -62,10 +65,14 @@ def defineCharacteristics(self):
self.METHOD_OPTIONS))
self.addParameter(ParameterString(self.EXTRA,
'Additional creation parameters', '', optional=True))
self.addParameter(ParameterSelection(self.RTYPE, 'Output raster type',
self.TYPE, 5))
self.addOutput(OutputRaster(self.OUTPUT, 'Output layer'))

def processAlgorithm(self, progress):
arguments = []
arguments.append('-ot')
arguments.append(self.TYPE[self.getParameterValue(self.RTYPE)])
arguments.append('-s_srs')
arguments.append(str(self.getParameterValue(self.SOURCE_SRS)))
arguments.append('-t_srs')
Expand All @@ -89,4 +96,4 @@ def processAlgorithm(self, progress):
arguments.append(out)

GdalUtils.runGdal(['gdalwarp', GdalUtils.escapeAndJoin(arguments)],
progress)
progress)

0 comments on commit b24572a

Please sign in to comment.