1v.to.db(1) Grass User's Manual v.to.db(1)
2
3
4
6 v.to.db - Populate database values from vector features.
7 Load values from vector to database. For uploaded/printed category val‐
8 ues '-1' is used for 'no category' and 'null'/'-' if category cannot be
9 found or multiple categories were found.
10
12 vector, database, attribute table
13
15 v.to.db
16 v.to.db help
17 v.to.db [-psc] map=name [type=string[,string,...]] [layer=integer]
18 [qlayer=integer] option=string [units=string] [col‐
19 umn=string[,string,...]] [qcolumn=string] [--verbose] [--quiet]
20
21 Flags:
22 -p
23 Print only
24
25 -s
26 Only print sql statements
27
28 -c
29 In print mode prints totals for options: length,area,count
30
31 --verbose
32 Verbose module output
33
34 --quiet
35 Quiet module output
36
37 Parameters:
38 map=name
39 Name of input vector map
40
41 type=string[,string,...]
42 Type
43 Type of elements (for coor valid point/centroid, for length valid
44 line/boundary)
45 Options: point,line,boundary,centroid
46 Default: point,line,boundary,centroid
47
48 layer=integer
49 Layer number
50 A single vector map can be connected to multiple database tables.
51 This number determines which table to use.
52 Default: 1
53
54 qlayer=integer
55 Layer number
56 Query layer. Used by 'query' option.
57 Default: 1
58
59 option=string
60 Value to upload
61 Options: cat,area,compact,perime‐
62 ter,length,count,coor,start,end,sides,query,slope
63 cat: insert new row for each category if doesn't exist yet
64 area: area size
65 compact: compactness of an area, calculated as compactness =
66 perimeter / (2 * sqrt(PI * area))
67 perimeter: perimeter length of an area
68 length: line length
69 count: number of features for each category
70 coor: point coordinates, X,Y or X,Y,Z
71 start: line/boundary starting point coordinates, X,Y or X,Y,Z
72 end: line/boundary end point coordinates, X,Y or X,Y,Z
73 sides: categories of areas on the left and right side of the bound‐
74 ary, 'qlayer' is used for area category
75 query: result of a database query for all records of the geome‐
76 try(or geometries) from table specified by 'qlayer' option
77 slope: slope steepness of vector line or boundary
78
79 units=string
80 Units
81 mi(les),f(eet),me(ters),k(ilometers),a(cres),h(ectares)
82 Options: mi,miles,f,feet,me,meters,k,kilometers,a,acres,h,hectares
83
84 column=string[,string,...]
85 Column(s)
86
87 qcolumn=string
88 Query column used for 'query' option
89 E.g. 'cat', 'count(*)', 'sum(val)'
90
92 v.to.db loads vector map features or metrics into a database table, or
93 prints them (or the SQL queries used to obtain them) in a form of a
94 human-readable report.
95
97 The units miles, feet, meters and kilometers are square for
98 option=area.
99
100 Feet and acre units are always reported in their common versions (i.e.
101 the International Foot, exactly 5280 feet in a mile), even when the
102 location's standard map unit is the US Survey foot.
103
104 When calculating perimeters in Latitude-Longitude locations, the geo‐
105 desic distance between the vertices is used.
106
107 When using option=coor on a vector area map, only coordinates of cen‐
108 troids with unique category will be reported.
109
110 If the module is apparently slow and the map attributes are stored in
111 an external DBMS such as PostgreSQL, it is highly recommended to create
112 an index on the key (category) column.
113
114 Uploading the vector map attributes to a database requires a table
115 attached to a given input vector layer. The print only (-p) mode
116 doesn't require a table. Use db.execute or v.db.addtable to create a
117 table if needed.
118
119 Updating the table has to be done column-wise. The column must be
120 present in the table, except when using the print only (-p) mode. Use
121 db.execute or v.db.addcol to add new columns if needed.
122
124 Updating attribute tables
125 Upload category numbers to attribute table (used for new map):
126
127 v.to.db map=soils type=area option=cat
128
129
130 Upload area sizes of each polygon to attribute table:
131
132 v.to.db map=soils type=area option=area col=area_size unit=h
133
134
135 Upload line lengths (in meters) of each vector line to attribute table
136 (use v.category in case of missing categories):
137
138 v.to.db map=roads option=length type=line col=linelength units=me
139
140
141 Upload x and y coordinates from vector geometry to attribute table:
142
143 v.to.db map=pointsmap option=coor col=x,y
144
145
146 Upload x, y and z coordinates from vector geometry to attribute table:
147
148 v.to.db map=pointsmap option=coor col=x,y,z
149
150
151 Transfer attributes from a character column (with numeric contents) to
152 a new integer column:
153
154 v.db.addcol usa_income_employment2002 col="FIPS_NUM integer"
155 v.to.db usa_income_employment2002 option=query col=FIPS_NUM
156 qcol=STATE_FIPS
157
158
159 Upload category numbers of left and right area, to an attribute table
160 of boundaries common for the areas:
161
162 # add categories for boundaries of the input vector map, in layer 2:
163 v.category soils out=mysoils layer=2 type=boundary option=add
164 # add a table with columns named "left" and "right" to layer 2 of the
165 input
166 # vector map:
167 v.db.addtable mysoils layer=2 col="left integer,right integer"
168 # upload categories of left and right areas:
169 v.to.db mysoils option=sides col=left,right layer=2
170 # display the result:
171 v.db.select mysoils layer=2
172
173
174 Printing reports
175 Report x,y,z coordinates of points in the input vector map:
176
177 v.to.db -p bugsites option=coor type=point
178 Report all area sizes of the input vector map:
179
180 v.to.db -p soils option=area type=boundary units=h
181
182
183 Report all area sizes of the input vector map, in hectares, sorted by
184 category number (requires GNU sort utility installed):
185
186 v.to.db -p soils option=area type=boundary units=h | sort -n
187
188
189 Report all line lengths of the input vector map, in kilometers:
190
191 v.to.db -p roads option=length type=line units=k
192
193
194 Report number of features for each category in the input vector map:
195
196 v.to.db -p roads option=count type=line
197
198
200 d.what.vect, db.execute, v.category, v.db.connect, v.db.addtable,
201 v.db.addcol, v.db.connect, v.distance, v.report, v.univar, v.what
202
204 Radim Blazek
205
206 Last changed: $Date: 2007-11-20 10:34:59 +0100 (Tue, 20 Nov 2007) $
207
208 Full index
209
210 © 2003-2008 GRASS Development Team
211
212
213
214GRASS 6.3.0 v.to.db(1)