v.to.db(1)

πŸ’– v.to.db(1) β€” GRASS GIS User's Manual πŸ’–

okay bestie, sit down, hydrate, because today we're talking about v.to.db, a real one from the GRASS GIS User's Manual. she takes stuff your vector map knows about itself β€” areas, lengths, coordinates, whole vibes β€” and writes it into an attribute table, or just prints it out so you can look at it. no cap, this module is lowkey the backbone of half your attribute workflows. let's get into it 🫢


✨ NAME ✨

v.to.db β€” populates attribute values from vector features. literally that's her whole job and she does it flawlessly πŸ’…


πŸ”‘ KEYWORDS πŸ”‘

vector, attribute table, database, area, azimuth, bounding box, category, compactness, coordinates, fractal, geometry, length, perimeter, sides, sinuous, slope


πŸ“œ SYNOPSIS πŸ“œ

v.to.db
v.to.db --help
v.to.db [-phsc] map=name  [layer=string]   [type=string[,string,...]]
option=string columns=name[,name,...]  [units=string]
[query_layer=string]   [query_column=name]   [separator=character]
[--overwrite]  [--help]  [--verbose]  [--quiet]  [--ui]

🚩 Flags 🚩

  • -p β€” Print only. no table, no writes, just show me the receipts ✨
  • -h β€” Print header.
  • -s β€” Only print SQL statements. she'll hand you the SQL and let you do the rest, main character energy.
  • -c β€” Print also totals for option length, area, or count. love a lil summary πŸŽ€
  • --overwrite β€” Allow output files to overwrite existing files.
  • --help β€” Print usage summary.
  • --verbose β€” Verbose module output.
  • --quiet β€” Quiet module output.
  • --ui β€” Force launching GUI dialog.

πŸŽ›οΈ Parameters πŸŽ›οΈ

  • map=name [required] β€” Name of vector map. Or data source for direct OGR access.
  • layer=string β€” Layer number or name (write to). 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,...] β€” Feature type. For coor valid point/centroid, for length valid line/boundary. Options: point, line, boundary, centroid. Default: point,line,boundary,centroid
  • option=string [required] β€” Value to upload. Options: cat, area, compact, fd, perimeter, length, count, coor, start, end, sides, query, slope, sinuous, azimuth, bbox
    • cat: insert new row for each category if doesn't exist yet
    • area: area size
    • compact: compactness of an area, calculated as compactness = perimeter / (2 * sqrt(PI * area))
    • fd: fractal dimension of boundary defining a polygon, calculated as fd = 2 * (log(perimeter) / log(area))
    • perimeter: perimeter length of an area
    • length: line length
    • count: number of features for each category
    • coor: point coordinates, X,Y or X,Y,Z
    • start: line/boundary starting point coordinates, X,Y or X,Y,Z
    • end: line/boundary end point coordinates, X,Y or X,Y,Z
    • sides: categories of areas on the left and right side of the boundary, 'query_layer' is used for area category
    • query: result of a database query for all records of the geometry (or geometries) from table specified by 'query_layer' option
    • slope: slope steepness of vector line or boundary
    • sinuous: line sinuousity, calculated as line length / distance between end points
    • azimuth: line azimuth, calculated as angle between North direction and endnode direction at startnode
    • bbox: bounding box of area, N,S,E,W
  • columns=name[,name,...] [required] β€” Name of attribute column(s) to populate. Name of attribute column(s).
  • units=string β€” Units. Options: miles, feet, meters, kilometers, acres, hectares, radians, degrees
  • query_layer=string β€” Query layer number or name (read from). 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
  • query_column=name β€” Name of attribute column used for 'query' option. E.g. 'cat', 'count(*)', 'sum(val)'
  • separator=character β€” Field separator for print mode. Special characters: pipe, comma, space, tab, newline. Default: pipe

🌸 DESCRIPTION 🌸

so v.to.db loads vector map features or metrics into a database table, or prints them (or the SQL queries used to obtain them) in a form of a human-readable report. two modes, both iconic πŸ’–

for uploaded/printed category values, '-1' is used for 'no category', and 'null'/'-' if the category cannot be found or if multiple categories were found. for line azimuths, '-1' is used for closed lines (start equals end). noted. memorized. tattooed πŸŽ€


πŸ“ NOTES πŸ“

Measures of lengths and areas are always reported in meters, unless the unit parameter is set. and bestie, the units miles, feet, meters and kilometers are square for option=area. don't forget the square part, i'm begging πŸ™ˆ

Feet and acre units are always reported in their common versions (i.e. the International Foot, exactly 5280 feet in a mile), even when the coordinate reference system's standard map unit is the US Survey foot.

When calculating perimeters in Latitude-Longitude CRS, the geodesic distance between the vertices is used.

