v.to.db

Langue: en

Autres versions - même langue

Version: 372349 (fedora - 01/12/10)

Section: 1 (Commandes utilisateur)

NAME

v.to.db - Populate database values from vector features.
Load values from vector to database. For uploaded/printed category values '-1' is used for 'no category' and 'null'/'-' if category cannot be found or multiple categories were found.

KEYWORDS

vector, database, attribute table

SYNOPSIS

v.to.db
v.to.db help
v.to.db [-psc] map=name [type=string[,string,...]] [layer=integer] [qlayer=integer] option=string [units=string] [column=string[,string,...]] [qcolumn=string] [--verbose] [--quiet]

Flags:

-p

Print only
-s

Only print sql statements
-c

In print mode prints totals for options: length,area,count
--verbose

Verbose module output
--quiet

Quiet module output

Parameters:

map=name

Name of input vector map
type=string[,string,...]

Type
Type of elements (for coor valid point/centroid, for length valid line/boundary)
Options: point,line,boundary,centroid
Default: point,line,boundary,centroid
layer=integer

Layer number
A single vector map can be connected to multiple database tables. This number determines which table to use.
Default: 1
qlayer=integer

Layer number
Query layer. Used by 'query' option.
Default: 1
option=string

Value to upload
Options: cat,area,compact,perimeter,length,count,coor,start,end,sides,query,slope
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))
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, 'qlayer' is used for area category
query: result of a database query for all records of the geometry(or geometries) from table specified by 'qlayer' option
slope: slope steepness of vector line or boundary
units=string

Units
mi(les),f(eet),me(ters),k(ilometers),a(cres),h(ectares)
Options: mi,miles,f,feet,me,meters,k,kilometers,a,acres,h,hectares
column=string[,string,...]

Column(s)
qcolumn=string

Query column used for 'query' option
E.g. 'cat', 'count(*)', 'sum(val)'

DESCRIPTION

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.

NOTES

The units miles, feet, meters and kilometers are square for option=area.

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 location's standard map unit is the US Survey foot.

When calculating perimeters in Latitude-Longitude locations, 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.

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.

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 must be present in the table, except when using the print only (-p) mode. Use db.execute or v.db.addcol to add new columns if needed.

EXAMPLES

Updating attribute tables

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

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

Upload area sizes of each polygon to attribute table:

v.to.db map=soils type=area option=area col=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 col=linelength units=me

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

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

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

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

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

v.db.addcol usa_income_employment2002 col="FIPS_NUM integer"
v.to.db usa_income_employment2002 option=query col=FIPS_NUM qcol=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 col="left integer,right integer"
# upload categories of left and right areas:
v.to.db mysoils option=sides col=left,right layer=2
# display the result:
v.db.select mysoils layer=2

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

SEE ALSO

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

AUTHOR

Radim Blazek

Last changed: $Date: 2007-11-20 10:34:59 +0100 (Tue, 20 Nov 2007) $

Full index

© 2003-2008 GRASS Development Team