Skip to content
Permalink
Browse files
[processing] fix order of command line arguments in gdal_polygonize (fix
  • Loading branch information
alexbruy authored and github-actions committed Nov 15, 2021
1 parent 67a25d8 commit 983bdf24c8171c5406665a38ab6975ee9a36c489
Showing with 19 additions and 22 deletions.
  1. +12 −10 python/plugins/processing/algs/gdal/polygonize.py
  2. +7 −12 python/plugins/processing/tests/GdalAlgorithmsRasterTest.py
@@ -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:
@@ -2403,8 +2403,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(
@@ -2415,8 +2414,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
@@ -2427,9 +2425,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
@@ -2442,8 +2439,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
@@ -2454,9 +2450,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):

0 comments on commit 983bdf2

Please sign in to comment.