v.db.update.html 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. <h2>DESCRIPTION</h2>
  2. <em>v.db.update</em> assigns a new value to a column in the
  3. attribute table connected to a given map. The <em>value</em> parameter allows updating with a literal value. Alternatively, with the <em>qcol</em> parameter values can be
  4. copied from another column in the table or be the result of a combination or transformation of other columns.
  5. <h2>NOTES</h2>
  6. <em>v.db.update</em> is just a front-end to <em>db.execute</em> to
  7. allow easier usage.
  8. <p>For complex SQL UPDATE statements, <em>db.execute</em> should be used.
  9. <h2>EXAMPLES</h2>
  10. <h3>Replacing of NULL values</h3>
  11. In this example, selectively display lakes without (blue) and with
  12. NULL (red) are shown to find out which type is undefined. In the
  13. original map there are lakes missing FTYPE attribute which are
  14. wetlands along streams. These NULL attributes are replaced with the
  15. landuse type WETLAND:
  16. <div class="code"><pre>
  17. g.copy vect=lakes,mylakes
  18. v.db.select mylakes
  19. v.db.select mylakes where="FTYPE IS NULL"
  20. # display the lakes, show undefined FTYPE lakes in red
  21. g.region vector=mylakes
  22. d.mon wx0
  23. d.vect mylakes where="FTYPE NOT NULL" type=area col=blue
  24. d.vect mylakes where="FTYPE IS NULL" type=area col=red
  25. # replace NULL with FTYPE WETLAND
  26. v.db.update mylakes col=FTYPE value=WETLAND \
  27. where="FTYPE IS NULL"
  28. v.db.select mylakes
  29. </pre></div>
  30. <h3>Updating of columns with on the fly calculation</h3>
  31. Spearfish example: adding new column, copying values from another table
  32. column with on the fly calculation:
  33. <div class="code"><pre>
  34. g.copy vect=fields,myfields
  35. v.db.addcolumn myfields col="polynum integer"
  36. v.db.update myfields col=polynum qcol="cat*2"
  37. v.db.select myfields
  38. </pre></div>
  39. <h3>Type casting</h3>
  40. Type cast (type conversion) of strings to double precision
  41. (unsupported by DBF driver):
  42. <div class="code"><pre>
  43. g.copy vect=geodetic_pts,mygeodetic_pts
  44. v.db.update mygeodetic_pts col=zval qcol="CAST(z_value AS double precision)" \
  45. where="z_value &lt;&gt; 'N/A'"
  46. </pre></div>
  47. <h3>Updating of columns with on the fly calculation (SQLite extended functions)</h3>
  48. Note: this requires SQLite extended functions. For details see the GRASS GIS Wiki
  49. (compilation of <a href="https://grasswiki.osgeo.org/wiki/Build_SQLite_extension_on_Linux">libsqlitefunctions.so</a>
  50. and <a href="https://grasswiki.osgeo.org/wiki/Build_SQLite_extension_on_windows">libsqlitefunctions.dll</a>).
  51. <p>
  52. North Carolina data set example: adding new column, copying values from
  53. another table column with on the fly calculation:
  54. <div class="code"><pre>
  55. g.copy vect=precip_30ynormals,myprecip_30ynormals
  56. v.db.addcolumn myprecip_30ynormals column="logjuly double precision"
  57. v.db.update myprecip_30ynormals column="logjuly" query_column="log(jul)" \
  58. sqliteextra=$HOME/sqlite_extensions/libsqlitefunctions.so
  59. v.db.select myprecip_30ynormals columns=jul,logjuly
  60. jul|logjuly
  61. 132.842|4.88916045210132
  62. 127|4.84418708645859
  63. 124.206|4.82194147751127
  64. 104.648|4.65060233738593
  65. 98.298|4.58800368106618
  66. ...
  67. </pre></div>
  68. <h2>SEE ALSO</h2>
  69. <em>
  70. <a href="db.execute.html">db.execute</a>,
  71. <a href="v.db.addcolumn.html">v.db.addcolumn</a>,
  72. <a href="v.db.addtable.html">v.db.addtable</a>,
  73. <a href="v.db.connect.html">v.db.connect</a>,
  74. <a href="v.db.droptable.html">v.db.droptable</a>,
  75. <a href="v.db.join.html">v.db.join</a>,
  76. <a href="v.db.select.html">v.db.select</a><br>
  77. <a href="sql.html">GRASS SQL interface</a>
  78. </em>
  79. <h2>AUTHOR</h2>
  80. Moritz Lennert (mlennert@club.worldonline.be)
  81. <p>
  82. <i>Last changed: $Date$</i>