[Qgis-user] Raster calculation: if Layer1 is > 1, then Layer2 should be 0

Andrea Giudiceandrea andreaerdna at libero.it
Thu Feb 17 13:21:55 PST 2022


> *Bernd Vogelgesang*bernd.vogelgesang at gmx.de 
> <mailto:qgis-user%40lists.osgeo.org?Subject=Re%3A%20%5BQgis-user%5D%20Raster%20calculation%3A%20if%20Layer1%20is%20%3E%201%2C%0A%20then%20Layer2%20should%20be%200&In-Reply-To=%3C962b4ae7-f8cd-5c70-e4d5-fec2f81891f1%40gmx.de%3E>
> /Thu Feb 17 12:19:12 PST 2022/
> I hardly never work with raster calculations, and unfortunately there is
> nowhere a collection of syntax examples for different use cases to be
> found (documentation :( ).
>
> Giving a threshold of 1 meters difference for inaccuracities, all pixels
> in this layer above 1 should result in 0 (zero) in my viewshed raster
> (Layer 2)

Hi Bernd,
what QGIS version are you using? What raster calculator are you using 
(there are 5 raster calculators, including also the ones provided by 
GDAL, SAGA and GRASS)?

Have you read the documentation for the main raster calculator of QGIS 
at 
https://docs.qgis.org/3.22/en/docs/user_manual/working_with_raster/raster_analysis.html#raster-analysis 
?
It seems to me it contains some examples, including:

<<...
If you want to mask out parts of a raster – say, for instance, because 
you are only interested in elevations above 0 meters – you can use the 
following expression to create a mask and apply the result to a raster 
in one step.

("elevation at 1" >= 0) * "elevation at 1"

In other words, for every cell greater than or equal to 0 the 
conditional expression evaluates to 1, which keeps the original value by 
multiplying it by 1. Otherwise the conditional expression evaluates to 
0, which sets the raster value to 0. This creates the mask on the fly.

..>>

Best regards.

Andrea Giudiceandrea
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/qgis-user/attachments/20220217/daec1d93/attachment.html>


More information about the Qgis-user mailing list