1v.db.update(1) Grass User's Manual v.db.update(1)
2
3
4
6 v.db.update - Updates a column in the attribute table connected to a
7 vector map.
8
10 vector, attribute table, database
11
13 v.db.update
14 v.db.update --help
15 v.db.update map=name layer=string column=name [value=string]
16 [query_column=name] [where=sql_query] [sqliteextra=name] [--help]
17 [--verbose] [--quiet] [--ui]
18
19 Flags:
20 --help
21 Print usage summary
22
23 --verbose
24 Verbose module output
25
26 --quiet
27 Quiet module output
28
29 --ui
30 Force launching GUI dialog
31
32 Parameters:
33 map=name [required]
34 Name of vector map
35 Or data source for direct OGR access
36
37 layer=string [required]
38 Layer number or name
39 Vector features can have category values in different layers. This
40 number determines which layer to use. When used with direct OGR
41 access this is the layer name.
42 Default: 1
43
44 column=name [required]
45 Name of attribute column to update
46
47 value=string
48 Literal value to update the column with
49
50 query_column=name
51 Name of other attribute column to query, can be combination of col‐
52 umns (e.g. co1+col2)
53
54 where=sql_query
55 WHERE conditions of SQL statement without ’where’ keyword
56 Example: income < 1000 and population >= 10000
57
58 sqliteextra=name
59 Name of SQLite extension file for extra functions (SQLite backend
60 only)
61
63 v.db.update assigns a new value to a column in the attribute table con‐
64 nected to a given map. The value parameter allows updating with a lit‐
65 eral value. Alternatively, with the qcol parameter values can be copied
66 from another column in the table or be the result of a combination or
67 transformation of other columns.
68
70 v.db.update is just a front-end to db.execute to allow easier usage.
71
72 For complex SQL UPDATE statements, db.execute should be used.
73
75 Replacing of NULL values
76 In this example, selectively display lakes without (blue) and with NULL
77 (red) are shown to find out which type is undefined. In the original
78 map there are lakes missing FTYPE attribute which are wetlands along
79 streams. These NULL attributes are replaced with the landuse type WET‐
80 LAND:
81 g.copy vect=lakes,mylakes
82 v.db.select mylakes
83 v.db.select mylakes where="FTYPE IS NULL"
84 # display the lakes, show undefined FTYPE lakes in red
85 g.region vector=mylakes
86 d.mon wx0
87 d.vect mylakes where="FTYPE NOT NULL" type=area col=blue
88 d.vect mylakes where="FTYPE IS NULL" type=area col=red
89 # replace NULL with FTYPE WETLAND
90 v.db.update mylakes col=FTYPE value=WETLAND \
91 where="FTYPE IS NULL"
92 v.db.select mylakes
93
94 Updating of columns with on the fly calculation
95 Spearfish example: adding new column, copying values from another table
96 column with on the fly calculation:
97 g.copy vect=fields,myfields
98 v.db.addcolumn myfields col="polynum integer"
99 v.db.update myfields col=polynum qcol="cat*2"
100 v.db.select myfields
101
102 Type casting
103 Type cast (type conversion) of strings to double precision (unsupported
104 by DBF driver):
105 g.copy vect=geodetic_pts,mygeodetic_pts
106 v.db.update mygeodetic_pts col=zval qcol="CAST(z_value AS double precision)" \
107 where="z_value <> ’N/A’"
108
109 Updating of columns with on the fly calculation (SQLite extended functions)
110 Note: this requires SQLite extended functions. For details see the
111 GRASS GIS Wiki (compilation of libsqlitefunctions.so and libsqlitefunc‐
112 tions.dll).
113
114 North Carolina data set example: adding new column, copying values from
115 another table column with on the fly calculation:
116 g.copy vect=precip_30ynormals,myprecip_30ynormals
117 v.db.addcolumn myprecip_30ynormals column="logjuly double precision"
118 v.db.update myprecip_30ynormals column="logjuly" query_column="log(jul)" \
119 sqliteextra=$HOME/sqlite_extensions/libsqlitefunctions.so
120 v.db.select myprecip_30ynormals columns=jul,logjuly
121 jul|logjuly
122 132.842|4.88916045210132
123 127|4.84418708645859
124 124.206|4.82194147751127
125 104.648|4.65060233738593
126 98.298|4.58800368106618
127 ...
128
130 db.execute, v.db.addcolumn, v.db.addtable, v.db.connect, v.db.dropt‐
131 able, v.db.join, v.db.select
132 GRASS SQL interface
133
135 Moritz Lennert (mlennert@club.worldonline.be)
136
137 Last changed: $Date: 2017-03-12 11:58:07 +0100 (Sun, 12 Mar 2017) $
138
140 Available at: v.db.update source code (history)
141
142 Main index | Vector index | Topics index | Keywords index | Graphical
143 index | Full index
144
145 © 2003-2019 GRASS Development Team, GRASS GIS 7.6.0 Reference Manual
146
147
148
149GRASS 7.6.0 v.db.update(1)