Bug report #17843

Can't add QGIS raster calculator in the processing modeller

Added by Alister Hood over 6 years ago. Updated over 5 years ago.

Status:Closed
Priority:Normal
Assignee:Mathieu Pellerin - nIRV
Category:Processing/QGIS
Affected QGIS version:master Regression?:No
Operating System:Windows Easy fix?:No
Pull Request or Patch supplied:No Resolution:fixed/implemented
Crashes QGIS or corrupts data:No Copied to github as #:25738

Description

When I try to add the QGIS raster calculator in the processing modeller there is a "Python error".

BTW the reason I wanted to try to use it when there are other raster calculators available is that I was hoping it supported referring to model values the way the Modeler-only "Calculator" tool does i.e. a->VARIABLE_NAME. But it seems the Modeler-only tools have been removed in QGIS3!

fa2aff18e5

Associated revisions

Revision eb7a187a
Added by Alexander Bruy over 6 years ago

[processing] add missed imports (fix #17843)

History

#1 Updated by Alexander Bruy over 6 years ago

  • % Done changed from 0 to 100
  • Status changed from Open to Closed

#2 Updated by Alister Hood over 6 years ago

The dialog opens now, but there is an error if I try to use it:

An error has occurred while executing Python code: 

AttributeError: 'LayersListWidgetWrapper' object has no attribute '_getOptions' 
Traceback (most recent call last):
  File "C:/OSGEO4~1/apps/qgis-dev/./python/plugins\processing\modeler\ModelerParametersDialog.py", line 357, in okPressed
    alg = self.createAlgorithm()
  File "C:/OSGEO4~1/apps/qgis-dev/./python/plugins\processing\modeler\ModelerParametersDialog.py", line 308, in createAlgorithm
    val = self.wrappers[param.name()].value()
  File "C:/OSGEO4~1/apps/qgis-dev/./python/plugins\processing\algs\qgis\ui\RasterCalculatorWidgets.py", line 249, in value
    options = self._getOptions()
AttributeError: 'LayersListWidgetWrapper' object has no attribute '_getOptions'

Python version: 3.6.0 (v3.6.0:41df79263a11, Dec 23 2016, 08:06:12) [MSC v.1900 64 bit (AMD64)] 
QGIS version: 2.99.0-Master Master, 05c7132518 

Python Path:
C:/OSGEO4~1/apps/qgis-dev/./python/plugins\processing
C:/OSGEO4~1/apps/qgis-dev/./python
C:/Users/alistair/AppData/Roaming/QGIS/QGIS3\profiles\default/python
C:/Users/alistair/AppData/Roaming/QGIS/QGIS3\profiles\default/python/plugins
C:/OSGEO4~1/apps/qgis-dev/./python/plugins
C:\OSGeo4W64\bin\python36.zip
C:\OSGEO4~1\apps\Python36\DLLs
C:\OSGEO4~1\apps\Python36\lib
C:\OSGeo4W64\bin
C:\OSGEO4~1\apps\Python36
C:\OSGEO4~1\apps\Python36\lib\site-packages
C:/Users/alistair/AppData/Roaming/QGIS/QGIS3\profiles\default/python

Should I open another ticket?
05c7132518

#3 Updated by Alister Hood over 6 years ago

  • Status changed from Closed to Reopened

I am happy to file a new ticket, but I am reopening for now: as described in the previous comment, although the dialog now opens, it errors when you click 'OK', so you still can't actually add it to a model.

I have also noticed that it doesn't list all of the available raster layers. i.e. it lists all layers that are explicit model inputs, but if another algorithm which generates a raster layer is used more than once in the model, it only lists the output from one of those uses. This is unlike other algorithms, where all raster layers are available.

Note that fixing this second issue still leaves a wider problem with the model builder: if you have a model where the same algorithm is used more than once, there is no way to tell the difference between the outputs of each, for use in other algorithms in the model. You might expect to be able to work around this by naming the outputs (i.e. as "final results"), but the names of final results aren't added to the list of input layers.

#4 Updated by Alister Hood over 6 years ago

Note that if this is fixed #17430 can also be closed.

I have also noticed that it doesn't list all of the available raster layers...

I was wondering if this is related to the fact that when you try to use the output from another algorithm, it shows as this, which looks wrong:
"<qgis._core.QgsProcessingModelChildParameterSource object at 0x000001B39085B3A8>@1"

#5 Updated by Mathieu Pellerin - nIRV over 6 years ago

  • Status changed from Reopened to Closed
  • Resolution set to fixed/implemented
  • Assignee changed from Victor Olaya to Mathieu Pellerin - nIRV

Alister, I'm pretty sure the raster calculator now works well within a model. Let me know if it's not the case.

#6 Updated by Alister Hood about 6 years ago

  • Status changed from Closed to Reopened

I'm still getting this on Windows (latest osgeo4w64 nightly) when I try to add it to the model:

An error has occurred while executing Python code: 

AttributeError: type object 'QgsProcessing' has no attribute 'FlagOptional' 
Traceback (most recent call last):
  File "C:/OSGEO4~1/apps/qgis-dev/./python/plugins\processing\modeler\ModelerParametersDialog.py", line 359, in okPressed
    alg = self.createAlgorithm()
  File "C:/OSGEO4~1/apps/qgis-dev/./python/plugins\processing\modeler\ModelerParametersDialog.py", line 310, in createAlgorithm
    val = self.wrappers[param.name()].value()
  File "C:/OSGEO4~1/apps/qgis-dev/./python/plugins\processing\gui\wrappers.py", line 696, in value
    if len(values) == 0 and not self.param.flags() & QgsProcessing.FlagOptional:
AttributeError: type object 'QgsProcessing' has no attribute 'FlagOptional'

Python version: 3.6.0 (v3.6.0:41df79263a11, Dec 23 2016, 08:06:12) [MSC v.1900 64 bit (AMD64)] 
QGIS version: 2.99.0-Master Master, 2c53630747

#7 Updated by Alister Hood about 6 years ago

Alister Hood wrote:

I'm still getting this on Windows (latest osgeo4w64 nightly) when I try to add it to the model:

FWIW I can't test on linux as the only master build I have is in an ubuntu install on WSL, and the processing modeller does not work there (the panes on the left are rendered with all their widgets on top of each other)... I presume it does work on normal linux installs?

#8 Updated by Mathieu Pellerin - nIRV about 6 years ago

  • Status changed from Reopened to Closed

Alister, fixed the

'QgsProcessing' has no attribute 'FlagOptional'
error, thanks for the report.

#9 Updated by Alister Hood over 5 years ago

BTW the reason I wanted to try to use it when there are other raster calculators available is that I was hoping it supported referring to model values the way the Modeler-only "Calculator" tool does i.e. a->VARIABLE_NAME. But it seems the Modeler-only tools have been removed in QGIS3!

The simple workaround for what I wanted to achieve (FWIW I need it more often than not for my processing use cases) is to feed the value from user input to the "create constant raster algorithm", and use the output of that in the raster calculator. Creating a raster just for that seems rather inefficient though.

Also available in: Atom PDF