Skip to content
Permalink
Browse files

[processing][gdal] Fix parsing of creation options

Creation options must be specified one at a time - the
current approach causes them to be specified once embedded
in quotation marks, which is not valid input for gdal

(cherry-picked from 00bb177)
  • Loading branch information
nyalldawson committed Mar 22, 2018
1 parent 9dc4b04 commit 50c239b1d4231e5949576a907bd1ee09e53aeded
@@ -132,8 +132,7 @@ def getConsoleCommands(self, parameters, context, feedback, executing=True):
arguments.append(QgsRasterFileWriter.driverForExtension(os.path.splitext(out)[1]))

if options:
arguments.append('-co')
arguments.append(options)
arguments.extend(GdalUtils.parseCreationOptions(options))

arguments.append(inLayer.source())
arguments.append(out)
@@ -154,8 +154,7 @@ def getConsoleCommands(self, parameters, context, feedback, executing=True):
arguments.append('-dstnodata {}'.format(nodata))

if options:
arguments.append('-co')
arguments.append(options)
arguments.extend(GdalUtils.parseCreationOptions(options))

arguments.append(inLayer.source())
arguments.append(out)
@@ -389,3 +389,11 @@ def ogrLayerName(uri):
name = ly.GetName()
ds = None
return name

@staticmethod
def parseCreationOptions(value):
parts = value.split('|')
options = []
for p in parts:
options.extend(['-co', p])
return options
@@ -167,8 +167,7 @@ def getConsoleCommands(self, parameters, context, feedback, executing=True):

options = self.parameterAsString(parameters, self.OPTIONS, context)
if options:
arguments.append('-co')
arguments.append(options)
arguments.extend(GdalUtils.parseCreationOptions(options))

arguments.append(ogrLayer)
arguments.append(out)
@@ -181,8 +181,7 @@ def getConsoleCommands(self, parameters, context, feedback, executing=True):
options = self.parameterAsString(parameters, self.OPTIONS, context)

if options:
arguments.append('-co')
arguments.append(options)
arguments.extend(GdalUtils.parseCreationOptions(options))

arguments.append(ogrLayer)
arguments.append(out)
@@ -190,8 +190,7 @@ def getConsoleCommands(self, parameters, context, feedback, executing=True):

options = self.parameterAsString(parameters, self.OPTIONS, context)
if options:
arguments.append('-co')
arguments.append(options)
arguments.extend(GdalUtils.parseCreationOptions(options))

arguments.append(ogrLayer)
arguments.append(out)
@@ -175,8 +175,7 @@ def getConsoleCommands(self, parameters, context, feedback, executing=True):

options = self.parameterAsString(parameters, self.OPTIONS, context)
if options:
arguments.append('-co')
arguments.append(options)
arguments.extend(GdalUtils.parseCreationOptions(options))

arguments.append(ogrLayer)
arguments.append(out)
@@ -146,8 +146,7 @@ def getConsoleCommands(self, parameters, context, feedback, executing=True):

options = self.parameterAsString(parameters, self.OPTIONS, context)
if options:
arguments.append('-co')
arguments.append(options)
arguments.extend(GdalUtils.parseCreationOptions(options))

arguments.append(ogrLayer)
arguments.append(out)
@@ -161,8 +161,7 @@ def getConsoleCommands(self, parameters, context, feedback, executing=True):

options = self.parameterAsString(parameters, self.OPTIONS, context)
if options:
arguments.append('-co')
arguments.append(options)
arguments.extend(GdalUtils.parseCreationOptions(options))

arguments.append(ogrLayer)
arguments.append(out)
@@ -125,7 +125,6 @@ def getConsoleCommands(self, parameters, context, feedback, executing=True):

options = self.parameterAsString(parameters, self.OPTIONS, context)
if options:
arguments.append('-co')
arguments.append(options)
arguments.extend(GdalUtils.parseCreationOptions(options))

return ['gdaldem', GdalUtils.escapeAndJoin(arguments)]
@@ -160,7 +160,6 @@ def getConsoleCommands(self, parameters, context, feedback, executing=True):

options = self.parameterAsString(parameters, self.OPTIONS, context)
if options:
arguments.append('-co')
arguments.append(options)
arguments.extend(GdalUtils.parseCreationOptions(options))

