Skip to content
Permalink
Browse files

Add raster data type output option to some Processing/GDAL tools othe…

…rewise output is always Float64
  • Loading branch information
Giovanni Manghi
Giovanni Manghi committed Oct 21, 2014
1 parent ba8a60f commit 93efeeff83dcf791ce910b6ca1a40ab30b0db670
@@ -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 *
@@ -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"
@@ -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):
@@ -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)))

@@ -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']

@@ -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):
@@ -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)))

@@ -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 *
@@ -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"

@@ -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):
@@ -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)))

@@ -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 *
@@ -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"

@@ -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):
@@ -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)))

@@ -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

@@ -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'
@@ -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):
@@ -72,4 +80,4 @@ def processAlgorithm(self, progress):
else:
commands = ['gdal_merge.py', GdalUtils.escapeAndJoin(arguments)]

GdalUtils.runGdal(commands, progress)
GdalUtils.runGdal(commands, progress)
@@ -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']

@@ -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)

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

GdalUtils.runGdal(commands, progress)
GdalUtils.runGdal(commands, progress)
@@ -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"
@@ -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):
@@ -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 + '%')
@@ -126,4 +133,4 @@ def processAlgorithm(self, progress):
arguments.append(out)

GdalUtils.runGdal(['gdal_translate',
GdalUtils.escapeAndJoin(arguments)], progress)
GdalUtils.escapeAndJoin(arguments)], progress)
@@ -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'
@@ -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')
@@ -89,4 +96,4 @@ def processAlgorithm(self, progress):
arguments.append(out)

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

0 comments on commit 93efeef

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