v.to.db.html 6.1 KB

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