v.db.update1grass
Updates a column in the attribute table connected to a vector map.
Usage
v.db.update
v.db.update --help
v.db.update map=name
layer=string
column=name
[value=string]
[query_column=name]
[where=sql_query]
[sqliteextra=name]
[--help]
[--verbose]
[--quiet]
[--ui]
Keywords
vector, attribute table, database, attribute update, type casting
Overview
v.db.update assigns a new value to a column in the attribute table connected to a given map. The value parameter allows updating with a literal value. Alternatively, with the qcol parameter values can be copied from another column in the table or be the result of a combination or transformation of other columns.
Notes
v.db.update is just a front-end to db.execute to allow easier usage.
For complex SQL UPDATE statements, db.execute should be used.
Examples
Replacing of NULL values
In this example, selectively display lakes without (blue) and with NULL (red) are shown to find out which type is undefined. In the original map there are lakes missing FTYPE attribute which are wetlands along streams. These NULL attributes are replaced with the landuse type WETLAND:
g.copy vect=lakes,mylakesv.db.select mylakesv.db.select mylakes where="FTYPE IS NULL"# display the lakes, show undefined FTYPE lakes in redg.region vector=mylakesd.mon wx0d.vect mylakes where="FTYPE NOT NULL" type=area col=blued.vect mylakes where="FTYPE IS NULL" type=area col=red# replace NULL with FTYPE WETLANDv.db.update mylakes col=FTYPE value=WETLAND \where="FTYPE IS NULL"v.db.select mylakes
Updating of columns with on the fly calculation
Spearfish example: adding new column, copying values from another table column with on the fly calculation:
g.copy vect=fields,myfieldsv.db.addcolumn myfields col="polynum integer"v.db.update myfields col=polynum qcol="cat*2"v.db.select myfields
Type casting
Type cast (type conversion) of strings to double precision (unsupported by DBF driver):
g.copy vect=geodetic_pts,mygeodetic_ptsv.db.update mygeodetic_pts col=zval qcol="CAST(z_value AS double precision)" \where="z_value <> ’N/A’"
Updating of columns with on the fly calculation (SQLite extended functions)
Note: this requires SQLite extended functions. For details see the GRASS GIS Wiki (compilation of libsqlitefunctions.so and libsqlitefunctions.dll).
North Carolina data set example: adding new column, copying values from another table column with on the fly calculation:
g.copy vect=precip_30ynormals,myprecip_30ynormalsv.db.addcolumn myprecip_30ynormals column="logjuly double precision"v.db.update myprecip_30ynormals column="logjuly" query_column="log(jul)" \sqliteextra=$HOME/sqlite_extensions/libsqlitefunctions.sov.db.select myprecip_30ynormals columns=jul,logjulyjul|logjuly132.842|4.88916045210132127|4.84418708645859124.206|4.82194147751127104.648|4.6506023373859398.298|4.58800368106618...
Source code
Available at: v.db.update source code (history)
Accessed: Monday Feb 24 17:51:45 2025
Main index | Vector index | Topics index | Keywords index | Graphical index | Full index
© 2003-2025 GRASS Development Team, GRASS GIS 8.4.1 Reference Manual
Releases
9 releases since Debian 5.0 (Lenny); the text changed 8 times.