Raster Analytics


This page introduces some basic raster tools.  The art of spatial analyses involves sequencing simple operations such as these to get answers to complex questions.

r.buffer creates one or more buffer zones of specified widths around all clumps of non-zero cells in a raster layer. For example,
> r.buffer input=streams output=streambuf
  distances=100,200,300
creates the map at the left.  Its categories can be extracted with r.cats:
> r.cats streambuf
1   distances calculated from these locations
2   100 meters
3   200 meters
4   300 meters


r.clump finds areas of top-, bottom- and side-contiguous cells with the same value and assigns each a unique "clump" ID or category value. Diagonal neighbors are assigned to separate clumps. Generally use this on a binary or reclass map. This is useful for doing analyses of individual clumps rather than entire categories in a raster map.

In this example, I extracted the igneous cells from the Spearfish geology map (upper panel), then clumped these so that each clump has its own pixel value (lower panel):
> r.mapcalc ig='if(geology==3)'
> r.clump i=ig o=ig.clump

r.grow expands the edges of non-zero clumps in an input map by one pixel into zero- or missing-value cellsl. You can use this module to delineate 1-pixel boundaries of raster features. Try extracting igneous areas as a binary raster layer from geology, then growing it, then subtracting the original layer from the grown layer to obtain raster boundary features (1's) on a background of 0's (yellow) and missing data.:
> r.grow i=ig o=ig.grow
> r.mapcalc ig.bndy='ig.grow-ig'



r.neighbors calculates the average, median, mode, minimum, maximum, standard deviation, variance, diversity or interspersion of cell values in an N x N neighborhood (N = odd number between 1 and 25), and assigns the result to the center cell.  This module is useful for smoothing images or DEM's, or extracting vegetative texture from a vegetation index map.  For example, we might extract the infrared (shown as red) and red (shown as green) components from a SPOT satellite scene with the commands
> r.mapcalc red=r#spot.image
> r.mapcalc green=g#spot.image
then calculate a Normalized Difference Vegetation Index (below, left, displayed with a "ramp" color table) ...
> r.mapcalc ndvi='100*(red-green)/(red+green)'
and then calculate a vegetation texture (below, right, displayed with a grayscale equalized color table)...
> r.neighbors input=ndvi output=veg_tex size=5 method=stddev

Then we might use r.average to calculate the mean texture for each category in the vegcover map...
> r.average base=vegcover cover=veg_tex output=avg_tex
then convert this to an integer map...
> r.mapcalc veg_tex='int(veg_tex)'
and then use r.stats to extract the mean texture values for each category in vegcover:...
> r.stats -l vegcover,avg_tex
1 irrigated agriculture 14
2 rangeland 14
3 coniferous forest 30
4 deciduous forest 18
5 mixed forest 22
6 disturbed 13

In this SPOT scene, the infra-red and red reflectances are actually positively correlated, as determined from r.covar:
> r.covar -r red,green
1.000000 0.557173
0.557173 1.000000
r.coin is particularly useful for continuous-value maps, where a coincidence table of discrete values (generated with r.coin) isn't feasible


r.contour extracts a vector contour map from a raster map.  It is typically used on digital elevation models, which are themselves typically interpolated from vector hypsography (elevation contour) data.  So the original hypsography will be a lot more accurate than the map r.contour generates.


r.thin thins raster line features that are more than one cell wide to a single cell width.  This is typically required when converting raster line features to vector lines with the r.line module.

r.patch creates a composite map from two or more maps.  It is most commonly used to tile adjacent maps into a single map.  Where r.patch combines multiple maps such as
> r.patch input=A,B,C output=D
output map D will have all non-zero values of A, non-zero values of B where A is zero, and non-zero values of C where A and B are zero.
 

Some specialized utilities:

r.slope.aspect creates slope and aspect maps from DEM's.

r.surf.contour interpolates between sparse non-zero raster cells. It is mostly used for creating DEM's from rasterized hypsography (elevation contour line) layers.

r.surf.idw does inverse-distance-weighted surface interpolation.

r.watershed defines watershed boundaries, calculates surface flow volumes, etc. from an input DEM.



course syllabus