Skip to content
Permalink
Browse files
[Processing][GDAL] Well manage optional parameters
Because EXTRA and NO_DATA parameters are optional, the value can be `None` which is the same as `''`.

(cherry picked from commit 793b712)

Conflicts:
	python/plugins/processing/algs/gdal/rasterize.py
	python/plugins/processing/algs/gdal/warp.py
  • Loading branch information
rldhont authored and alexbruy committed Apr 26, 2016
1 parent cf0e367 commit 4bf3c50a374fec781bfa631134fb03cb4473e869
@@ -98,9 +98,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))
@@ -114,7 +118,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)

@@ -125,7 +129,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)
@@ -116,11 +116,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))
@@ -135,7 +139,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)

@@ -160,7 +164,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)
@@ -64,7 +64,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:
@@ -73,7 +75,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))
@@ -103,10 +103,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')
@@ -115,10 +119,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')
@@ -116,7 +116,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))
@@ -125,7 +127,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)

arguments = []
arguments.append('-a')
@@ -147,7 +151,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)

@@ -165,7 +169,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')

@@ -120,13 +120,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))
@@ -148,7 +152,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':
@@ -171,7 +175,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)
@@ -106,7 +106,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))
@@ -126,7 +128,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')
@@ -139,8 +141,10 @@ 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))
if len(extra) > 0:
extra = self.getParameterValue(self.EXTRA)
if extra is not None:
extra = unicode(extra)
if extra and len(extra) > 0:
arguments.append(extra)
if GdalUtils.getFormatShortNameFromFilename(out) == "GTiff":
arguments.append("-co COMPRESS=" + compress)

0 comments on commit 4bf3c50

Please sign in to comment.