1v.to.db(1)                    Grass User's Manual                   v.to.db(1)
2
3
4

NAME

6       v.to.db  - Populates attribute values from vector features.
7

KEYWORDS

9       vector,  attribute  table,  database,  area, length, perimeter, coordi‐
10       nates, bounding box, category
11

SYNOPSIS

13       v.to.db
14       v.to.db --help
15       v.to.db [-psc]  map=name   [layer=string]    [type=string[,string,...]]
16       option=string          columns=name[,name,...]           [units=string]
17       [query_layer=string]     [query_column=name]      [separator=character]
18       [--help]  [--verbose]  [--quiet]  [--ui]
19
20   Flags:
21       -p
22           Print only
23
24       -s
25           Only print SQL statements
26
27       -c
28           Print also totals for option length, area, or count
29
30       --help
31           Print usage summary
32
33       --verbose
34           Verbose module output
35
36       --quiet
37           Quiet module output
38
39       --ui
40           Force launching GUI dialog
41
42   Parameters:
43       map=name [required]
44           Name of vector map
45           Or data source for direct OGR access
46
47       layer=string
48           Layer number or name (write to)
49           Vector  features can have category values in different layers. This
50           number determines which layer to use. When  used  with  direct  OGR
51           access this is the layer name.
52           Default: 1
53
54       type=string[,string,...]
55           Feature type
56           For coor valid point/centroid, for length valid line/boundary
57           Options: point, line, boundary, centroid
58           Default: point,line,boundary,centroid
59
60       option=string [required]
61           Value to upload
62           Options:  cat,  area,  compact, fd, perimeter, length, count, coor,
63           start, end, sides, query, slope, sinuous, azimuth, bbox
64           cat: insert new row for each category if doesn’t exist yet
65           area: area size
66           compact: compactness of an area, calculated as
67           compactness = perimeter / (2 * sqrt(PI * area))
68           fd: fractal dimension of boundary defining a polygon, calculated as
69           fd = 2 * (log(perimeter) / log(area))
70           perimeter: perimeter length of an area
71           length: line length
72           count: number of features for each category
73           coor: point coordinates, X,Y or X,Y,Z
74           start: line/boundary starting point coordinates, X,Y or X,Y,Z
75           end: line/boundary end point coordinates, X,Y or X,Y,Z
76           sides: categories of areas on the left and right side of the bound‐
77           ary, ’query_layer’ is used for area category
78           query:  result  of  a  database query for all records of the geome‐
79           try(or geometries) from table specified by ’query_layer’ option
80           slope: slope steepness of vector line or boundary
81           sinuous: line sinuousity, calculated  as  line  length  /  distance
82           between end points
83           azimuth:  line azimuth, calculated as angle between North direction
84           and endnode direction at startnode
85           bbox: bounding box of area, N,S,E,W
86
87       columns=name[,name,...] [required]
88           Name of attribute column(s) to populate
89           Name of attribute column(s)
90
91       units=string
92           Units
93           Options: miles, feet, meters, kilometers, acres, hectares, radians,
94           degrees
95
96       query_layer=string
97           Query layer number or name (read from)
98           Vector  features can have category values in different layers. This
99           number determines which layer to use. When  used  with  direct  OGR
100           access this is the layer name.
101           Default: 1
102
103       query_column=name
104           Name of attribute column used for ’query’ option
105           E.g. ’cat’, ’count(*)’, ’sum(val)’
106
107       separator=character
108           Field separator for print mode
109           Special characters: pipe, comma, space, tab, newline
110           Default: pipe
111

DESCRIPTION

113       v.to.db  loads vector map features or metrics into a database table, or
114       prints them (or the SQL queries used to obtain them) in  a  form  of  a
115       human-readable  report.  For  uploaded/printed  category values ’-1’ is
116       used for ’no category’ and ’null’/’-’ if category cannot  be  found  or
117       multiple  categories  were  found.  For  line azimuths ’-1’ is used for
118       closed lines (start equals end).
119

NOTES

