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