When multiple input maps are given to r.univar, the overall statistics are calculated. This is useful for a time series of the same variable, as well as for the case of a segmented/tiled dataset. Allowing multiple raster maps to be specified saves the user from using a temporary raster map for the result of r.series or r.patch.
This module can use large amounts of system memory when the -e extended statistics flag is used with a very large region setting. If the region is too large the module should exit gracefully with a memory allocation error. Basic statistics can be calculated using any size input region.
Without a zones input raster, the r.quantile module will be significantly more efficient for calculating percentiles with large maps.
#### set the raster region to match the map
g.region vect=fields res=10 -ap
#### create rasterized version of vector map
v.to.rast in=fields out=fields.10m use=cat type=area labelcolumn=label
r.colors fields.10m color=random
#### perform analysis
r.univar -t map=elevation.10m zones=fields.10m | \
cut -f1,5,6,8 -d'|' > fields_stats.txt
#### populate vector DB with stats
# create working copy of vector map
g.copy vect=fields,fields_stats
# create new attribute columns to hold output
v.db.addcol map=fields_stats \
columns='mean_elev DOUBLE PRECISION, min_elev DOUBLE PRECISION, max_elev DOUBLE PRECISION'
# create SQL command file, and execute it
sed -e '1d' fields_stats.txt | awk -F'|' \
'{print "UPDATE fields_stats SET min_elev = "$2", max_elev = "$3", \
mean_elev = "$4" WHERE cat = "$1";"}' \
> fields_stats_sqlcmd.txt
db.execute input=fields_stats_sqlcmd.txt
#### view completed table
v.db.select fields_stats
Last changed: $Date: 2012-08-14 02:11:23 -0700 (Tue, 14 Aug 2012) $