I am using the Raster calculator in a model builder workflow (QGIS 3.16), but get a very unspecific error when using algorithm outputs
as input for the raster calculator:
An error occurred while performing the calculation
Error encountered while running Raster calculator
Execution failed after 0.96 seconds
Using the raster calculator with model inputs
works fine. However whenever I use one of the (listed) algorithm outputs
(e.g. the result of a rasterization operation or the previous result of a raster calculation), the model fails to execute, without giving further reason (it says to check the log messages, but they are exactly the same as above mentioned error).
Below are images of model and error.
I've tried/checked:
- a reference raster needs to be given (I tried model inputs as well as algorithm outputs)
- I tested real calculations as well the most simple one (identity, just adding the plain layer)
- I tried renaming the algorithms (I thought maybe the names are to long or special characters are a problem)
None of that worked.
Is this a known issue?
Are there known workarounds?
The final formula I want to use would be the following.
Is this feasible with other operators (not the raster calculator)?
min(100,
("algorithm_output3" +
(100 * (
("algorithm_output1@1" < 25) AND ("algorithm_output2@1">= 30)
)
)
)
) * ("algorithm_output2@1">= 30)
Best Answer
I managed to work around the QGIS raster calculator by using
gdal_calc
. It is not as intuitive to work with, but once you get the hang of the syntax, it works just as fine (or even better, since it does not suffer from the bug of not being able to process previous algorithm outputs).The doc provides some examples for the calculation syntax (using numpy.functions). The actual formula for my case I ended up using was:
minimum((C + (100 * logical_and(B < 25, A >= 30))) * (A >= 30), 100)