1

Is it possible to use the Abs() function in the raster calculator in QGIS?

I've tried it, but it didn't work.

3

Matematically, the absolute value of a number, |x|, is: x if x >=0 and -x if x < 0. For this reason, the implementation of abs() function in the raster calculator is:

("layer@1" >= 0)*("layer@1") + ("layer@1" < 0)*(-"layer@1")

To test this I used a NDVI raster whose values are between -1 and 1.

enter image description here

The result is confirmed in the next image (see Map Legend and the window of Value Tool Plugin).

enter image description here

2

There isn't an absolute function in the built-in Raster Calculator in QGIS. However there is an abs() function in the SAGA plugin. You can find it on the following path:

SAGA -> Grid - Calculus -> Raster calculator

You have to select the input layers. "They can be refered in the formula using letters (a, b, c...). The order for this naming is the same order as they appear in the selection window" (SAGA Raster calculator help).

SAGA Raster calculator abs() function proper syntax with one layer:

SAGA Raster calculator

You can also write a Python script to calculate the absolute value of every raster with a negative value, but this method is easier.

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.