7

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

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.

11

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.

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.