1v.to.db(1) Grass User's Manual v.to.db(1)
2
3
4
6 v.to.db - Populates attribute values from vector features.
7
9 vector, attribute table, database, area, azimuth, bounding box, cate‐
10 gory, compactness, coordinates, fractal, length, perimeter, sides, sin‐
11 uous, slope
12
14 v.to.db
15 v.to.db --help
16 v.to.db [-psc] map=name [layer=string] [type=string[,string,...]]
17 option=string columns=name[,name,...] [units=string]
18 [query_layer=string] [query_column=name] [separator=character]
19 [--help] [--verbose] [--quiet] [--ui]
20
21 Flags:
22 -p
23 Print only
24
25 -s
26 Only print SQL statements
27
28 -c
29 Print also totals for option length, area, or count
30
31 --help
32 Print usage summary
33
34 --verbose
35 Verbose module output
36
37 --quiet
38 Quiet module output
39
40 --ui
41 Force launching GUI dialog
42
43 Parameters:
44 map=name [required]
45 Name of vector map
46 Or data source for direct OGR access
47
48 layer=string
49 Layer number or name (write to)
50 Vector features can have category values in different layers. This
51 number determines which layer to use. When used with direct OGR
52 access this is the layer name.
53 Default: 1
54
55 type=string[,string,...]
56 Feature type
57 For coor valid point/centroid, for length valid line/boundary
58 Options: point, line, boundary, centroid
59 Default: point,line,boundary,centroid
60
61 option=string [required]
62 Value to upload
63 Options: cat, area, compact, fd, perimeter, length, count, coor,
64 start, end, sides, query, slope, sinuous, azimuth, bbox
65 cat: insert new row for each category if doesn’t exist yet
66 area: area size
67 compact: compactness of an area, calculated as
68 compactness = perimeter / (2 * sqrt(PI * area))
69 fd: fractal dimension of boundary defining a polygon, calculated as
70 fd = 2 * (log(perimeter) / log(area))
71 perimeter: perimeter length of an area
72 length: line length
73 count: number of features for each category
74 coor: point coordinates, X,Y or X,Y,Z
75 start: line/boundary starting point coordinates, X,Y or X,Y,Z
76 end: line/boundary end point coordinates, X,Y or X,Y,Z
77 sides: categories of areas on the left and right side of the bound‐
78 ary, ’query_layer’ is used for area category
79 query: result of a database query for all records of the geome‐
80 try(or geometries) from table specified by ’query_layer’ option
81 slope: slope steepness of vector line or boundary
82 sinuous: line sinuousity, calculated as line length / distance
83 between end points
84 azimuth: line azimuth, calculated as angle between North direction
85 and endnode direction at startnode
86 bbox: bounding box of area, N,S,E,W
87
88 columns=name[,name,...]Â [required]
89 Name of attribute column(s) to populate
90 Name of attribute column(s)
91
92 units=string
93 Units
94 Options: miles, feet, meters, kilometers, acres, hectares, radians,
95 degrees
96
97 query_layer=string
98 Query layer number or name (read from)
99 Vector features can have category values in different layers. This
100 number determines which layer to use. When used with direct OGR
101 access this is the layer name.
102 Default: 1
103
104 query_column=name
105 Name of attribute column used for ’query’ option
106 E.g. ’cat’, ’count(*)’, ’sum(val)’
107
108 separator=character
109 Field separator for print mode
110 Special characters: pipe, comma, space, tab, newline
111 Default: pipe
112
114 v.to.db loads vector map features or metrics into a database table, or
115 prints them (or the SQL queries used to obtain them) in a form of a
116 human-readable report. For uploaded/printed category values ’-1’ is
117 used for ’no category’ and ’null’/’-’ if category cannot be found or
118 multiple categories were found. For line azimuths ’-1’ is used for
119 closed lines (start equals end).
120
122 Measures of lengths and areas are always reported in meters, unless the
123 unit parameter is set. The units miles, feet, meters and kilometers
124 are square for option=area.
125
126 Feet and acre units are always reported in their common versions (i.e.
127 the International Foot, exactly 5280 feet in a mile), even when the
128 location’s standard map unit is the US Survey foot.
129
130 When calculating perimeters in Latitude-Longitude locations, the geo‐
131 desic distance between the vertices is used.
132
133 When using option=coor on a vector area map, only coordinates of cen‐
134 troids with unique category will be reported.
135
136 When using option=bbox on a vector area map with more than one feature
137 per category value, the results corresponds to the bounding box of all
138 features of same category taken together.
139
140 Line azimuth is calculated as angle from the North direction to the
141 line endnode direction at the line statnode. By default it’s reported
142 in decimal degrees (0-360, CW) but it also may be repored in radians
143 with unit=radians. Azimuth value -1 is used to report closed line with
144 it’s startnode and endnode being in same place. Azimuth values make
145 sense only if every vector line has only one entry in database (unique
146 CAT value).
147
148 If the module is apparently slow and the map attributes are stored in
149 an external DBMS such as PostgreSQL, it is highly recommended to create
150 an index on the key (category) column.
151
152 Uploading the vector map attributes to a database requires a table
153 attached to a given input vector layer. The print only (-p) mode
154 doesn’t require a table. Use db.execute or v.db.addtable to create a
155 table if needed.
156
157 Updating the table has to be done column-wise. The column must be
158 present in the table, except when using the print only (-p) mode. Use
159 db.execute or v.db.addcolumn to add new columns if needed.
160
162 Updating attribute tables
163 Upload category numbers to attribute table (used for new map):
164 v.to.db map=soils type=centroid option=cat
165
166 Upload polygon areas to corresponding centroid record in the attribute
167 table:
168 v.to.db map=soils type=centroid option=area columns=area_size unit=h
169
170 Upload line lengths (in meters) of each vector line to attribute table
171 (use v.category in case of missing categories):
172 v.to.db map=roads option=length type=line columns=linelength units=me
173
174 Upload x and y coordinates from vector geometry to attribute table:
175 v.to.db map=pointsmap option=coor columns=x,y
176
177 Upload x, y and z coordinates from vector geometry to attribute table:
178 v.to.db map=pointsmap option=coor columns=x,y,z
179
180 Transfer attributes from a character column (with numeric contents) to
181 a new integer column:
182 v.db.addcolumn usa_income_employment2002 col="FIPS_NUM integer"
183 v.to.db usa_income_employment2002 option=query columns=FIPS_NUM query_column=STATE_FIPS
184
185 Upload category numbers of left and right area, to an attribute table
186 of boundaries common for the areas:
187 # add categories for boundaries of the input vector map, in layer 2:
188 v.category soils out=mysoils layer=2 type=boundary option=add
189 # add a table with columns named "left" and "right" to layer 2 of the input
190 # vector map:
191 v.db.addtable mysoils layer=2 columns="left integer,right integer"
192 # upload categories of left and right areas:
193 v.to.db mysoils option=sides columns=left,right layer=2
194 # display the result:
195 v.db.select mysoils layer=2
196
197 Compute DL, the Fractal Dimension (Mandelbrot, 1982), of the boundary
198 defining a polygon based on the formula:
199 D = 2 * (log perimeter) / (log area):
200 g.copy vect=soils,mysoils
201 v.db.addcolumn mysoils col="d double precision"
202 v.to.db mysoils option=fd column="d"
203 g.region vector=mysoils res=50
204 v.to.rast input=mysoils output=soils_fd type=area use=attr attribute_column=d
205 r.colors map=soils_fd color=gyr
206 d.mon wx0
207 d.rast.leg soils_fd
208 d.vect mysoils type=boundary
209
210 Printing reports
211 Report x,y,z coordinates of points in the input vector map:
212 v.to.db -p bugsites option=coor type=point
213 Report all area sizes of the input vector map:
214 v.to.db -p soils option=area type=boundary units=h
215
216 Report all area sizes of the input vector map, in hectares, sorted by
217 category number (requires GNU sort utility installed):
218 v.to.db -p soils option=area type=boundary units=h | sort -n
219
220 Report all line lengths of the input vector map, in kilometers:
221 v.to.db -p roads option=length type=line units=k
222
223 Report number of features for each category in the input vector map:
224 v.to.db -p roads option=count type=line
225
227 d.what.vect, db.execute, v.category, v.db.addtable, v.db.addcolumn,
228 v.db.connect, v.distance, v.report, v.univar, v.what
229
231 · Mandelbrot, B. B. (1982). The fractal geometry of nature. New
232 York: W. H. Freeman.
233
234 · Xu, Y. F. & Sun, D. A. (2005). Geotechnique 55, No. 9, 691-695
235
237 Radim Blazek, ITC-irst, Trento, Italy
238 Line sinuousity implemented by Wolf Bergenheim
239
241 Available at: v.to.db source code (history)
242
243 Main index | Vector index | Topics index | Keywords index | Graphical
244 index | Full index
245
246 © 2003-2019 GRASS Development Team, GRASS GIS 7.8.2 Reference Manual
247
248
249
250GRASS 7.8.2 v.to.db(1)