Skip to content

Commit cb0b335

Browse files
gkimbellnyalldawson
authored andcommitted
[FEATURE][processing] Add custom OPTIONS to contour algorithm (#7834)
1 parent 318946a commit cb0b335

File tree

2 files changed

+24
-0
lines changed

2 files changed

+24
-0
lines changed

python/plugins/processing/algs/gdal/contour.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ class contour(GdalAlgorithm):
5555
IGNORE_NODATA = 'IGNORE_NODATA'
5656
NODATA = 'NODATA'
5757
OFFSET = 'OFFSET'
58+
OPTIONS = 'OPTIONS'
5859
OUTPUT = 'OUTPUT'
5960

6061
def __init__(self):
@@ -104,6 +105,13 @@ def initAlgorithm(self, config=None):
104105
nodata_param.setFlags(offset_param.flags() | QgsProcessingParameterDefinition.FlagAdvanced)
105106
self.addParameter(offset_param)
106107

108+
options_param = QgsProcessingParameterString(self.OPTIONS,
109+
self.tr('Additional creation options'),
110+
defaultValue='',
111+
optional=True)
112+
options_param.setFlags(options_param.flags() | QgsProcessingParameterDefinition.FlagAdvanced)
113+
self.addParameter(options_param)
114+
107115
self.addParameter(QgsProcessingParameterVectorDestination(
108116
self.OUTPUT, self.tr('Contours'), QgsProcessing.TypeVectorLine))
109117

@@ -163,6 +171,10 @@ def getConsoleCommands(self, parameters, context, feedback, executing=True):
163171
if offset:
164172
arguments.append('-off {}'.format(offset))
165173

174+
options = self.parameterAsString(parameters, self.OPTIONS, context)
175+
if options:
176+
arguments.append(options)
177+
166178
if outFormat:
167179
arguments.append('-f {}'.format(outFormat))
168180

python/plugins/processing/tests/GdalAlgorithmsTest.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -589,6 +589,18 @@ def testContour(self):
589589
'-b 1 -a elev -i 5.0 -snodata 0.0 -f "GPKG" ' +
590590
source + ' ' +
591591
'd:/temp/check.gpkg'])
592+
# fixed level contours
593+
self.assertEqual(
594+
alg.getConsoleCommands({'INPUT': source,
595+
'BAND': 1,
596+
'FIELD_NAME': 'elev',
597+
'INTERVAL': 0,
598+
'OPTIONS': '-fl 100 125 150 200',
599+
'OUTPUT': 'd:/temp/check.shp'}, context, feedback),
600+
['gdal_contour',
601+
'-b 1 -a elev -i 0.0 -fl 100 125 150 200 -f "ESRI Shapefile" ' +
602+
source + ' ' +
603+
'd:/temp/check.shp'])
592604

593605
def testGdal2Tiles(self):
594606
context = QgsProcessingContext()

0 commit comments

Comments
 (0)