Is it possible to use the Abs() function in the raster calculator in QGIS?
I've tried it, but it didn't work.
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It only takes a minute to sign up.Sign up to join this community
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.
The result is confirmed in the next image (see Map Legend and the window of Value Tool Plugin).
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:
You can also write a Python script to calculate the absolute value of every raster with a negative value, but this method is easier.