I'm using GRASS 7.4.1 in QGIS 3.2 and would like to change 0 values of a slope raster to 1. I've been following this video tutorial and my r.mapcalc function looks exactly the same. However the output adds 1 to all values in the slope raster. The model looks like this in the GUI:

enter image description here

And the formula in the output reads "slope_1 = ((slope+((slope==0)+1)))"

How can I convert only 0 values to 1 instead of adding 1 to all values? In ArcGIS raster calculator I would use something like Con(raster==0,1,raster)

Stripping the GRASS r.mapcalc function back further the output from this created a raster with original 0 values converted to 2 and all other values converted to 1:

enter image description here


I am aware there are other methods I could use to achive the same results but part of the purpose of doing this is to learn how to use the r.mapcalc GUI and so I am only looking for answers that use r.mapcalc GUI. Specifically I'd like to know why the formula / model used isn't behaving as expected and if another formula / model would be better suited to the problem.

2 Answers 2


Do you have to use r.mapcalc? If not I would use Reclassify by Table. Set the range you want to reclass(0 to 0 and the new value 1). All the zeros should become one but the rest should stay the same. enter image description here

enter image description here

before reclass

after reclass


Thanks to Joe from the QGIS FB page. He pointed out that the original formula was using a logical test (slope == 0). The output from this would be a binary raster; value 1 where the original raster value was 0 and 0 where it was anything other than 0. This provides the required output to add to the original slope raster. It is unneccesary to include the addition of the constant. Using the output from the logical test works in this instance. So the final model looks like this:

enter image description here

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.