r.stats(1grass)
π r.stats π (1grass) β the GRASS User's Manual glow-up β¨
okay bestie, listen. this is the GRASS User's Manual page for r.stats(1grass), and it generates area statistics for raster map. that's the whole vibe. it's a raster/statistics girlie and she's lowkey iconic. π
π KEYWORDS π
raster, statistics β that's the whole tag list, no cap. π¦
β¨ SYNOPSIS β¨
r.stats
r.stats --help
r.stats [-acpl1gxArnNCi] input=name[,name,...] [output=name]
[separator=character] [null_value=string] [nsteps=integer]
[sort=string] format=name [--overwrite] [--help] [--verbose]
[--quiet] [--ui]
πΈ Flags πΈ
-aβ prints the area totals in square meters π-cβ prints cell counts, and bestie they're sortable π-pβ prints percents, but they're approximate (so the total might not add up to 100%, don't come for me)-lβ prints the category labels π·οΈ-1β one cell (range) per line, one at a time, we respect personal space-gβ prints grid coordinates (east and north) π§-xβ prints x and y (column and row). indexing starts with 1: first column and row are 1 β-Aβ prints averaged values instead of intervals (floating-point maps only) π«§-rβ prints raw indexes of floating-point ranges (floating-point maps only)-nβ do not report no data value π-Nβ do not report cells where all maps have no data-Cβ report for cats floating-point ranges (floating-point maps only) π±-iβ read floating-point map as integer (uses the mapβs quant rules)--overwriteβ lets output files overwrite files that already exist (chaotic, but ok)--helpβ prints the usage summary--verboseβ verbose module output, she's chatty--quietβ quiet module output, she's mysterious--uiβ force-launches the GUI dialog π₯οΈ
π Parameters π
input=name[,name,...][required] β name of the raster map(s) you want to report onoutput=nameβ name for the output file. if it's omitted, or you just put-, it goes to stdout π«separator=characterβ the field separator. special characters you can use: pipe, comma, space, tab, newlinenull_value=stringβ the string that represents the NULL value. default:*nsteps=integerβ how many floating-point subranges to collect stats from. default:255sort=stringβ sort the output statistics by cell counts. default is sorted by categories or intervals. options:asc,descasc: sort by cell counts in ascending order β¬οΈdesc: sort by cell counts in descending order β¬οΈ
format=name[required] β output format. options:plain,csv,json. default:plainplain: human readable text outputcsv: CSV (Comma Separated Values)json: JSON (JavaScript Object Notation)
π DESCRIPTION π
r.stats calculates the area present in each of the categories or floating-point intervals of your user-selected input raster map. area statistics come in units of square meters and/or cell counts. this analysis uses the current geographic region (g.region) and mask settings (r.mask). and yes, the output statistics can be saved to an output file. π
area statistics get printed in square meters for each category when you pass -a. similarly, if you pick the -c flag, areas will be stated in number of cells too. two for one, we love a multitasker. π
π NOTES π
if you specify a single raster map, you get a list of categories printed out. the -x flag will print x and y (column and row) starting with 1 (both the first row and the first column are indexed with 1). if you specify multiple raster maps, a cross-tabulation table for each combination of categories in the raster maps gets printed. π
for example, if one raster map was specified, the output would look like:
1 1350000.00
2 4940000.00
3 8870000.00
if three raster maps were specified, the output would look like:
0 0 0 8027500.00
0 1 0 1152500.00
1 0 0 164227500.00
1 0 1 2177500.00
1 1 0 140092500.00
1 1 1 3355000.00
2 0 0 31277500.00
2 0 1 2490000.00
2 1 0 24207500.00
2 1 1 1752500.00
3 0 0 17140000.00
3 1 0 11270000.00
3 1 1 2500.00
within each grouping, the first field is the category value of the first raster map, the second is the category values associated with the second raster map, the third is the category values for the third raster map, and the last field gives the area in square meters for that particular combination of these three raster maps' categories. for example, above, combination 3,1,1 covered 2500 square meters. fields are separated by the separator option. the output from r.stats is sorted by category or category intervals (for floating-point raster maps). π₯
note that you only get the option of printing out cell statistics in terms of cell counts and/or area totals. if you want units other than the ones available here, use r.report instead. iykyk. π§
πΈ EXAMPLES πΈ
Report area for each category
report the area for each category in the single raster map:
g.region raster=geology_30m
r.stats -a in=geology_30m nv=no-data sep=tab
217 71960000.000000
262 19760000.000000
270 67760000.000000
405 25120000.000000
583 2520000.000000
720 480000.000000
766 840000.000000
862 6560000.000000
910 4360000.000000
921 1200000.000000
946 360000.000000
948 80000.000000
no-data 33375200000.000004
Report sorted number of cells for each category
report the sorted number of cells for each category in the single raster map (suppress NULL data):
g.region raster=geology_30m
r.stats -cn input=geology_30m sort=desc
217 1799
270 1694
405 628
262 494
862 164
910 109
583 63
921 30
766 21
720 12
946 9
948 2
Report area, number of cells, and percents in multiple raster maps
report area, number of cells, and percents (separated by tabs) for each category in multiple raster maps (suppress NULL data):
g.region raster=towns
r.stats -nacp input=towns,urban separator=tab
1 55 23840000.000000 596 11.89%
2 55 13680000.000000 342 6.82%
3 55 1360000.000000 34 0.68%
4 55 16040000.000000 401 8.00%
5 55 98240000.000000 2456 48.98%
6 55 19760000.000000 494 9.85%
Report sorted area intervals of floating-point raster map
report the sorted area for each interval of a floating-point input raster map. the number of intervals is given by the nsteps option.
g.region raster=elevation
r.stats -an input=elevation nsteps=10 sort=desc separator=tab
95.879221-105.954329 36440000.000000
85.804114-95.879221 30800000.000000
105.954329-116.029436 30080000.000000
116.029436-126.104543 27960000.000000
126.104543-136.17965 26440000.000000
136.17965-146.254757 20880000.000000
75.729007-85.804114 15880000.000000
65.6539-75.729007 6040000.000000
146.254757-156.329865 5720000.000000
55.578793-65.6539 760000.000000
JSON Format
g.region raster=elevation
r.stats -an input=elevation nsteps=10 sort=desc format=json
[
{
"categories": [
{
"range": {
"from": 116.02943572998046,
"to": 126.10454292297364
}
}
],
"area": 1188100
},
{
"categories": [
{
"range": {
"from": 105.9543285369873,
"to": 116.02943572998046
}
}
],
"area": 857300
},
{
"categories": [
{
"range": {
"from": 126.10454292297364,
"to": 136.17965011596681
}
}
],
"area": 504700
},
{
"categories": [
{
"range": {
"from": 95.879221343994146,
"to": 105.9543285369873
}
}
],
"area": 336900
},
{
"categories": [
{
"range": {
"from": 85.804114151000974,
"to": 95.879221343994146
}
}
],
"area": 66500
}
]
Report raster cell counts in multiple raster maps
report raster cell counts of landuse and geological categories within zipcode areas:
g.region raster=zipcodes
# landuse/landcover and zipcodes
r.stats -c input=landclass96,zipcodes separator=comma
# landuse/landcover, geology and zipcodes with category labels
r.stats -c input=landclass96,zipcodes,geology_30m separator=comma -l
π¦ SEE ALSO π¦
g.region, r.report, r.coin, r.describe, r.stats.quantile, r.stats.zonal, r.statistics, r.univar
π AUTHORS π
Michael Shapiro, U.S. Army Construction Engineering Research Laboratory Sort option by Martin Landa, Czech Technical University in Prague, 2013
π«Ά SOURCE CODE π«Ά
Available at: r.stats source code (history)
Latest change: Thursday Oct 02 14:39:13 2025 in commit: 1850489bf42c72d8dcfe2e4db1738441b4a7dc43
Main index | Raster index | Topics index | Keywords index | Graphical index | Full index
and that's the whole page bestie, you ate that. π
β¨ this was GRASS 8.5.0, Β© 2003-2026 GRASS Development Team, straight out of the GRASS 8.5.0 Reference Manual β and the page itself is r.stats(1grass), so go forth and compute those stats, periodt. ππ¦π
π¦ where this page comes from
- alpine 3.24: grass-gis-doc 8.5.0-r1 Β· GPL-2.0-or-later
- ubuntu stonking: grass-doc 8.5.0-1ubuntu1 Β· GPL-2.0-or-later
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms