v.vect.stats(1grass)
β¨ v.vect.stats β¨
okay bestie, gather round, because this is the v.vect.stats manual page from the GRASS User's Manual and it is literally about counting points in areas and doing stats on point attributes. we're gonna get through this together and it's gonna be adorable and also extremely thorough π
KEYWORDS: vector, attribute table, database, univariate statistics, zonal statistics
πΈ SYNOPSIS πΈ
v.vect.stats
v.vect.stats --help
v.vect.stats [-p] points=name areas=name [type=string[,string,...]]
[points_layer=string] [points_cats=range] [points_where=sql_query]
[areas_layer=string] [areas_cats=range] [areas_where=sql_query]
[method=string] [points_column=name] [count_column=name]
[stats_column=name] [separator=character] format=name [--help]
[--verbose] [--quiet] [--ui]
π Flags
-pβ Print output to stdout, do not update attribute table. First column is always area category.--helpβ Print usage summary--verboseβ Verbose module output--quietβ Quiet module output--uiβ Force launching GUI dialog
π¦ Parameters
points=name[required] β Name of existing vector map with points. Or data source for direct OGR access.areas=name[required] β Name of existing vector map with areas. Or data source for direct OGR access.type=string[,string,...]β Feature type. Input feature type. Options:point,centroid. Default:point.points_layer=stringβ Layer number for points map. 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.points_cats=rangeβ Category values for points map. Example:1,3,7-9,13.points_where=sql_queryβ WHERE conditions of SQL statement without 'where' keyword for points map. Example:income < 1000 and population >= 10000.areas_layer=stringβ Layer number for area map. 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.areas_cats=rangeβ Category values for area map. Example:1,3,7-9,13.areas_where=sql_queryβ WHERE conditions of SQL statement without 'where' keyword for area map. Example:income < 1000 and population >= 10000.method=stringβ Method for aggregate statistics. Options:sum,average,median,mode,minimum,min_cat,maximum,max_cat,range,stddev,variance,diversity.points_column=nameβ Column name of points map to use for statistics. Column of points map must be numeric.count_column=nameβ Column name to upload points count. Column to hold points count, must be of type integer, will be created if not existing.stats_column=nameβ Column name to upload statistics. Column to hold statistics, must be of type double, will be created if not existing.separator=characterβ Field separator. Special characters:pipe,comma,space,tab,newline.format=name[required] β Output format. Options:plain,csv,json. Default:plain.plain: Human readable text outputcsv: CSV (Comma Separated Values)json: JSON (JavaScript Object Notation)
π DESCRIPTION π
so v.vect.stats counts the number of points in vector map points that fall into each area in vector map areas. and optionally it can calculate statistics on point attributes in points for each area. the results get either uploaded to the attribute table of the vector map areas, or printed to stdout. pick your fighter π
π₯ Statistical methods
using numeric attribute values of all points falling into a given area, a new value is determined with the selected method. v.vect.stats can perform the following operations:
sumβ The sum of values.averageβ The average value of all point attributes (sum / count).medianβ The value found half-way through a list of the attribute values, when these are ranged in numerical order.modeβ The most frequently occurring value.minimumβ The minimum observed value.min_catβ The point category corresponding to the minimum observed value.maximumβ The maximum observed value.max_catβ The point category corresponding to the maximum observed value.rangeβ The range of the observed values.stddevβ The statistical standard deviation of the attribute values.varianceβ The statistical variance of the attribute values.diversityβ The number of different attribute values.
π NOTES π
Points not falling into any area are ignored. Areas without category (no centroid attached or centroid without category) are ignored. If no points are falling into a given area, the point count is set to0(zero) and the statistics result to"null".
The columns count_column and stats_column are created if not yet existing. If they do already exist, the count_column must be of type integer and the stats_column of type double precision.
In case that v.vect.stats complains about the points_column of the input points vector map not being numeric, the module v.db.update can be used to perform type casting, i.e. adding and populating an additional numeric column with the values type converted from string attributes to floating point numbers.
π EXAMPLES π
π Preparation for examples
The subsequent examples are based on randomly sampled elevation data (North Carolina sample database):
# work on map copy for attribute editing
g.copy vector=zipcodes_wake,myzipcodes_wake
# set computational region: extent of ZIP code map, raster pixels
# aligned to raster map
g.region vector=myzipcodes_wake align=elev_state_500m -p
# generate random elevation points
r.random elev_state_500m vector=rand5000 n=5000
v.colors rand5000 color=elevation
# visualization
d.mon wx0
d.vect myzipcodes_wake -c
d.vect rand5000
These vector maps are used for the examples below.
π§ Count points per polygon with printed output
See above for the creation of the input maps.
Counting points per polygon, print results to terminal:
v.vect.stats points=rand5000 area=myzipcodes_wake -p
π Count points per polygon with column update
See above for the creation of the input maps.
Counting of points per polygon, with update of "num_points" column (will be automatically created):
v.vect.stats points=rand5000 area=myzipcodes_wake count_column=num_points
# verify result
v.db.select myzipcodes_wake column=ZIPCODE_,ZIPNAME,num_points
β¨ Average values of points in polygon with printed output
See above for the creation of the input maps.
Calculation of average point elevation per ZIP code polygon, printed to terminal in comma separated style:
# check name of point map column:
v.info -c rand5000
v.vect.stats points=rand5000 area=myzipcodes_wake \
method=average points_column=value separator=comma -p
π Average values of points in polygon with column update
See above for the creation of the input maps.
Calculation of average point elevation per ZIP code polygon, with update of "avg_elev" column and counting of points per polygon, with update of "num_points" column (new columns will be automatically created):
# check name of point map column:
v.info -c rand5000
v.vect.stats points=rand5000 area=myzipcodes_wake count_column=num_points \
method=average points_column=value stats_column=avg_elev
# verify result
v.db.select myzipcodes_wake column=ZIPCODE_,ZIPNAME,avg_elev
π Point statistics in a hexagonal grid
The grid extent and size is influenced by the current computational region. The extent is based on the vector map points_of_interest from the basic North Carolina sample dataset.
g.region vector=points_of_interest res=2000 -pa
The hexagonal grid is created using the v.mkgrid module as a vector map based on the previously selected extent and size of the grid.
v.mkgrid map=hexagons -h
The v.vect.stats module counts the number of points and does one statistics on a selected column (here: elev_m).
v.vect.stats points=points_of_interest areas=hexagons method=average \
points_column=elev_m count_column=count stats_column=average
User should note that some of the points may be outside the grid since the hexagons cannot cover all the area around the edges (the computational region extent needs to be enlarged if all points should be considered). The last command sets the vector map color table to viridis based on the count column.
v.colors map=hexagons use=attr column=average color=viridis
Point statistics in a hexagonal grid (count of points, average of values associated with point, standard deviation)
π¦ SEE ALSO π¦
v.rast.statsfor zonal statistics of raster maps using vector zones (univariate statistics of a raster map),r.stats.zonalfor zonal statistics of raster map using raster zones (univariate statistics using two raster maps),v.what.vectfor querying one vector map by another,v.distancefor finding nearest features,r.distancefor computing distances between objects in raster maps,v.mkgridfor creating vector grids to aggregate point data.
π AUTHOR π
Markus Metz
π SOURCE CODE π
Available at: v.vect.stats source code (history)
Latest change: Saturday Oct 11 04:38:40 2025 in commit: 3dd71f5fab83b72a2db2da959fe075c5b3b52200
Main index | Vector index | Topics index | Keywords index | Graphical index | Full index
Β© 2003-2026 GRASS Development Team, GRASS 8.5.0 Reference Manual
and that's the whole page bestie, you made it, we're so back π«Ά this was v.vect.stats from the GRASS 8.5.0 Reference Manual (that's the version + date up top and down at the bottom, don't @ me) β go count some points, slay π
β¨
π¦ 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