15

What is the equivalent statement of the following expression in the QGIS raster calculator?

    Con(((Abs("DEM" - "FSMin") > 120) | (Abs("DEM" - "FSMax") > 120)), 1, 0)

I have no problem running this command in ArcMap but as soon as I paste it in QGIS the raster calculator there rejects it.

PolyGeo
  • 65,136
  • 29
  • 109
  • 338
user32882
  • 3,514
  • 2
  • 31
  • 67

2 Answers2

35

You can create a condition by using a little 'trick':

Suppose you have a raster file (layer1) with values below 0 but you want only positive values.

("layer1@1" > 0 )

Is resulting in 1 when it is above 0 and is resulting in 0 when it is below 0.

("layer1@1" > 0 ) * "layer1@1"

When you multiply this with the raster value it will either be 0 or it will be 1 multiplied with the raster value.

Gert
  • 717
  • 8
  • 11
15

As of QGIS 3.22, the raster calculator supports if statements. Depending on the naming of the layers and raster band numbering, it would be something like

if((abs("DEM@1" - "FSMin@1") > 120) or (abs("DEM@1" - "FSMax@1") > 120), 1, 0)
Todd West
  • 179
  • 1
  • 8
carlonchoboy
  • 151
  • 1
  • 5