return ['gdaldem', GdalUtils.escapeAndJoin(arguments)]
@@ -152,8 +152,7 @@ def getConsoleCommands(self, parameters, context, feedback, executing=True):

options = self.parameterAsString(parameters, self.OPTIONS, context)
if options:
arguments.append('-co')
arguments.append(options)
arguments.extend(GdalUtils.parseCreationOptions(options))

arguments.append('-o')
arguments.append(out)
@@ -112,7 +112,6 @@ def getConsoleCommands(self, parameters, context, feedback, executing=True):

options = self.parameterAsString(parameters, self.OPTIONS, context)
if options:
arguments.append('-co')
arguments.append(options)
arguments.extend(GdalUtils.parseCreationOptions(options))

return ['nearblack', GdalUtils.escapeAndJoin(arguments)]
@@ -170,8 +170,7 @@ def getConsoleCommands(self, parameters, context, feedback, executing=True):
arguments.append(QgsRasterFileWriter.driverForExtension(os.path.splitext(out)[1]))

if options:
arguments.append('-co')
arguments.append(options)
arguments.extend(GdalUtils.parseCreationOptions(options))

arguments.append(inLayer.source())
arguments.append(out)
@@ -214,8 +214,7 @@ def getConsoleCommands(self, parameters, context, feedback, executing=True):
options = self.parameterAsString(parameters, self.OPTIONS, context)

if options:
arguments.append('-co')
arguments.append(options)
arguments.extend(GdalUtils.parseCreationOptions(options))

arguments.append(ogrLayer)
arguments.append(out)
@@ -187,8 +187,7 @@ def getConsoleCommands(self, parameters, context, feedback, executing=True):

options = self.parameterAsString(parameters, self.OPTIONS, context)
if options:
arguments.append('-co')
arguments.append(options)
arguments.extend(GdalUtils.parseCreationOptions(options))

if self.parameterAsBool(parameters, self.DIR_FOR_ROW, context):
arguments.append('-pyramidOnly')
@@ -129,7 +129,6 @@ def getConsoleCommands(self, parameters, context, feedback, executing=True):

options = self.parameterAsString(parameters, self.OPTIONS, context)
if options:
arguments.append('-co')
arguments.append(options)
arguments.extend(GdalUtils.parseCreationOptions(options))

return ['gdaldem', GdalUtils.escapeAndJoin(arguments)]
@@ -99,7 +99,6 @@ def getConsoleCommands(self, parameters, context, feedback, executing=True):

options = self.parameterAsString(parameters, self.OPTIONS, context)
if options:
arguments.append('-co')
arguments.append(options)
arguments.extend(GdalUtils.parseCreationOptions(options))

return ['gdaldem', GdalUtils.escapeAndJoin(arguments)]
@@ -137,8 +137,7 @@ def getConsoleCommands(self, parameters, context, feedback, executing=True):

options = self.parameterAsString(parameters, self.OPTIONS, context)
if options:
arguments.append('-co')
arguments.append(options)
arguments.extend(GdalUtils.parseCreationOptions(options))

arguments.append(inLayer.source())
arguments.append(out)
@@ -98,7 +98,6 @@ def getConsoleCommands(self, parameters, context, feedback, executing=True):

options = self.parameterAsString(parameters, self.OPTIONS, context)
if options:
arguments.append('-co')
arguments.append(options)
arguments.extend(GdalUtils.parseCreationOptions(options))

return ['gdaldem', GdalUtils.escapeAndJoin(arguments)]
@@ -70,4 +70,4 @@ def value(self):
elif self.dialogType == DIALOG_BATCH:
return self.widget.text()
else:
return ' '.join(self.widget.options())
return '|'.join(self.widget.options())
@@ -212,8 +212,7 @@ def getConsoleCommands(self, parameters, context, feedback, executing=True):

options = self.parameterAsString(parameters, self.OPTIONS, context)
if options:
arguments.append('-co')
arguments.append(options)
arguments.extend(GdalUtils.parseCreationOptions(options))

arguments.append(inLayer.source())
arguments.append(out)

0 comments on commit 50c239b

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