v.db.join.html 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. <h2>DESCRIPTION</h2>
  2. <em>v.db.join</em> joins the content of another table into the connected
  3. attribute table of a vector map.
  4. <h2>NOTES</h2>
  5. <em>v.db.join</em> is a front-end to <em>db.execute</em> to allow easier usage.
  6. The vector attribute table must be stored in a SQL database (SQLite, PostgreSQL,
  7. MySQL, ODBC, ...). The DBF backend is not supported. Tables can be
  8. imported with <em>db.in.ogr</em>.
  9. <p>The vector map-database connection(s) can be verified with <em>v.db.connect</em>.
  10. <h2>EXAMPLES</h2>
  11. Exercise to join North Carolina geological classes from a CSV table to
  12. the "geology" map of the North Carolina sample dataset (requires download
  13. of legend CSV file <a href="http://www.grassbook.org/wp-content/uploads/ncexternal/nc_geology.csv">nc_geology.csv</a>
  14. from <a href="http://www.grassbook.org/wp-content/uploads/ncexternal/index.html">External data for NC sample dataset</a>):
  15. <div class="code"><pre>
  16. # check original map attributes
  17. v.db.select geology column=GEO_NAME,SHAPE_area
  18. # import of CSV table
  19. db.in.ogr input=nc_geology.csv output=nc_geology
  20. # work on copy of geology map in current mapset
  21. g.copy vector=geology,mygeology
  22. # check column names of vector map attributes
  23. v.info -c mygeology
  24. # check column names of legend table
  25. db.describe -c nc_geology
  26. # join table using key columns (map: "GEO_NAME"; table: "geol_id")
  27. v.db.join map=mygeology column=GEO_NAME other_table=nc_geology other_column=geol_id
  28. # verify result (here abbreviated)
  29. v.db.select mygeology | head -3
  30. cat|onemap_pro|PERIMETER|GEOL250_|GEOL250_ID|GEO_NAME|SHAPE_area|SHAPE_len|geol_id|longname|comment
  31. 1|963738.75|4083.97998|2|1|Zml|963738.608571|4083.979839|Zml|Metagraywacke|Interlayered with metaconglomerate, ...
  32. 2|22189124|26628.261719|3|2|Zmf|22189123.2296|26628.261112|Zmf|Metafelsite|Light-colored porphyritic extrusive rock
  33. ...
  34. </pre></div>
  35. <h3>Soil map table join</h3>
  36. Joining the soil type explanations from table <em>soils_legend</em>
  37. into the Spearfish soils map (<a href="http://www.grassbook.org/code-examples/code-examples-1st-edition/">download legend</a>):
  38. <div class="code"><pre>
  39. g.copy vect=soils,mysoils
  40. # import legend table
  41. db.in.ogr soils_legend.csv out=soils_legend
  42. # get join column names
  43. v.info -c mysoils
  44. db.describe -c soils_legend
  45. # look at original table
  46. v.db.select mysoils
  47. cat|label
  48. 1|Aab
  49. 2|Ba
  50. 3|Bb
  51. 4|BcB
  52. 5|BcC
  53. ...
  54. # look at legend
  55. db.select table=soils_legend
  56. db.select table=soils_legend | head -7
  57. id|shortname|longname
  58. 0|no data|no data
  59. 0|AaB|Alice fine sandy loam, 0 to 6
  60. 0|Ba|Barnum silt loam
  61. 0|Bb|Barnum silt loam, channeled
  62. 0|BcB|Boneek silt loam, 2 to 6
  63. 0|BcC|Boneek silt loam, 6 to 9
  64. ...
  65. # join soils_legend into mysoils attribute table
  66. v.db.join mysoils col=label other_table=soils_legend ocol=shortname
  67. # verification of join
  68. v.db.select mysoils
  69. cat|label|id|shortname|longname
  70. 1|Aab|||
  71. 2|Ba|2|Ba|Barnum silt loam
  72. 3|Bb|3|Bb|Barnum silt loam, channeled
  73. 4|BcB|4|BcB|Boneek silt loam, 2 to 6
  74. 5|BcC|5|BcC|Boneek silt loam, 6 to 9
  75. ...
  76. </pre></div>
  77. <h2>SEE ALSO</h2>
  78. <em>
  79. <a href="db.execute.html">db.execute</a>,
  80. <a href="db.in.ogr.html">db.in.ogr</a>,
  81. <a href="db.select.html">db.select</a>,
  82. <a href="v.db.update.html">v.db.update</a><br>
  83. <a href="sql.html">GRASS SQL interface</a>
  84. </em>
  85. <h2>AUTHOR</h2>
  86. Markus Neteler
  87. <p><i>Last changed: $Date$</i>