121       Measures of lengths and areas are always reported in meters, unless the
122       unit  parameter  is  set.  The units miles, feet, meters and kilometers
123       are square for option=area.
124
125       Feet and acre units are always reported in their common versions  (i.e.
126       the  International  Foot,  exactly  5280 feet in a mile), even when the
127       location’s standard map unit is the US Survey foot.
128
129       When calculating perimeters in Latitude-Longitude locations,  the  geo‐
130       desic distance between the vertices is used.
131
132       When  using  option=coor on a vector area map, only coordinates of cen‐
133       troids with unique category will be reported.
134
135       When using option=bbox on a vector area map with more than one  feature
136       per  category value, the results corresponds to the bounding box of all
137       features of same category taken together.
138
139       Line azimuth is calculated as angle from the  North  direction  to  the
140       line  endnode  direction at the line statnode. By default it’s reported
141       in decimal degrees (0-360, CW) but it also may be  repored  in  radians
142       with  unit=radians. Azimuth value -1 is used to report closed line with
143       it’s startnode and endnode being in same  place.  Azimuth  values  make
144       sense  only if every vector line has only one entry in database (unique
145       CAT value).
146
147       If the module is apparently slow and the map attributes are  stored  in
148       an external DBMS such as PostgreSQL, it is highly recommended to create
149       an index on the key (category) column.
150
151       Uploading the vector map attributes to  a  database  requires  a  table
152       attached  to  a  given  input  vector  layer.  The print only (-p) mode
153       doesn’t require a table. Use db.execute or v.db.addtable  to  create  a
154       table if needed.
155
156       Updating  the  table  has  to  be  done column-wise. The column must be
157       present in the table, except when using the print only (-p)  mode.  Use
158       db.execute or v.db.addcolumn to add new columns if needed.
159

EXAMPLES

161   Updating attribute tables
162       Upload category numbers to attribute table (used for new map):
163       v.to.db map=soils type=centroid option=cat
164
165       Upload  polygon areas to corresponding centroid record in the attribute
166       table:
167       v.to.db map=soils type=centroid option=area columns=area_size unit=h
168
169       Upload line lengths (in meters) of each vector line to attribute  table
170       (use v.category in case of missing categories):
171       v.to.db map=roads option=length type=line columns=linelength units=me
172
173       Upload x and y coordinates from vector geometry to attribute table:
174       v.to.db map=pointsmap option=coor columns=x,y
175
176       Upload x, y and z coordinates from vector geometry to attribute table:
177       v.to.db map=pointsmap option=coor columns=x,y,z
178
179       Transfer  attributes from a character column (with numeric contents) to
180       a new integer column:
181       v.db.addcolumn usa_income_employment2002 col="FIPS_NUM integer"
182       v.to.db usa_income_employment2002 option=query columns=FIPS_NUM query_column=STATE_FIPS
183
184       Upload category numbers of left and right area, to an  attribute  table
185       of boundaries common for the areas:
186       # add categories for boundaries of the input vector map, in layer 2:
187       v.category soils out=mysoils layer=2 type=boundary option=add
188       # add a table with columns named "left" and "right" to layer 2 of the input
189       # vector map:
190       v.db.addtable mysoils layer=2 columns="left integer,right integer"
191       # upload categories of left and right areas:
192       v.to.db mysoils option=sides columns=left,right layer=2
193       # display the result:
194       v.db.select mysoils layer=2
195
196       Compute  DL,  the Fractal Dimension (Mandelbrot, 1982), of the boundary
197       defining a polygon based on the formula:
198       D = 2 * (log perimeter) / (log area):
199       g.copy vect=soils,mysoils
200       v.db.addcolumn mysoils col="d double precision"
201       v.to.db mysoils option=fd column="d"
202       g.region vector=mysoils res=50
203       v.to.rast input=mysoils output=soils_fd type=area use=attr attribute_column=d
204       r.colors map=soils_fd color=gyr
205       d.mon wx0
206       d.rast.leg soils_fd
207       d.vect mysoils type=boundary
208
209   Printing reports
210       Report x,y,z coordinates of points in the input vector map:
211       v.to.db -p bugsites option=coor type=point
212       Report all area sizes of the input vector map:
213       v.to.db -p soils option=area type=boundary units=h
214
215       Report all area sizes of the input vector map, in hectares,  sorted  by
216       category number (requires GNU sort utility installed):
217       v.to.db -p soils option=area type=boundary units=h | sort -n
218
219       Report all line lengths of the input vector map, in kilometers:
220       v.to.db -p roads option=length type=line units=k
221
222       Report number of features for each category in the input vector map:
223       v.to.db -p roads option=count type=line
224

SEE ALSO

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

REFERENCES

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

AUTHOR

236       Radim Blazek, ITC-irst, Trento, Italy
237       Line sinuousity implemented by Wolf Bergenheim
238
239       Last changed: $Date: 2017-01-29 15:04:26 +0100 (Sun, 29 Jan 2017) $
240

SOURCE CODE

242       Available at: v.to.db source code (history)
243
244       Main  index  | Vector index | Topics index | Keywords index | Graphical
245       index | Full index
246
247       © 2003-2019 GRASS Development Team, GRASS GIS 7.6.0 Reference Manual
248
249
250
251GRASS 7.6.0                                                         v.to.db(1)
Impressum