2 Raster map algebra

GRASS provides the very powerful map calculator r.mapcalc. This module is best used on the command line as there you have flexible cursor support provided by the shell. It operates cell by cell, using a moving window technology. To start with some simple operations, we filter all pixels with elevation higher than 1000m from the Spearfish DEM:

     r.mapcalc "elev_1500 = if(elevation.dem > 1500.0, $\backslash$

               elevation.dem, null())"

     d.rast elev_1500

The command, embedded in double quotes, contains an ``if'' statement (if higher than 1500m) with a ``then'' option (copy the pixel values) and an ``else'' option (write No Data if the condition is not satisfied). The null() function is a reserved word which inserts a No Data value for the actual raster cell being processed. There are a couple of further functions available such as mean(), min(), max(), sin(), cos() etc. The map calculator can accept more than one input map. New maps can be generated from calculations performed on a set of input maps. Additionally adjacent values can be considered, e.g. to generate flow through a landscape. Please refer to the manual page or the books indicated in the bibliography for further functions and examples.


© 2005, GDF Hannover bR - Solutions for spatial data analysis and remote sensing