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?


Use this r.mapcalc expression:

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


  • 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.
  • Though the part of the Slope Raster not covered by the Road Raster gets cut off. Is there a way to keep that part?
    – ustroetz
    Oct 30 '13 at 22:24
  • 2
    You could use r.patch before in order to make the Road raster cover the lower part of the Slope raster. Oct 30 '13 at 22:31
  • 1
    more simply, g.region rast=slope.
    – gene
    Oct 31 '13 at 16:17
  • 2
    Note that for GRASS 7, the command should be r.mapcalc "output = not(if(Road))*Slope" (both spaces and quotes are needed).
    – wenzeslaus
    Feb 20 '14 at 23:23
  • @wenzeslaus Thanks for the suggestion, I've updated the answer. Feb 21 '14 at 18:43

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.