Skip to content

r.stats.zonal

Calculates category or object oriented statistics (accumulator-based statistics).

r.stats.zonal [-cr] base=name cover=name method=string output=name [--overwrite] [--verbose] [--quiet] [--qq] [--ui]

Example:

r.stats.zonal base=name cover=name method=string output=name

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

Example:

gs.run_command("r.stats.zonal", 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: count, sum, min, max, range, average, avedev, variance, stddev, skewness, kurtosis, variance2, stddev2, skewness2, kurtosis2
    count: Count of values in specified objects
    sum: Sum of values in specified objects
    min: Minimum of values in specified objects
    max: Maximum of values in specified objects
    range: Range of values (max - min) in specified objects
    average: Average of values in specified objects
    avedev: Average deviation of values in specified objects
    variance: Variance of values in specified objects
    stddev: Standard deviation of values in specified objects
    skewness: Skewness of values in specified objects
    kurtosis: Kurtosis of values in specified objects
    variance2: (2-pass) Variance of values in specified objects
    stddev2: (2-pass) Standard deviation of values in specified objects
    skewness2: (2-pass) Skewness of values in specified objects
    kurtosis2: (2-pass) Kurtosis of values in specified objects
output=name [required]
    Resultant raster map
-c
    Cover values extracted from the category labels of the cover map
-r
    Create reclass map with statistics as category labels
--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: count, sum, min, max, range, average, avedev, variance, stddev, skewness, kurtosis, variance2, stddev2, skewness2, kurtosis2
    count: Count of values in specified objects
    sum: Sum of values in specified objects
    min: Minimum of values in specified objects
    max: Maximum of values in specified objects
    range: Range of values (max - min) in specified objects
    average: Average of values in specified objects
    avedev: Average deviation of values in specified objects
    variance: Variance of values in specified objects
    stddev: Standard deviation of values in specified objects
    skewness: Skewness of values in specified objects
    kurtosis: Kurtosis of values in specified objects
    variance2: (2-pass) Variance of values in specified objects
    stddev2: (2-pass) Standard deviation of values in specified objects
    skewness2: (2-pass) Skewness of values in specified objects
    kurtosis2: (2-pass) Kurtosis of values in specified objects
output : str, required
    Resultant raster map
    Used as: output, raster, name
flags : str, optional
    Allowed values: c, r
    c
        Cover values extracted from the category labels of the cover map
    r
        Create reclass map with statistics as category labels
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.stats.zonal is a tool to analyse exploratory statistics of a floating-point "cover layer" according to how it intersects with objects in a "base layer". A variety of standard statistical measures are possible. This type of analysis is often called zonal statistics. The zones are specified as the base raster map and the statistics are computed from cells in the cover raster map. Notably, the output of this module is spatial: The resulting values are recorded as cell values in the output raster map.

NOTES

r.stats.zonal is intended to be a partial replacement for r.statistics, with support for floating-point cover maps at the expense of not supporting quantiles. For this, see r.stats.quantile.

EXAMPLE

In this example, the raster polygon map zipcodes in the North Carolina sample dataset is used to calculate zonal raster statistics using the elevation raster map:

g.region raster=zipcodes -p

# pixel count in zipcode areas
r.stats.zonal base=zipcodes cover=elevation method=count output=zipcodes_elev_count
r.colors zipcodes_elev_count color=gyr -g

# average elevation in zipcode areas
r.stats.zonal base=zipcodes cover=elevation method=average output=zipcodes_elev_avg
r.colors zipcodes_elev_avg color=elevation -g

Zonal (average) elevation statistics

Figure: ZIP code map on the left shows ZIP code areas, elevation map the respective values per pixel, zonal statistics map on the right shows the average elevation per zone (all maps: spatial subset).

SEE ALSO

  • r.stats.quantile for computing quantiles in zones (objects in base raster map),
  • r.quantile for computing quantiles of a whole raster map,
  • r.statistics for categorical (integer) zonal statistics,
  • r.univar for zonal statistics with textual (non-spatial) output,
  • v.vect.stats for statistics of vector points in vector areas.

AUTHOR

Glynn Clements

SOURCE CODE

Available at: r.stats.zonal source code (history)
Latest change: Thursday Feb 13 11:55:34 2025 in commit ffc0b8c