Bug report #19115
[processing] Optional band rise exception in Batch mode (QgsProcessingParameterRasterLayer)
Status: | Closed | ||
---|---|---|---|
Priority: | High | ||
Assignee: | Luigi Pirelli | ||
Category: | Processing/Core | ||
Affected QGIS version: | 3.1(master) | Regression?: | Yes |
Operating System: | Easy fix?: | Yes | |
Pull Request or Patch supplied: | No | Resolution: | |
Crashes QGIS or corrupts data: | No | Copied to github as #: | 26945 |
Description
As far I can see, most of commands that use optional QgsProcessingParameterBand fail running alg in batch mode due to control like this:
https://github.com/qgis/QGIS/blob/master/python/plugins/processing/algs/gdal/gdalcalc.py#L225
because the value for the band is ''.
I can fix gdalcalc, but probably it's a more general problem related with the m,eaning of default in optional QgsProcessingParameterBand
Associated revisions
[processing] Correct management of optional rasters in batch mode. Fixes #19115
History
#1 Updated by Luigi Pirelli over 6 years ago
- Assignee set to Nyall Dawson
Hi Nyall I assign to you, just because I suppose you can fix in a minute. It's not clear to me if giving a default return to None to QgsProcessingParameterBand can have side effects
#2 Updated by Luigi Pirelli over 6 years ago
- Subject changed from [processing] Optional band rise exception in Batch mode (QgsProcessingParameterBand) to [processing] Optional band rise exception in Batch mode (QgsProcessingParameterRasterLayer)
Ho to reproduce
1) get a generic raster in qgis
2) open processing alg: e.g. gdal raster calculator
3) open "run as batch process"
4) add raster layer (step1) and layer A (mandatory) and leave empty any other layer (otpionals)
5) run =>
Traceback (most recent call last):
File "/mnt/data/PROGRAMMING/QGIS/QGIS-master/build/output/python/plugins/processing/algs/gdal/GdalAlgorithm.py", line 119, in processAlgorithm
commands = self.getConsoleCommands(parameters, context, feedback, executing=True)
File "/mnt/data/PROGRAMMING/QGIS/QGIS-master/build/output/python/plugins/processing/algs/gdal/gdalcalc.py", line 228, in getConsoleCommands
raise QgsProcessingException(self.invalidRasterError(parameters, self.INPUT_B))
_core.QgsProcessingException: Could not load source layer for INPUT_B: invalid value
but it is optional!
#3 Updated by Luigi Pirelli over 6 years ago
this is the run log
Processing algorithm 1/1…
Algorithm Raster calculator starting…
Input parameters:
{'BAND_A': 1,
'BAND_B': -1,
'BAND_C': -1,
'BAND_D': -1,
'BAND_E': -1,
'BAND_F': -1,
'EXTRA': '',
'FORMULA': 'A*2',
'INPUT_A': 'landcover',
'INPUT_B': '',
'INPUT_C': '',
'INPUT_D': '',
'INPUT_E': '',
'INPUT_F': '',
'NO_DATA': None,
'OPTIONS': '',
'OUTPUT': <QgsProcessingOutputLayerDefinition {'sink':/tmp/pippo.tif, 'createOptions': {}}>,
'RTYPE': 5}
Traceback (most recent call last):
File "/mnt/data/PROGRAMMING/QGIS/QGIS-master/build/output/python/plugins/processing/algs/gdal/GdalAlgorithm.py", line 119, in processAlgorithm
commands = self.getConsoleCommands(parameters, context, feedback, executing=True)
File "/mnt/data/PROGRAMMING/QGIS/QGIS-master/build/output/python/plugins/processing/algs/gdal/gdalcalc.py", line 228, in getConsoleCommands
raise QgsProcessingException(self.invalidRasterError(parameters, self.INPUT_B))
_core.QgsProcessingException: Could not load source layer for INPUT_B: invalid value
#4 Updated by Luigi Pirelli over 6 years ago
parameters if NOT run as batch are
Processing algorithm…
Algorithm 'Raster calculator' starting…
Input parameters:
{ 'BAND_B' : -1, 'BAND_C' : -1, 'INPUT_A' : '/home/ginetto/PROGRAMMING/GIS/GISDATA/qgis_sample_data/raster/landcover.img', 'INPUT_B' : None, 'EXTRA' : '', 'BAND_D' : -1, 'OUTPUT' : '/tmp/processing_15f1ccd70fc94dcc8af15be11fbb2182/85718598606f4759946e1883d6879506/OUTPUT.tif', 'FORMULA' : 'A*2', 'NO_DATA' : None, 'RTYPE' : 5, 'INPUT_F' : None, 'INPUT_D' : None, 'OPTIONS' : '', 'INPUT_E' : None, 'BAND_E' : -1, 'INPUT_C' : None, 'BAND_F' : -1, 'BAND_A' : 1 }
GDAL command:
gdal_calc --calc "A*2" --format GTiff --type Float32 -A /home/ginetto/PROGRAMMING/GIS/GISDATA/qgis_sample_data/raster/landcover.img --A_band 1 --outfile /tmp/processing_15f1ccd70fc94dcc8af15be11fbb2182/85718598606f4759946e1883d6879506/OUTPUT.tif
so it's clear that the way to build param disctionary works in different way depending if it is in batch or not
#5 Updated by Luigi Pirelli over 6 years ago
- Assignee changed from Nyall Dawson to Luigi Pirelli
#6 Updated by Luigi Pirelli over 6 years ago
- % Done changed from 0 to 100
- Status changed from Open to Closed
Applied in changeset qgis|fa7879ade16515784be51ab6d2170604eb5ea5f5.