When using option=coor on a vector area map, only coordinates of centroids with unique category will be reported.

When using option=bbox on a vector area map with more than one feature per category value, the results corresponds to the bounding box of all features of same category taken together.

Line azimuth is calculated as angle from the North direction to the line endnode direction at the line statnode. By default it's reported in decimal degrees (0-360, CW) but it also may be repored in radians with unit=radians. Azimuth value -1 is used to report closed line with it's startnode and endnode being in same place. Azimuth values make sense only if every vector line has only one entry in database (unique CAT value).

If the module is apparently slow and the map attributes are stored in an external DBMS such as PostgreSQL, it is highly recommended to create an index on the key (category) column. fr fr, do it, your future self will thank you πŸ’…

Uploading the vector map attributes to a database requires a table attached to a given input vector layer. The print only (-p) mode doesn't require a table. Use db.execute or v.db.addtable to create a table if needed.

Updating the table has to be done column-wise. The column will be created in the table if it doesn't already exist, except when using the print only (-p) mode. If the column exists, the --overwrite flag is required to overwrite it. no sneaky silent overwrites here, she's polite like that 🫢


πŸ§ͺ EXAMPLES πŸ§ͺ

Updating attribute tables

Upload category numbers to attribute table (used for new map):

v.to.db map=soils type=centroid option=cat

Upload polygon areas to corresponding centroid record in the attribute table:

v.to.db map=soils type=centroid option=area columns=area_size unit=h

Upload line lengths (in meters) of each vector line to attribute table (use v.category in case of missing categories):

v.to.db map=roads option=length type=line columns=linelength units=me

Upload x and y coordinates from vector geometry to attribute table:

v.to.db map=pointsmap option=coor columns=x,y

Upload x, y and z coordinates from vector geometry to attribute table:

v.to.db map=pointsmap option=coor columns=x,y,z

Transfer attributes from a character column (with numeric contents) to a new integer column:

v.db.addcolumn usa_income_employment2002 col="FIPS_NUM integer"
v.to.db usa_income_employment2002 option=query columns=FIPS_NUM query_column=STATE_FIPS

Upload category numbers of left and right area, to an attribute table of boundaries common for the areas:

# add categories for boundaries of the input vector map, in layer 2:
v.category soils out=mysoils layer=2 type=boundary option=add
# add a table with columns named "left" and "right" to layer 2 of the input
# vector map:
v.db.addtable mysoils layer=2 columns="left integer,right integer"
# upload categories of left and right areas:
v.to.db mysoils option=sides columns=left,right layer=2
# display the result:
v.db.select mysoils layer=2

Compute DL, the Fractal Dimension (Mandelbrot, 1982), of the boundary defining a polygon based on the formula: D = 2 * (log perimeter) / (log area):

g.copy vect=soils,mysoils
v.db.addcolumn mysoils col="d double precision"
v.to.db mysoils option=fd column="d"
g.region vector=mysoils res=50
v.to.rast input=mysoils output=soils_fd type=area use=attr attribute_column=d
r.colors map=soils_fd color=gyr
d.mon wx0
d.rast.leg soils_fd
d.vect mysoils type=boundary

Printing reports

Report x,y,z coordinates of points in the input vector map:

v.to.db -p bugsites option=coor type=point

Report all area sizes of the input vector map:

v.to.db -p soils option=area type=boundary units=h

Report all area sizes of the input vector map, in hectares, sorted by category number (requires GNU sort utility installed):

v.to.db -p soils option=area type=boundary units=h | sort -n

Report all line lengths of the input vector map, in kilometers:

v.to.db -p roads option=length type=line units=k

Report number of features for each category in the input vector map:

v.to.db -p roads option=count type=line

πŸ“š REFERENCES πŸ“š

  1. Mandelbrot, B. B. (1982). The fractal geometry of nature. New York: W. H. Freeman.
  2. Xu, Y. F. & Sun, D. A. (2005). Geotechnique 55, No. 9, 691-695

πŸ‘€ SEE ALSO πŸ‘€

d.what.vect, db.execute, v.category, v.db.addtable, v.db.addcolumn, v.db.connect, v.distance, v.report, v.univar, v.what


πŸ‘‘ AUTHORS πŸ‘‘

Radim Blazek, ITC-irst, Trento, Italy Line sinuousity implemented by Wolf Bergenheim


πŸ’Ύ SOURCE CODE πŸ’Ύ

Available at: v.to.db source code (history)

Accessed: Saturday Jan 17 05:41:33 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, no skips, no cuts, every single flag and formula accounted for πŸ’– this was GRASS 8.4.2 and you were reading the v.to.db(1) manual β€” go populate an attribute table and slay, you've got this πŸ‘‘βœ¨πŸŒΈπŸ¦‹

πŸ“¦ where this page comes from