Skip to content
Permalink
Browse files

Merge pull request #3033 from rldhont/processing_gdal_optional

[Processing] well manage optional parameters in GDAL algorithms
  • Loading branch information
alexbruy committed Apr 26, 2016
2 parents 9a05558 + 793b712 commit 2ba252b34409349aeb84a43aa644c8fc00c816f7
@@ -107,9 +107,13 @@ def defineCharacteristics(self):

def getConsoleCommands(self):
out = self.getOutputValue(self.OUTPUT)
noData = unicode(self.getParameterValue(self.NO_DATA))
noData = self.getParameterValue(self.NO_DATA)
if noData is not None:
noData = unicode(noData)
projwin = unicode(self.getParameterValue(self.PROJWIN))
extra = unicode(self.getParameterValue(self.EXTRA))
extra = self.getParameterValue(self.EXTRA)
if extra is not None:
extra = unicode(extra)
jpegcompression = unicode(self.getParameterValue(self.JPEGCOMPRESSION))
predictor = unicode(self.getParameterValue(self.PREDICTOR))
zlevel = unicode(self.getParameterValue(self.ZLEVEL))
@@ -123,7 +127,7 @@ def getConsoleCommands(self):
arguments.append(GdalUtils.getFormatShortNameFromFilename(out))
arguments.append('-ot')
arguments.append(self.TYPE[self.getParameterValue(self.RTYPE)])
if len(noData) > 0:
if noData and len(noData) > 0:
arguments.append('-a_nodata')
arguments.append(noData)

@@ -134,7 +138,7 @@ def getConsoleCommands(self):
arguments.append(regionCoords[1])
arguments.append(regionCoords[2])

if len(extra) > 0:
if extra and len(extra) > 0:
arguments.append(extra)
if GdalUtils.getFormatShortNameFromFilename(out) == "GTiff":
arguments.append("-co COMPRESS=" + compress)
@@ -125,11 +125,15 @@ def getConsoleCommands(self):
maskLayer = dataobjects.getObjectFromUri(
self.getParameterValue(self.MASK))
ogrMask = ogrConnectionString(mask)[1:-1]
noData = unicode(self.getParameterValue(self.NO_DATA))
noData = self.getParameterValue(self.NO_DATA)
if noData is not None:
noData = unicode(noData)
addAlphaBand = self.getParameterValue(self.ALPHA_BAND)
cropToCutline = self.getParameterValue(self.CROP_TO_CUTLINE)
keepResolution = self.getParameterValue(self.KEEP_RESOLUTION)
extra = unicode(self.getParameterValue(self.EXTRA))
extra = self.getParameterValue(self.EXTRA)
if extra is not None:
extra = unicode(extra)
jpegcompression = unicode(self.getParameterValue(self.JPEGCOMPRESSION))
predictor = unicode(self.getParameterValue(self.PREDICTOR))
zlevel = unicode(self.getParameterValue(self.ZLEVEL))
@@ -144,7 +148,7 @@ def getConsoleCommands(self):
arguments.append('-q')
arguments.append('-of')
arguments.append(GdalUtils.getFormatShortNameFromFilename(out))
if len(noData) > 0:
if noData and len(noData) > 0:
arguments.append('-dstnodata')
arguments.append(noData)

@@ -169,7 +173,7 @@ def getConsoleCommands(self):
if addAlphaBand:
arguments.append('-dstalpha')

if len(extra) > 0:
if extra and len(extra) > 0:
arguments.append(extra)
if GdalUtils.getFormatShortNameFromFilename(out) == "GTiff":
arguments.append("-co COMPRESS=" + compress)
@@ -73,7 +73,9 @@ def defineCharacteristics(self):
def getConsoleCommands(self):
interval = unicode(self.getParameterValue(self.INTERVAL))
fieldName = unicode(self.getParameterValue(self.FIELD_NAME))
extra = unicode(self.getParameterValue(self.EXTRA))
extra = self.getParameterValue(self.EXTRA)
if extra is not None:
extra = unicode(extra)

arguments = []
if len(fieldName) > 0:
@@ -82,7 +84,7 @@ def getConsoleCommands(self):
arguments.append('-i')
arguments.append(interval)

if len(extra) > 0:
if extra and len(extra) > 0:
arguments.append(extra)

arguments.append(self.getParameterValue(self.INPUT_RASTER))
@@ -99,10 +99,14 @@ def defineCharacteristics(self):

def getConsoleCommands(self):
out = self.getOutputValue(self.OUTPUT)
extra = unicode(self.getParameterValue(self.EXTRA))
extra = self.getParameterValue(self.EXTRA)
if extra is not None:
extra = unicode(extra)
#debug = self.getParameterValue(self.DEBUG)
formula = self.getParameterValue(self.FORMULA)
noData = unicode(self.getParameterValue(self.NO_DATA))
noData = self.getParameterValue(self.NO_DATA)
if noData is not None:
noData = unicode(noData)

