Skip to content

Commit 0e7c31e

Browse files
committed
[processing][grass] Fix handling of optional file parameters
1 parent e273ac2 commit 0e7c31e

File tree

3 files changed

+46
-45
lines changed

3 files changed

+46
-45
lines changed

python/plugins/processing/algs/grass7/Grass7Algorithm.py

+12-11
Original file line numberDiff line numberDiff line change
@@ -612,17 +612,18 @@ def processCommand(self, parameters, context, feedback, delOutputs=False):
612612
outName = out.name()
613613
# For File destination
614614
if isinstance(out, QgsProcessingParameterFileDestination):
615-
# for HTML reports, we need to redirect stdout
616-
if out.defaultFileExtension().lower() == 'html':
617-
command += ' > "{}"'.format(
618-
self.parameterAsFileOutput(
619-
parameters, outName, context)
620-
)
621-
else:
622-
command += ' {}="{}"'.format(
623-
outName,
624-
self.parameterAsFileOutput(
625-
parameters, outName, context))
615+
if outName in parameters and parameters[outName] is not None:
616+
# for HTML reports, we need to redirect stdout
617+
if out.defaultFileExtension().lower() == 'html':
618+
command += ' > "{}"'.format(
619+
self.parameterAsFileOutput(
620+
parameters, outName, context)
621+
)
622+
else:
623+
command += ' {}="{}"'.format(
624+
outName,
625+
self.parameterAsFileOutput(
626+
parameters, outName, context))
626627
# For folders destination
627628
elif isinstance(out, QgsProcessingParameterFolderDestination):
628629
# We need to add a unique temporary basename

python/plugins/processing/algs/grass7/description/i.cluster.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,4 @@ QgsProcessingParameterNumber|convergence|Percent convergence|QgsProcessingParame
1010
QgsProcessingParameterNumber|separation|Cluster separation|QgsProcessingParameterNumber.Double|0.0|True|0.0|None
1111
QgsProcessingParameterNumber|min_size|Minimum number of pixels in a class|QgsProcessingParameterNumber.Integer|17|True|1|None
1212
QgsProcessingParameterFileDestination|signaturefile|Signature File|Txt files (*.txt)|None|False
13-
QgsProcessingParameterFileDestination|reportfile|Final Report File|Txt files (*.txt)|None|False
13+
QgsProcessingParameterFileDestination|reportfile|Final Report File|Txt files (*.txt)|None|True

python/plugins/processing/tests/testdata/grass7_algorithms_imagery_tests.yaml

+33-33
Original file line numberDiff line numberDiff line change
@@ -258,39 +258,39 @@ tests:
258258
hash: e1a433546cc1fdf7061adc0d9b77676c9d66ee8e0773d471bdb39a37
259259
type: rasterhash
260260

261-
# - algorithm: grass7:i.cluster
262-
# name: GRASS7 i.cluster
263-
# params:
264-
# GRASS_REGION_PARAMETER: '344500.0,358400.0,6682800.0,6693700.0'
265-
# classes: 5
266-
# convergence: 98
267-
# input:
268-
# params:
269-
# - name: custom/grass7/raster_6class.tif
270-
# type: raster
271-
# - name: custom/grass7/raster_5class.tif
272-
# type: raster
273-
# - name: custom/grass7/raster_4class.tif
274-
# type: raster
275-
# type: multi
276-
# iterations: 30
277-
# min_size: 17
278-
# separation: 0
279-
# results:
280-
# signaturefile:
281-
# type: regex
282-
# name: expected/grass7/i.cluster.sig.txt
283-
# rules:
284-
# - '#Class 1'
285-
# - '1.83333 1.53759 3.31579'
286-
# - '#Class 2'
287-
# - '2.11045 4.35498 3.32266'
288-
# - '#Class 3'
289-
# - '5.32655 1.72558 3.32713'
290-
# - '#Class 4'
291-
# - '4.34567 4.36522 3.30235'
292-
# - '#Class 5'
293-
# - '6 4.55734 3.30291'
261+
- algorithm: grass7:i.cluster
262+
name: GRASS7 i.cluster
263+
params:
264+
GRASS_REGION_PARAMETER: '344500.0,358400.0,6682800.0,6693700.0'
265+
classes: 5
266+
convergence: 98
267+
input:
268+
params:
269+
- name: custom/grass7/raster_6class.tif
270+
type: raster
271+
- name: custom/grass7/raster_5class.tif
272+
type: raster
273+
- name: custom/grass7/raster_4class.tif
274+
type: raster
275+
type: multi
276+
iterations: 30
277+
min_size: 17
278+
separation: 0
279+
results:
280+
signaturefile:
281+
type: regex
282+
name: expected/grass7/i.cluster.sig.txt
283+
rules:
284+
- '#Class 1'
285+
- '1.83333 1.53759 3.31579'
286+
- '#Class 2'
287+
- '2.11045 4.35498 3.32266'
288+
- '#Class 3'
289+
- '5.32655 1.72558 3.32713'
290+
- '#Class 4'
291+
- '4.34567 4.36522 3.30235'
292+
- '#Class 5'
293+
- '6 4.55734 3.30291'
294294

295295
- algorithm: grass7:i.oif
296296
name: GRASS7 i.oif

0 commit comments

Comments
 (0)