mirror of
https://github.com/qgis/QGIS.git
synced 2025-02-27 00:33:48 -05:00
additional parameters for polygonize algorithm
This commit is contained in:
parent
1d12620579
commit
d66914aec6
@ -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)
|
||||
|
@ -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()
|
||||
|
Loading…
x
Reference in New Issue
Block a user