GRASS logo

Note: A new GRASS GIS stable version has been released: GRASS GIS 7. Go directly to the new manual page here


r.average - Finds the average of values in a cover map within areas assigned the same category value in a user-specified base map.


raster, statistics


r.average help
r.average [-c] base=name cover=name output=name [--overwrite] [--verbose] [--quiet]


Cover values extracted from the category labels of the cover map
Allow output files to overwrite existing files
Verbose module output
Quiet module output


Name of base raster map
Name of cover raster map
Name for output raster map


r.average calculates the average value of data contained in a cover raster map layer for areas assigned the same category value in the user-specified base raster map layer. These averaged values are stored in the category labels file associated with a new output map layer. The values to be averaged are taken from a user-specified cover map. The category values for the cover map will be averaged, unless the -c flag is set. If the -c flag is set, the values that appear in the category labels file for the cover map will be averaged instead (see example below).

The output map is actually a reclass of the base map (see r.reclass), and will have exactly the same category values as the base map. The averaged values computed by r.average are stored in the output map's category labels file. The base= map is an existing raster map layer in the user's current mapset search path. For each group of cells assigned the same category value in the base map, the values assigned these cells in the cover map will be averaged. The cover map is an existing raster map layer containing the values (in the form of cell category values or cell category labels) to be averaged within each category of the base map.


The -c option requires that the category label for each category in the cover map be a valid number, integer, or decimal. To be exact, if the first item in the label is numeric, then that value is used. Otherwise, zero is used. The following table covers all possible cases:

         category    value 
         label       used by -c 
          .12	        .12 
          .80 KF        .8 
          no data       0 

(This flag is very similar to the @ operator in r.mapcalc, and the user is encouraged to read the manual entry for r.mapcalc to see how it works there.)

The user should use the results of r.average with care. Since this utility assigns a value to each cell which is based on global information (i.e., information at spatial locations other than just the location of the cell itself), the resultant map layer is only valid if the geographic region and mask settings are the same as they were at the time that the result map was created.

Results are affected by the current region settings and mask.


Assume that farms is a map with 7 farms (i.e., 7 categories), and that soils.Kfactor is a map of soil K factor values with the following category file:
	cat 	cat 
	value 	label 
	0 	no soil data 
	1 	.10 
	2 	.15 
	3 	.17 
	4 	.20 
	5 	.24 
	6 	.28 
	7 	.32 
	8 	.37 
	9 	.43 

r.average -c base=farms cover=soils.Kfactor
will compute the average soil K factor for each farm, and store the result in the output map, which will be a reclass of farms with category labels as follows (example only):
	cat	cat 
	value	label 
	1	.1023 
	2	.1532 
	3	.172 
	4	.3872 
	5	.003 
	6	.28 
	7	.2345 


g.region, r.category, r.clump, r.describe, r.mapcalc, r.mfilter, r.mode, r.neighbors, r.reclass, r.statistics, r.stats


Michael Shapiro, U.S. Army Construction Engineering Research Laboratory

Last changed: $Date: 2008-05-16 12:09:06 -0700 (Fri, 16 May 2008) $

Main index - raster index - Full index

© 2003-2016 GRASS Development Team