v.rast.stats(1grass)

✨ v.rast.stats ✨

okay bestie so you're reading the GRASS User's Manual page for v.rast.stats and honestly? it's giving zonal statistics but make it fashion. it's a GRASS module, it lives in the grass manual, and it's about to become your new obsession πŸ’–


🌸 NAME 🌸

v.rast.stats β€” literally calculates univariate statistics from a raster map based on a vector map and uploads those statistics to new attribute columns. that's the whole vibe. no cap.


🏷️ KEYWORDS 🏷️

vector, statistics, raster, univariate statistics, zonal statistics, sampling, querying


πŸ¦‹ SYNOPSIS πŸ¦‹

v.rast.stats
v.rast.stats --help
v.rast.stats [-cd] map=name  [layer=string]   [type=string[,string,...]]
[where=sql_query]  raster=name[,name,...]
column_prefix=string[,string,...]  [method=string[,string,...]]
[percentile=integer]   [--help]  [--verbose]  [--quiet]  [--ui]

πŸŽ€ Flags πŸŽ€

  • -c β€” Continue if upload column(s) already exist. like, keep going even if the columns are already there, she's not gonna stop for that πŸ’…
  • -d β€” Create densified lines (default: thin lines). All cells touched by the line will be set, not only those on the render path. so the line gets thicc and grabs everything it touches ✨
  • --help β€” Print usage summary. the little "help me" button 🫢
  • --verbose β€” Verbose module output. she talks a LOT πŸ’¬
  • --quiet β€” Quiet module output. she says nothing 🀫
  • --ui β€” Force launching GUI dialog. pop-up era πŸ‘‘

🌈 Parameters 🌈

  • map=name [required] β€” Name of vector map. Or data source for direct OGR access.
  • layer=string β€” Layer number or name. Vector features can have category values in different layers. This number determines which layer to use. When used with direct OGR access this is the layer name. Default: 1.
  • type=string[,string,...] β€” Input feature type. Options: point, line, boundary, centroid, area. Default: point,line,boundary,centroid,area (yes, all of them, she's an overachiever).
  • where=sql_query β€” WHERE conditions of SQL statement without 'where' keyword. Example: income < 1000 and population >= 10000.
  • raster=name[,name,...] [required] β€” Name of input raster map to calculate statistics from.
  • column_prefix=string[,string,...] [required] β€” Column prefix for new attribute columns.
  • method=string[,string,...] β€” The methods to use. Options: number, null_cells, minimum, maximum, range, average, stddev, variance, coeff_var, sum, first_quartile, median, third_quartile, percentile. Default: number,null_cells,minimum,maximum,range,average,stddev,variance,coeff_var,sum,first_quartile,median,third_quartile,percentile.
  • percentile=integer β€” Percentile to calculate. Options: 0-100. Default: 90.

πŸ’œ DESCRIPTION πŸ’œ

so v.rast.stats calculates basic univariate statistics from a raster map β€” but only for the parts covered by the specified vector map. only the parts the vector map is standing on. she's not doing extra credit for free zones.

the vector map gets rasterized according to the raster map resolution. then univariate statistics are calculated per vector category (cat) from the raster map, and the results get uploaded into the vector map attribute table. a new column is generated in the attribute table for each statistic you requested in method β€” but only if it's not already present, bestie, she checks first.

the univariate statistics include:

  • the number of raster cells counted
  • the number of raster NULL cells counted
  • minimum and maximum cell values
  • range
  • average
  • standard deviation
  • variance
  • coefficient of variation
  • sum
  • first quartile
  • median
  • third quartile
  • and percentile

that's the whole roster. iconic lineup honestly πŸ‘‘


πŸ“ NOTES πŸ“

v.rast.stats is only meaningful for lines or polygons. that's the vibe check β€” points and centroids, we don't really know her like that.

the module may take a long time to run if the raster region contains a large number of cells. in that case the --verbose flag may be used to track progress. so if you're sitting there like "is she alive??" β€” --verbose, she'll tell you 😭

the script stops if a (prefixed) upload column is already present in the vector map attribute table, unless otherwise instructed with the -c continue flag. so rude of her to just bail, but okay. the column prefix will be separated from the statistic name with an underscore. for example, with a prefix of "elev" the sum column will be named elev_sum. the underscore is doing the heavy lifting, periodt.

if a DBF database is being used, note that column names are restricted by the DBF specification to 10 characters. therefore it is advised to be economical in the use of the column prefix when using DBF, as any additional characters will be chopped off. she will literally chop them off bestie, do not test her βœ‚οΈ

the script internally aligns the raster grid cells to the grid of the first input raster map. first one on the list leads, everybody else follows.

if an area has several categories in the selected layer (equivalent to overlapping polygons in Simple Features), only one category will be kept during the rasterization process. statistics for the skipped categories will thus be partial. lowkey devastating.

for example, if there are three areas: area 1 with cat 1, area 2 with cat 2, area 3 with cats 1, 2. only one category value of area 3 will be used for rasterization, the other category value will be skipped. thus statistics for the used category value will be complete, while statistics for the skipped category value will be incomplete. so area 3 is only half of a main character. tragic.

⚠️ large amounts of system memory can be used when extended statistics (first_quartile,median,third_quartile,percentile) are being requested with a very large region setting. if the region is too large the module should display memory allocation errors. basic statistics can be calculated using any size input region β€” so if your machine starts wheezing, that's the extended stats' fault, not yours 🫠

πŸ“ EXAMPLES πŸ“

example to upload DEM statistics to a ZIP codes vector map (North Carolina sample dataset):

g.copy vect=zipcodes_wake,myzipcodes_wake
# set computational region to DEM:
g.region raster=elevation -p
# calculate selected DEM statistics, upload to vector map table:
v.rast.stats myzipcodes_wake raster=elevation \
  column_prefix=elev method=minimum,maximum,average,range,stddev,percentile \
  percentile=95
# verify results:
v.info -c myzipcodes_wake
v.db.select myzipcodes_wake
v.univar myzipcodes_wake column=elev_range type=centroid

copy it, paste it, run it, slay it πŸ’…βœ¨


πŸ‘€ SEE ALSO πŸ‘€

r.univar, v.univar, v.vect.stats, v.what.rast, v.what.rast3, v.what.vect

(the whole friend group 🫢 go read their pages too)


🧚 AUTHOR 🧚

Markus Neteler, CEA (for the EDEN EU/FP6 Project)


⭐ SOURCE CODE ⭐

Available at: v.rast.stats source code (history)

Latest change: Thursday Aug 21 13:31:24 2025 in commit: 5626d00f2e1911bc29cd35b3ee853a72e5ab523c

Main index | Vector index | Topics index | Keywords index | Graphical index | Full index

Β© 2003-2026 GRASS Development Team, GRASS 8.5.0 Reference Manual


okay that's the whole page bestie, no crumbs left πŸͺ and a lil sign-off for you: this manual came from GRASS 8.5.0 (the reference manual, Β© 2003-2026 GRASS Development Team, with the latest change landing Thursday Aug 21 13:31:24 2025 in commit 5626d00f2e1911bc29cd35b3ee853a72e5ab523c) β€” now go calculate some stats, you absolute queen πŸ‘‘πŸ’–

πŸ“¦ where this page comes from