additional parameters for polygonize algorithm

This commit is contained in:
Alexander Bruy 2019-06-24 19:30:00 +03:00
parent 1d12620579
commit d66914aec6
2 changed files with 26 additions and 0 deletions

View File

@ -27,6 +27,7 @@ from qgis.PyQt.QtGui import QIcon
from qgis.core import (QgsProcessing,
QgsProcessingException,
QgsProcessingParameterDefinition,
QgsProcessingParameterRasterLayer,
QgsProcessingParameterBand,
QgsProcessingParameterString,
@ -45,6 +46,7 @@ class polygonize(GdalAlgorithm):
BAND = 'BAND'
FIELD = 'FIELD'
EIGHT_CONNECTEDNESS = 'EIGHT_CONNECTEDNESS'
EXTRA = 'EXTRA'
OUTPUT = 'OUTPUT'
def __init__(self):
@ -63,6 +65,13 @@ class polygonize(GdalAlgorithm):
self.tr('Use 8-connectedness'),
defaultValue=False))
extra_param = QgsProcessingParameterString(self.EXTRA,
self.tr('Additional command-line parameters'),
defaultValue=None,
optional=True)
extra_param.setFlags(extra_param.flags() | QgsProcessingParameterDefinition.FlagAdvanced)
self.addParameter(extra_param)
self.addParameter(QgsProcessingParameterVectorDestination(self.OUTPUT,
self.tr('Vectorized'),
QgsProcessing.TypeVectorPolygon))
@ -107,6 +116,10 @@ class polygonize(GdalAlgorithm):
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)
layerName = GdalUtils.ogrOutputLayerName(output)
if layerName:
arguments.append(layerName)

View File

@ -3219,6 +3219,19 @@ class TestGdalAlgorithms(unittest.TestCase, AlgorithmsTestBase.AlgorithmsTest):
'-b 1 -f "GPKG" check DN'
])
# additional parameters
self.assertEqual(
alg.getConsoleCommands({'INPUT': source,
'BAND': 1,
'FIELD': 'DN',
'EXTRA': '-nomask -q',
'OUTPUT': outsource}, context, feedback),
['gdal_polygonize.py',
source + ' ' +
outsource + ' ' +
'-b 1 -f "GPKG" -nomask -q check DN'
])
def testGdalPansharpen(self):
context = QgsProcessingContext()
feedback = QgsProcessingFeedback()