Raster – Using Map Algebra in Grass GIS to Merge Two Rastras with NoData Value

grassmap-algebrarasterraster-calculator

I have a slope raster and a road raster. The black pixels in the road raster are NoData values and the pink pixels have a value of 1. They don't cover exactly the same area.
enter image description here

I want to create a new raster based on the slope raster, except for pixels where there is a road pixel. If there is a road pixel, I want to assign a value of zero to the slope raster.

I am not quite sure how the formula needs to look like.
I tried the following, put it didn't give me the expected results:

r.mapcalc "output = ((Slope+(Road*null())))"

Any ideas?

Best Answer

Use this r.mapcalc expression:

r.mapcalc "output = not(if(Road))*Slope"

because:

  • if(Road)is equal to 1 if Road not zero, 0 otherwise.
  • not(if(Road))is equal to 0 if Road not zero, 1 otherwise.
Related Question