Rasters
Raster algebra
Raster algebra (or raster map algebra) is probably the
most general way of manipulating rasters which is accessible to the user.
if statement
Let's determine forested areas which are higher then certain elevation.
Set computational region (both extent and resolution) to the landclass raster:
g.region rast=landclass96
r.report map=landclass96 units=p
r.univar map=elevation
r.mapcalc "forest_high = if(elevation > 120 && landclass96 == 5, 1, null())"
Advanced raster algebra
eval function
If the output of the computation should be only one map
but the expression is so complex that it is better
to split it to several expressions, the eval function can be used:
r.mapcalc "eval(elev_200 = elevation - 200, elev_5 = 5 * elevation, elev_p = pow(elev_5, 2)); elevation_result = (0.5 * elev_200) + 0.8 * elev_p"
neighborhood operator [ , ]
Apply low pass filter (smoothing) on a Landsat image using r.mapcalc:
r.mapcalc "lsat7_2002_10_smooth = (lsat7_2002_10[-1,-1] + lsat7_2002_10[-1,0] + lsat7_2002_10[1,1] + lsat7_2002_10[0,-1] + lsat7_2002_10[0,0] + lsat7_2002_10[0,1] + lsat7_2002_10[1,-1] + lsat7_2002_10[1,0] + lsat7_2002_10[1,1]) / 9"
r.colors map=lsat7_2002_10_smooth raster=lsat7_2002_10
g.gui.mapswipe first=lsat7_2002_10 second=lsat7_2002_10_smooth
Learn more