v.rast.stats(1)

πŸ’– v.rast.stats β€” the manual, but make it cute πŸ’–

okay bestie, welcome to v.rast.stats from the GRASS GIS User's Manual β€” she's a vector module and she's about to do some serious math on your raster data. 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 β€” keep going even if the upload column(s) already exist πŸ’… (she's forgiving like that)
  • -d β€” create densified lines (default is thin lines). the way that this works is all cells touched by the line get set, not just the ones on the render path πŸ‘‘
  • --help β€” prints the usage summary, for when you're lost πŸ₯Ί
  • --verbose β€” verbose module output, aka she tells you everything πŸ—£οΈ
  • --quiet β€” quiet module output, aka she says nothing 🀫
  • --ui β€” force launching the GUI dialog, if you're a visual girlie πŸ–₯️✨

🌈 Parameters

  • map=name [required] β€” name of vector map. or, plot twist, a data source for direct OGR access 🫢
  • layer=string β€” layer number or name. vector features can have category values in different layers, and this number decides 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
  • where=sql_query β€” WHERE conditions of an SQL statement, no where keyword needed. example: income < 1000 and population >= 10000
  • raster=name[,name,...] [required] β€” name of the input raster map to calculate statistics from πŸ—ΊοΈ
  • column_prefix=string[,string,...] [required] β€” column prefix for the 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 (yes she wants all of them by default, she's an overachiever πŸ’…)
  • percentile=integer β€” percentile to calculate. options: 0-100. default: 90

πŸ’œ DESCRIPTION πŸ’œ

okay so v.rast.stats calculates basic univariate statistics from a raster map, but only for the parts covered by the specified vector map. literally just that overlap. ✨

the vector map gets rasterized according to the raster map resolution, then univariate statistics get calculated per vector category (cat) from the raster map, and the results get uploaded to 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 there, bestie.

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. it's giving statistical buffet. πŸ“


πŸ¦‹ NOTES πŸ¦‹

v.rast.stats is only meaningful for lines or polygons. that's the vibe check, fr fr.

this module may take a long time to run if the raster region contains a large number of cells. in that case, use the --verbose flag to track progress. patience is a virtue bestie 😭

the script stops if a (prefixed) upload column is already present in the vector map attribute table β€” unless you tell it otherwise with the -c continue flag. the column prefix gets separated from the statistic name with an underscore. so for example, with a prefix of "elev" the sum column will be named elev_sum. iconic naming convention honestly.

if a DBF database is being used, note that column names are restricted by the DBF specification to 10 characters. therefore it's advised to be economical in the use of the column prefix when using DBF, since any additional characters will get chopped off. πŸ’€ so keep it short, girlie.

if a MASK is present, it will be restored after the script finishes. the script changes temporarily to the resolution of the given raster map. 🧚

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. πŸ™ˆ

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. periodt.

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. πŸ‘‘

🌟 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

she ate that. πŸ”₯


🫢 SEE ALSO 🫢

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

πŸ‘‘ AUTHOR πŸ‘‘

Markus Neteler, CEA (for the EDEN EU/FP6 Project) β€” thank you king πŸ™


πŸ’… SOURCE CODE πŸ’…

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

accessed: Saturday Jan 17 05:41:53 2026

main index | vector index | topics index | keywords index | graphical index | full index

Β© 2003-2025 GRASS Development Team, GRASS GIS 8.4.2 Reference Manual


okay that's the whole page bestie!! πŸ’– this was v.rast.stats(1) from GRASS 8.4.2, accessed Saturday Jan 17 05:41:53 2026, Β© 2003-2025 GRASS Development Team β€” now go calculate some stats, you've got this πŸŽ€βœ¨πŸ¦‹

πŸ“¦ where this page comes from