mirror of
https://github.com/qgis/QGIS.git
synced 2025-04-15 00:04:00 -04:00
allow pass additional parameters in the contour algorithm
This commit is contained in:
parent
c64c2948d9
commit
18a56f97e0
@ -51,6 +51,7 @@ class contour(GdalAlgorithm):
|
||||
IGNORE_NODATA = 'IGNORE_NODATA'
|
||||
NODATA = 'NODATA'
|
||||
OFFSET = 'OFFSET'
|
||||
EXTRA = 'EXTRA'
|
||||
OPTIONS = 'OPTIONS'
|
||||
OUTPUT = 'OUTPUT'
|
||||
|
||||
@ -102,11 +103,19 @@ class contour(GdalAlgorithm):
|
||||
nodata_param.setFlags(offset_param.flags() | QgsProcessingParameterDefinition.FlagAdvanced)
|
||||
self.addParameter(offset_param)
|
||||
|
||||
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)
|
||||
|
||||
# TODO: remove in QGIS 4
|
||||
options_param = QgsProcessingParameterString(self.OPTIONS,
|
||||
self.tr('Additional creation options'),
|
||||
defaultValue='',
|
||||
optional=True)
|
||||
options_param.setFlags(options_param.flags() | QgsProcessingParameterDefinition.FlagAdvanced)
|
||||
options_param.setFlags(options_param.flags() | QgsProcessingParameterDefinition.FlagHidden)
|
||||
self.addParameter(options_param)
|
||||
|
||||
self.addParameter(QgsProcessingParameterVectorDestination(
|
||||
@ -169,13 +178,18 @@ class contour(GdalAlgorithm):
|
||||
if offset:
|
||||
arguments.append('-off {}'.format(offset))
|
||||
|
||||
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)
|
||||
|
||||
# TODO: remove in QGIS 4
|
||||
options = self.parameterAsString(parameters, self.OPTIONS, context)
|
||||
if options:
|
||||
arguments.append(options)
|
||||
|
||||
if outFormat:
|
||||
arguments.append('-f {}'.format(outFormat))
|
||||
|
||||
arguments.append(inLayer.source())
|
||||
arguments.append(output)
|
||||
|
||||
|
@ -717,16 +717,45 @@ class TestGdalAlgorithms(unittest.TestCase, AlgorithmsTestBase.AlgorithmsTest):
|
||||
'-b 1 -a elev -i 5.0 -snodata 0.0 -f "GPKG" ' +
|
||||
source + ' ' +
|
||||
outdir + '/check.gpkg'])
|
||||
# fixed level contours
|
||||
# with CREATE_3D
|
||||
self.assertEqual(
|
||||
alg.getConsoleCommands({'INPUT': source,
|
||||
'BAND': 1,
|
||||
'CREATE_3D': True,
|
||||
'OUTPUT': outdir + '/check.shp'}, context, feedback),
|
||||
['gdal_contour',
|
||||
'-b 1 -a ELEV -i 10.0 -3d -f "ESRI Shapefile" ' +
|
||||
source + ' ' +
|
||||
outdir + '/check.shp'])
|
||||
# with IGNORE_NODATA and OFFSET
|
||||
self.assertEqual(
|
||||
alg.getConsoleCommands({'INPUT': source,
|
||||
'BAND': 1,
|
||||
'IGNORE_NODATA': True,
|
||||
'OFFSET': 100,
|
||||
'OUTPUT': outdir + '/check.shp'}, context, feedback),
|
||||
['gdal_contour',
|
||||
'-b 1 -a ELEV -i 10.0 -inodata -off 100.0 -f "ESRI Shapefile" ' +
|
||||
source + ' ' +
|
||||
outdir + '/check.shp'])
|
||||
# with additional command line parameters
|
||||
self.assertEqual(
|
||||
alg.getConsoleCommands({'INPUT': source,
|
||||
'BAND': 1,
|
||||
'EXTRA': '-e 3 -amin MIN_H',
|
||||
'OUTPUT': outdir + '/check.shp'}, context, feedback),
|
||||
['gdal_contour',
|
||||
'-b 1 -a ELEV -i 10.0 -f "ESRI Shapefile" -e 3 -amin MIN_H ' +
|
||||
source + ' ' +
|
||||
outdir + '/check.shp'])
|
||||
# obsolete OPTIONS param
|
||||
self.assertEqual(
|
||||
alg.getConsoleCommands({'INPUT': source,
|
||||
'BAND': 1,
|
||||
'FIELD_NAME': 'elev',
|
||||
'INTERVAL': 0,
|
||||
'OPTIONS': '-fl 100 125 150 200',
|
||||
'OUTPUT': outdir + '/check.shp'}, context, feedback),
|
||||
['gdal_contour',
|
||||
'-b 1 -a elev -i 0.0 -fl 100 125 150 200 -f "ESRI Shapefile" ' +
|
||||
'-b 1 -a ELEV -i 10.0 -f "ESRI Shapefile" -fl 100 125 150 200 ' +
|
||||
source + ' ' +
|
||||
outdir + '/check.shp'])
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user