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.


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.


So far as I know, the default raster calculator in QGIS does not support conditional statements. You'll need to download a plugin called RasterCalc. This (and other options) are discussed at Open source, Python option for Arcpy's Con tool? Note that syntax may not be directly compatible between the softwares, so you may need to make some adjustments rather than cut/pasting directly - Con is a specific tool in ArcGIS.


In the new version of Qgis, this options is in the raster calculator

  • 2
    Your answer could be improved with additional supporting information. Please edit to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers in the help center.
    – Community Bot
    Nov 1 at 1:00

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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