v.to.db.html 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  1. <h2>DESCRIPTION</h2>
  2. <em>v.to.db</em> loads vector map features or metrics into a database
  3. table, or prints them (or the SQL queries used to obtain them) in a
  4. form of a human-readable report. For uploaded/printed category values
  5. '-1' is used for 'no category' and 'null'/'-' if category cannot be
  6. found or multiple categories were found. For line azimuths '-1' is used
  7. for closed lines (start equals end).
  8. <h2>NOTES</h2>
  9. Measures of lengths and areas are always reported in meters, unless the
  10. <em>unit</em> parameter is set.
  11. The units <em>miles</em>, <em>feet</em>, <em>meters</em> and
  12. <em>kilometers</em> are square for <em>option=area</em>.
  13. <p>Feet and acre units are always reported in their common versions
  14. (i.e. the International Foot, exactly 5280 feet in a mile), even
  15. when the location's standard map unit is the US Survey foot.
  16. <p>When calculating perimeters in Latitude-Longitude locations, the geodesic
  17. distance between the vertices is used.
  18. <p>When using <em>option=coor</em> on a vector area map,
  19. only coordinates of centroids with unique category will be reported.
  20. <p>Line azimuth is calculated as angle from the North direction to the line endnode
  21. direction at the line statnode. By default it's reported in decimal degrees (0-360, CW) but
  22. it also may be repored in radians with <em>unit=radians</em>. Azimuth value
  23. <b>-1</b> is used to report closed line with it's startnode and endnode being in
  24. same place. Azimuth values make sense only if every vector line has only one
  25. entry in database (unique CAT value).
  26. <p>If the module is apparently slow <em>and</em> the map attributes are
  27. stored in an external DBMS such as PostgreSQL, it is highly recommended
  28. to create an index on the key (category) column.
  29. <p>Uploading the vector map attributes to a database requires a table attached to
  30. a given input vector <em>layer</em>. The <b>print only</b> (<b>-p</b>) mode
  31. doesn't require a table. Use <em><a href="db.execute.html">db.execute</a></em>
  32. or <em><a href="v.db.addtable.html">v.db.addtable</a></em> to create a table if
  33. needed.
  34. <p>Updating the table has to be done column-wise. The <em>column</em> must be
  35. present in the table, except when using the <b>print only</b> (<b>-p</b>)
  36. mode. Use <em><a href="db.execute.html">db.execute</a></em> or
  37. <em><a href="v.db.addcolumn.html">v.db.addcolumn</a></em> to add new columns if
  38. needed.
  39. <h2>EXAMPLES</h2>
  40. <h3>Updating attribute tables</h3>
  41. Upload category numbers to attribute table (used for new map):<br>
  42. <div class="code"><pre>
  43. v.to.db map=soils type=centroid option=cat
  44. </pre></div>
  45. <p>Upload polygon areas to corresponding centroid record in the attribute table:<br>
  46. <div class="code"><pre>
  47. v.to.db map=soils type=centroid option=area columns=area_size unit=h
  48. </pre></div>
  49. <p>Upload line lengths (in meters) of each vector line to attribute table
  50. (use <em>v.category</em> in case of missing categories):<br>
  51. <div class="code"><pre>
  52. v.to.db map=roads option=length type=line columns=linelength units=me
  53. </pre></div>
  54. <p>Upload x and y coordinates from vector geometry to attribute table:<br>
  55. <div class="code"><pre>
  56. v.to.db map=pointsmap option=coor columns=x,y
  57. </pre></div>
  58. <p>Upload x, y and z coordinates from vector geometry to attribute table:<br>
  59. <div class="code"><pre>
  60. v.to.db map=pointsmap option=coor columns=x,y,z
  61. </pre></div>
  62. <p>Transfer attributes from a character column (with numeric contents) to a new
  63. integer column:<br>
  64. <div class="code"><pre>
  65. v.db.addcolumn usa_income_employment2002 col="FIPS_NUM integer"
  66. v.to.db usa_income_employment2002 option=query columns=FIPS_NUM query_column=STATE_FIPS
  67. </pre></div>
  68. <p>Upload category numbers of left and right area, to an attribute table of
  69. boundaries common for the areas:<br>
  70. <div class="code"><pre>
  71. # add categories for boundaries of the input vector map, in layer 2:
  72. v.category soils out=mysoils layer=2 type=boundary option=add
  73. # add a table with columns named "left" and "right" to layer 2 of the input
  74. # vector map:
  75. v.db.addtable mysoils layer=2 columns="left integer,right integer"
  76. # upload categories of left and right areas:
  77. v.to.db mysoils option=sides columns=left,right layer=2
  78. # display the result:
  79. v.db.select mysoils layer=2
  80. </pre></div>
  81. <p>Compute D<sub>L</sub>, the Fractal Dimension (Mandelbrot, 1982), of the
  82. boundary defining a polygon based on the formula:
  83. <br><tt>
  84. D = 2 * (log perimeter) / (log area):<br>
  85. </tt>
  86. <div class="code"><pre>
  87. g.copy vect=soils,mysoils
  88. v.db.addcolumn mysoils col="d double precision"
  89. v.to.db mysoils option=fd column="d"
  90. g.region vector=mysoils res=50
  91. v.to.rast input=mysoils output=soils_fd type=area use=attr attribute_column=d
  92. r.colors map=soils_fd color=gyr
  93. d.mon wx0
  94. d.rast.leg soils_fd
  95. d.vect mysoils type=boundary
  96. </pre></div>
  97. <h3>Printing reports</h3>
  98. Report x,y,z coordinates of points in the input vector map:<br>
  99. <div class="code"><pre>
  100. v.to.db -p bugsites option=coor type=point
  101. </pre></div>
  102. Report all area sizes of the input vector map:<br>
  103. <div class="code"><pre>
  104. v.to.db -p soils option=area type=boundary units=h
  105. </pre></div>
  106. <p>Report all area sizes of the input vector map, in hectares, sorted by category
  107. number (requires GNU <em>sort</em> utility installed):<br>
  108. <div class="code"><pre>
  109. v.to.db -p soils option=area type=boundary units=h | sort -n
  110. </pre></div>
  111. <p>Report all line lengths of the input vector map, in kilometers:<br>
  112. <div class="code"><pre>
  113. v.to.db -p roads option=length type=line units=k
  114. </pre></div>
  115. <p>Report number of features for each category in the input vector map:<br>
  116. <div class="code"><pre>
  117. v.to.db -p roads option=count type=line
  118. </pre></div>
  119. <h2>SEE ALSO</h2>
  120. <em>
  121. <a href="d.what.vect.html">d.what.vect</a>,
  122. <a href="db.execute.html">db.execute</a>,
  123. <a href="v.category.html">v.category</a>,
  124. <a href="v.db.addtable.html">v.db.addtable</a>,
  125. <a href="v.db.addcolumn.html">v.db.addcolumn</a>,
  126. <a href="v.db.connect.html">v.db.connect</a>,
  127. <a href="v.distance.html">v.distance</a>,
  128. <a href="v.report.html">v.report</a>,
  129. <a href="v.univar.html">v.univar</a>,
  130. <a href="v.what.html">v.what</a>
  131. </em>
  132. <h2>REFERENCES</h2>
  133. <ul>
  134. <li>Mandelbrot, B. B. (1982). The fractal geometry of nature. New York: W. H. Freeman.</li>
  135. <li>Xu, Y. F. &amp; Sun, D. A. (2005). Geotechnique 55, No. 9, 691-695</li>
  136. </ul>
  137. <h2>AUTHOR</h2>
  138. Radim Blazek, ITC-irst, Trento, Italy<br>
  139. Line sinuousity implemented by Wolf Bergenheim
  140. <p><i>Last changed: $Date$</i>