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.

2 Answers 2


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.


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)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.