Skip to content

Commit

Permalink
[FEATURE][processing] Add custom OPTIONS to contour algorithm (#7834)
Browse files Browse the repository at this point in the history
  • Loading branch information
gkimbell authored and nyalldawson committed Sep 11, 2018
1 parent 318946a commit cb0b335
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
12 changes: 12 additions & 0 deletions python/plugins/processing/algs/gdal/contour.py
Expand Up @@ -55,6 +55,7 @@ class contour(GdalAlgorithm):
IGNORE_NODATA = 'IGNORE_NODATA'
NODATA = 'NODATA'
OFFSET = 'OFFSET'
OPTIONS = 'OPTIONS'
OUTPUT = 'OUTPUT'

def __init__(self):
Expand Down Expand Up @@ -104,6 +105,13 @@ def initAlgorithm(self, config=None):
nodata_param.setFlags(offset_param.flags() | QgsProcessingParameterDefinition.FlagAdvanced)
self.addParameter(offset_param)

options_param = QgsProcessingParameterString(self.OPTIONS,
self.tr('Additional creation options'),
defaultValue='',
optional=True)
options_param.setFlags(options_param.flags() | QgsProcessingParameterDefinition.FlagAdvanced)
self.addParameter(options_param)

self.addParameter(QgsProcessingParameterVectorDestination(
self.OUTPUT, self.tr('Contours'), QgsProcessing.TypeVectorLine))

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

options = self.parameterAsString(parameters, self.OPTIONS, context)
if options:
arguments.append(options)

if outFormat:
arguments.append('-f {}'.format(outFormat))

Expand Down
12 changes: 12 additions & 0 deletions python/plugins/processing/tests/GdalAlgorithmsTest.py
Expand Up @@ -589,6 +589,18 @@ def testContour(self):
'-b 1 -a elev -i 5.0 -snodata 0.0 -f "GPKG" ' +
source + ' ' +
'd:/temp/check.gpkg'])
# fixed level contours
self.assertEqual(
alg.getConsoleCommands({'INPUT': source,
'BAND': 1,
'FIELD_NAME': 'elev',
'INTERVAL': 0,
'OPTIONS': '-fl 100 125 150 200',
'OUTPUT': 'd:/temp/check.shp'}, context, feedback),
['gdal_contour',
'-b 1 -a elev -i 0.0 -fl 100 125 150 200 -f "ESRI Shapefile" ' +
source + ' ' +
'd:/temp/check.shp'])

def testGdal2Tiles(self):
context = QgsProcessingContext()
Expand Down

0 comments on commit cb0b335

Please sign in to comment.