r.statistics(1grass)

πŸ’– r.statistics β€” the GRASS User's Manual glow-up πŸ’–

okay bestie, gather round, because we're about to talk about zonal statistics and honestly? it's giving main character energy. this is r.statistics, straight out of the GRASS User's Manual, and yes it's a whole vibe.


✨ NAME ✨

r.statistics β€” calculates category or object oriented statistics. no cap, that's literally the whole job description. πŸŽ€

🌸 KEYWORDS 🌸

raster, statistics, zonal statistics


πŸ¦‹ SYNOPSIS πŸ¦‹

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

πŸ’… Flags πŸ’…

  • -c β€” cover values extracted from the category labels of the cover map. (yes, the little label goblin flag, we'll get to why it's iconic in a sec)
  • --overwrite β€” allow output files to overwrite existing files. permission to be feral, granted.
  • --help β€” print usage summary. when in doubt, ask for help, that's self care.
  • --verbose β€” verbose module output. it will yap. you asked for it.
  • --quiet β€” quiet module output. it'll shut up. also self care.
  • --ui β€” force launching GUI dialog. for when you want buttons instead of typing.

πŸ“ Parameters πŸ“

  • base=name [required] β€” name of base raster map. this is the map doing the object-ifying, the base layer, the moment.
  • cover=name [required] β€” name of cover raster map. this is the map whose values get analyzed inside those objects.
  • method=string [required] β€” method of object-based statistic. pick your fighter:
    • Options: 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. the baby. the finished product. πŸ‘‘

πŸ’œ DESCRIPTION πŸ’œ

okay so. 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). fr fr, some other software calls it that, and now you know.

Here's the tea: all cells in the base layer are considered one object for the analysis. one single object, one single vibe. 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. (translation: if you want each blob of same-value cells treated as its own lil object, run r.clump first. it's the pre-game. 🫢)

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. so like, every little pocket of cover data that lands inside a base category gets its stats done. stacking, nesting, cute.

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. ⭐ so you're not stuck with integers, you can smuggle actual floating point numbers in through the category labels. iykyk.

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. so the map looks the same shape-wise, but the labels are now full of math. iconic.

wait β€” the numbers live in the category labels, not in the cell data. don't come for me, that's just how it is. πŸ’€

🌈 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 🧚

Calculating 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

look at that pipeline bestie. r.statistics does the math, r.category shows you the receipts, r.mapcalc makes a real map out of it, and r.univar gives you the final vibe check. slay. ✨


🌸 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: Thursday May 08 20:58:05 2025 in commit: 4144ba81fa125e1549fc52e1cf5feb4fa004be8b

Main index | Raster index | Topics index | Keywords index | Graphical index | Full index


okay that's the whole page bestie, no skips, no summaries, every flag accounted for. periodt. πŸ’–

this has been r.statistics from the GRASS 8.5.0 Reference Manual, Β© 2003-2026 GRASS Development Team β€” thanks for scrolling all the way down, ily, go run some zonal stats πŸ¦‹πŸŒΈπŸ’…

πŸ“¦ where this page comes from