Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
[processing] fix order of command line arguments in gdal_polygonize (fix
  • Loading branch information
alexbruy authored and nyalldawson committed Nov 16, 2021
1 parent 3d236b0 commit 854f6cb
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 22 deletions.
22 changes: 12 additions & 10 deletions python/plugins/processing/algs/gdal/polygonize.py
Expand Up @@ -95,29 +95,31 @@ def commandName(self):

def getConsoleCommands(self, parameters, context, feedback, executing=True):
arguments = []

if self.parameterAsBoolean(parameters, self.EIGHT_CONNECTEDNESS, context):
arguments.append('-8')

if self.EXTRA in parameters and parameters[self.EXTRA] not in (None, ''):
extra = self.parameterAsString(parameters, self.EXTRA, context)
arguments.append(extra)

inLayer = self.parameterAsRasterLayer(parameters, self.INPUT, context)
if inLayer is None:
raise QgsProcessingException(self.invalidRasterError(parameters, self.INPUT))

arguments.append(inLayer.source())

arguments.append('-b')
arguments.append(str(self.parameterAsInt(parameters, self.BAND, context)))

outFile = self.parameterAsOutputLayer(parameters, self.OUTPUT, context)
self.setOutputValue(self.OUTPUT, outFile)
output, outFormat = GdalUtils.ogrConnectionStringAndFormat(outFile, context)
arguments.append(output)

if self.parameterAsBoolean(parameters, self.EIGHT_CONNECTEDNESS, context):
arguments.append('-8')

arguments.append('-b')
arguments.append(str(self.parameterAsInt(parameters, self.BAND, context)))

if outFormat:
arguments.append('-f {}'.format(outFormat))

if self.EXTRA in parameters and parameters[self.EXTRA] not in (None, ''):
extra = self.parameterAsString(parameters, self.EXTRA, context)
arguments.append(extra)
arguments.append(output)

layerName = GdalUtils.ogrOutputLayerName(output)
if layerName:
Expand Down
19 changes: 7 additions & 12 deletions python/plugins/processing/tests/GdalAlgorithmsRasterTest.py
Expand Up @@ -2360,8 +2360,7 @@ def testGdalPolygonize(self):
'OUTPUT': outsource}, context, feedback),
['gdal_polygonize.py',
source + ' ' +
outsource + ' ' +
'-b 1 -f "ESRI Shapefile" check DN'
'-b 1 -f "ESRI Shapefile"' + ' ' + outsource + ' ' + 'check DN'
])

self.assertEqual(
Expand All @@ -2372,8 +2371,7 @@ def testGdalPolygonize(self):
'OUTPUT': outsource}, context, feedback),
['gdal_polygonize.py',
source + ' ' +
outsource + ' ' +
'-b 1 -f "ESRI Shapefile" check VAL'
'-b 1 -f "ESRI Shapefile"' + ' ' + outsource + ' ' + 'check VAL'
])

# 8 connectedness
Expand All @@ -2384,9 +2382,8 @@ def testGdalPolygonize(self):
'EIGHT_CONNECTEDNESS': True,
'OUTPUT': outsource}, context, feedback),
['gdal_polygonize.py',
source + ' ' +
outsource + ' ' +
'-8 -b 1 -f "ESRI Shapefile" check DN'
'-8' + ' ' + source + ' ' +
'-b 1 -f "ESRI Shapefile"' + ' ' + outsource + ' ' + 'check DN'
])

# custom output format
Expand All @@ -2399,8 +2396,7 @@ def testGdalPolygonize(self):
'OUTPUT': outsource}, context, feedback),
['gdal_polygonize.py',
source + ' ' +
outsource + ' ' +
'-b 1 -f "GPKG" check DN'
'-b 1 -f "GPKG"' + ' ' + outsource + ' ' + 'check DN'
])

# additional parameters
Expand All @@ -2411,9 +2407,8 @@ def testGdalPolygonize(self):
'EXTRA': '-nomask -q',
'OUTPUT': outsource}, context, feedback),
['gdal_polygonize.py',
source + ' ' +
outsource + ' ' +
'-b 1 -f "GPKG" -nomask -q check DN'
'-nomask -q' + ' ' + source + ' ' +
'-b 1 -f "GPKG"' + ' ' + outsource + ' ' + 'check DN'
])

def testGdalPansharpen(self):
Expand Down

0 comments on commit 854f6cb

Please sign in to comment.