arguments = []
arguments.append('--calc')
@@ -111,10 +115,10 @@ def getConsoleCommands(self):
arguments.append(GdalUtils.getFormatShortNameFromFilename(out))
arguments.append('--type')
arguments.append(self.TYPE[self.getParameterValue(self.RTYPE)])
if len(noData) > 0:
if noData and len(noData) > 0:
arguments.append('--NoDataValue')
arguments.append(noData)
if len(extra) > 0:
if extra and len(extra) > 0:
arguments.append(extra)
#if debug:
# arguments.append('--debug')
@@ -126,7 +126,9 @@ def defineCharacteristics(self):
def getConsoleCommands(self):
inLayer = self.getParameterValue(self.INPUT)
ogrLayer = ogrConnectionString(inLayer)[1:-1]
noData = unicode(self.getParameterValue(self.NO_DATA))
noData = self.getParameterValue(self.NO_DATA)
if noData is not None:
noData = unicode(noData)
jpegcompression = unicode(self.getParameterValue(self.JPEGCOMPRESSION))
predictor = unicode(self.getParameterValue(self.PREDICTOR))
zlevel = unicode(self.getParameterValue(self.ZLEVEL))
@@ -135,7 +137,9 @@ def getConsoleCommands(self):
bigtiff = self.BIGTIFFTYPE[self.getParameterValue(self.BIGTIFF)]
tfw = unicode(self.getParameterValue(self.TFW))
out = self.getOutputValue(self.OUTPUT)
extra = unicode(self.getParameterValue(self.EXTRA))
extra = self.getParameterValue(self.EXTRA)
if extra is not None:
extra = unicode(extra)
rastext = unicode(self.getParameterValue(self.RAST_EXT))

arguments = []
@@ -172,7 +176,7 @@ def getConsoleCommands(self):
arguments.append(unicode(self.getParameterValue(self.WIDTH)))
arguments.append(unicode(self.getParameterValue(self.HEIGHT)))

if len(noData) > 0:
if noData and len(noData) > 0:
arguments.append('-a_nodata')
arguments.append(noData)

@@ -190,7 +194,7 @@ def getConsoleCommands(self):
arguments.append("-co TFW=YES")
if len(bigtiff) > 0:
arguments.append("-co BIGTIFF=" + bigtiff)
if len(extra) > 0:
if extra and len(extra) > 0:
arguments.append(extra)
arguments.append('-l')

@@ -129,13 +129,17 @@ def getConsoleCommands(self):
out = self.getOutputValue(translate.OUTPUT)
outsize = unicode(self.getParameterValue(self.OUTSIZE))
outsizePerc = unicode(self.getParameterValue(self.OUTSIZE_PERC))
noData = unicode(self.getParameterValue(self.NO_DATA))
noData = self.getParameterValue(self.NO_DATA)
if noData is not None:
noData = unicode(noData)
expand = unicode(self.getParameterFromName(
self.EXPAND).options[self.getParameterValue(self.EXPAND)])
projwin = unicode(self.getParameterValue(self.PROJWIN))
crsId = self.getParameterValue(self.SRS)
sds = self.getParameterValue(self.SDS)
extra = unicode(self.getParameterValue(self.EXTRA))
extra = self.getParameterValue(self.EXTRA)
if extra is not None:
extra = unicode(extra)
jpegcompression = unicode(self.getParameterValue(self.JPEGCOMPRESSION))
predictor = unicode(self.getParameterValue(self.PREDICTOR))
zlevel = unicode(self.getParameterValue(self.ZLEVEL))
@@ -157,7 +161,7 @@ def getConsoleCommands(self):
arguments.append('-outsize')
arguments.append(outsize)
arguments.append(outsize)
if len(noData) > 0:
if noData and len(noData) > 0:
arguments.append('-a_nodata')
arguments.append(noData)
if expand != 'none':
@@ -180,7 +184,7 @@ def getConsoleCommands(self):
arguments.append(unicode(crsId))
if sds:
arguments.append('-sds')
if len(extra) > 0:
if extra and len(extra) > 0:
arguments.append(extra)
if GdalUtils.getFormatShortNameFromFilename(out) == "GTiff":
arguments.append("-co COMPRESS=" + compress)
@@ -118,7 +118,9 @@ def defineCharacteristics(self):
self.addOutput(OutputRaster(self.OUTPUT, self.tr('Reprojected')))

def getConsoleCommands(self):
noData = unicode(self.getParameterValue(self.NO_DATA))
noData = self.getParameterValue(self.NO_DATA)
if noData is not None:
noData = unicode(noData)
srccrs = self.getParameterValue(self.SOURCE_SRS)
dstcrs = self.getParameterValue(self.DEST_SRS)
jpegcompression = unicode(self.getParameterValue(self.JPEGCOMPRESSION))
@@ -139,7 +141,7 @@ def getConsoleCommands(self):
if len(dstcrs) > 0:
arguments.append('-t_srs')
arguments.append(dstcrs)
if len(noData) > 0:
if noData and len(noData) > 0:
arguments.append('-dstnodata')
arguments.append(noData)
arguments.append('-r')
@@ -152,7 +154,9 @@ def getConsoleCommands(self):
arguments.append('-tr')
arguments.append(unicode(self.getParameterValue(self.TR)))
arguments.append(unicode(self.getParameterValue(self.TR)))
extra = unicode(self.getParameterValue(self.EXTRA))
extra = self.getParameterValue(self.EXTRA)
if extra is not None:
extra = unicode(extra)
regionCoords = rastext.split(',')
try:
rastext = []
@@ -165,7 +169,7 @@ def getConsoleCommands(self):
rastext = []
if rastext:
arguments.extend(rastext)
if len(extra) > 0:
if extra and len(extra) > 0:
arguments.append(extra)
if GdalUtils.getFormatShortNameFromFilename(out) == "GTiff":
arguments.append("-co COMPRESS=" + compress)

0 comments on commit 2ba252b

Please sign in to comment.