I have a workflow in ArcGIS that I'm trying to convert to GRASS GIS. Part of this workflow involves using Raster Calculator to execute a conditional statement. If the conditional statement is true, a focal minimum calculation is performed on the cells for which the condition is met. If the condition is not met, cells are assigned the value from another raster. In general, my raster calculator expression looks like this:

Con("raster1" & "raster2", FocalStatistics("raster3", NbrCircle(15), "MINIMUM"), "raster3")

I'm aware that the GRASS GIS equivalent to ArcGIS Raster Calculator is r.mapcalc, and it appears that the equivalent to ArcGIS Focal Statistics is r.neighbors but what I'm not sure of is if you can execute the focal or neighborhood statistics from within the r.mapcalc expression, as I've done in ArcGIS Raster Calculator. Is this possible?


I don't think you can embed a GRASS module into an r.mapcalc expression. The way to accomplish with GRASS what you have shown in the ArcGIS raster calculator would require two steps, using a mask, as follows:

# As always, set the computational region
g.region -ap rast=rater3
# Determine the mask
# Note that the GRASS logical AND operator is &&
r.mapcalc "MASK = raster1 && raster2"
# Now your neighborhood calculation 
r.neighbors -c input=raster3 output=min_neighborhood size=15 method=minimum
# And remove the mask
r.mask -r

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.