qgis / QGIS

QGIS is a free, open source, cross platform (lin/win/mac) geographical information system (GIS)
https://qgis.org
GNU General Public License v2.0
10.53k stars 2.99k forks source link

[processing] Optional band rise exception in Batch mode (QgsProcessingParameterRasterLayer) #26945

Closed qgib closed 6 years ago

qgib commented 6 years ago

Author Name: Luigi Pirelli (@luipir) Original Redmine Issue: 19115 Affected QGIS version: 3.1(master) Redmine category:processing/core Assignee: Luigi Pirelli


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

qgib commented 6 years ago

Author Name: Luigi Pirelli (@luipir)


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


qgib commented 6 years ago

Author Name: Luigi Pirelli (@luipir)


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!


qgib commented 6 years ago

Author Name: Luigi Pirelli (@luipir)


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

qgib commented 6 years ago

Author Name: Luigi Pirelli (@luipir)


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

qgib commented 6 years ago

Author Name: Luigi Pirelli (@luipir)


qgib commented 6 years ago

Author Name: Luigi Pirelli (@luipir)


Applied in changeset fa7879ade16515784be51ab6d2170604eb5ea5f5.