Skip to content

r.statistics

Calculates category or object oriented statistics.

r.statistics [-c] base=name cover=name method=string output=name [--overwrite] [--verbose] [--quiet] [--qq] [--ui]

Example:

r.statistics base=name cover=name method=string output=name

grass.script.run_command("r.statistics", base, cover, method, output, flags=None, overwrite=False, verbose=False, quiet=False, superquiet=False)

Example:

gs.run_command("r.statistics", base="name", cover="name", method="string", output="name")

Parameters

base=name [required]
    Name of base raster map
cover=name [required]
    Name of cover raster map
method=string [required]
    Method of object-based statistic
    Allowed values: diversity, average, mode, median, avedev, stddev, variance, skewness, kurtosis, min, max, sum
    diversity: Diversity of values in specified objects in %%
    average: Average of values in specified objects
    mode: Mode of values in specified objects
    median: Median of values in specified objects
    avedev: Average deviation of values in specified objects
    stddev: Standard deviation of values in specified objects
    variance: Variance of values in specified objects
    skewness: Skewnes of values in specified objects
    kurtosis: Kurtosis of values in specified objects
    min: Minimum of values in specified objects
    max: Maximum of values in specified objects
    sum: Sum of values in specified objects
output=name [required]
    Resultant raster map
-c
    Cover values extracted from the category labels of the cover map
--overwrite
    Allow output files to overwrite existing files
--help
    Print usage summary
--verbose
    Verbose module output
--quiet
    Quiet module output
--qq
    Very quiet module output
--ui
    Force launching GUI dialog

base : str, required
    Name of base raster map
    Used as: input, raster, name
cover : str, required
    Name of cover raster map
    Used as: input, raster, name
method : str, required
    Method of object-based statistic
    Allowed values: diversity, average, mode, median, avedev, stddev, variance, skewness, kurtosis, min, max, sum
    diversity: Diversity of values in specified objects in %%
    average: Average of values in specified objects
    mode: Mode of values in specified objects
    median: Median of values in specified objects
    avedev: Average deviation of values in specified objects
    stddev: Standard deviation of values in specified objects
    variance: Variance of values in specified objects
    skewness: Skewnes of values in specified objects
    kurtosis: Kurtosis of values in specified objects
    min: Minimum of values in specified objects
    max: Maximum of values in specified objects
    sum: Sum of values in specified objects
output : str, required
    Resultant raster map
    Used as: output, raster, name
flags : str, optional
    Allowed values: c
    c
        Cover values extracted from the category labels of the cover map
overwrite: bool, optional
    Allow output files to overwrite existing files
    Default: False
verbose: bool, optional
    Verbose module output
    Default: False
quiet: bool, optional
    Quiet module output
    Default: False
superquiet: bool, optional
    Very quiet module output
    Default: False

DESCRIPTION

r.statistics is a tool to analyse exploratory statistics of a categorical "cover layer" according to how it intersects with objects in a "base layer". A variety of standard statistical measures are possible (called "zonal statistics" in some GIS). All cells in the base layer are considered one object for the analysis. For some applications, one will first want to prepare the input data so that all areas of contiguous cell category values in the base layer are uniquely identified, which can be done with r.clump.
The available methods are the following:

  • average deviation
  • average
  • diversity
  • kurtosis
  • maximum
  • median
  • minimum
  • mode
  • skewness
  • standard deviation
  • sum
  • variance

The calculations will be performed on each area of data of the cover layers which fall within each unique value, or category, of the base layer.

Setting the -c flag the category labels of the covering raster layer will be used. This is nice to avoid the GRASS limitation to integer in raster maps because using category values floating point numbers can be stored.

All calculations create an output layer. The output layer is a reclassified version of the base layer with identical category values, but modified category labels - the results of the calculations are stored in the category labels of the output layer.

NOTES

For floating-point cover map support, see the alternative r.stats.zonal. For quantile calculations with support for floating-point cover maps, see the alternative r.stats.quantile.

EXAMPLES

Calculation of average elevation of each field in the Spearfish region:

r.statistics base=fields cover=elevation.dem out=elevstats method=average
r.category elevstats
r.mapcalc "fieldelev = @elevstats"
r.univar fieldelev

SEE ALSO

r.category, r.clump, r.mode, r.mapcalc, r.neighbors, r.stats.quantile, r.stats.zonal, r.univar

AUTHOR

Martin Schroeder, Geographisches Institut Heidelberg, Germany

SOURCE CODE

Available at: r.statistics source code (history)
Latest change: Monday Feb 10 17:53:49 2025 in commit be43b74