v.in.ascii.html 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318
  1. <h2>DESCRIPTION</h2>
  2. <em>v.in.ascii</em> converts a vector map
  3. in <a href="vectorascii.html">GRASS ASCII vector format</a> to a
  4. vector map in binary format. The module may import two formats:
  5. <ul>
  6. <li><b>standard</b> contains all data types, each coordinate on one row</li>
  7. <li><b>point</b> (default) reads only points, each point defined on
  8. one row. Values are separated by a user-definable delimiter. If
  9. the <b>columns</b> option is not defined, default names are used. It
  10. is possible to specify the column order for the x,y,z coordinates
  11. and category values.</li>
  12. </ul>
  13. <p><em><a href="v.out.ascii.html">v.out.ascii</a></em> performs the
  14. function of <em>v.in.ascii</em> in reverse; i.e., it converts vector
  15. maps in binary format to GRASS ASCII vector format. These two companion programs
  16. are useful both for importing and exporting vector maps between GRASS
  17. and other software, and for transferring data between machines.
  18. <h2>NOTES</h2>
  19. The input is read from the file specified by the <b>input</b> option or
  20. from standard input.
  21. <p>The field separator may be a character, the word '<tt>tab</tt>'
  22. (or '<tt>\t</tt>') for tab, '<tt>space</tt>' (or '&nbsp;') for a blank,
  23. or '<tt>comma</tt>' (or ',') for a comma.
  24. <p>An attribute table is only created if it is needed, i.e. when at
  25. least one attribute column is present in the input file besides
  26. geometry columns. The attribute column will be auto-scanned for type, but
  27. may be explicitly declared along with the geometry columns using the
  28. <b>columns</b> parameter.
  29. <p>Use the <b>-z</b> flag to convert ASCII data into a 3D vector map.
  30. <p>In special cases of data import, such as the import of large LIDAR
  31. datasets (millions of data points), it may be necessary to disable
  32. topology support (vector level 1) due to memory constraints. This is
  33. done with the <b>-b</b> flag. As only very few vector modules support
  34. points data processing at vector level 1, usually topology is required
  35. (vector level 2). Therefore it is recommended that the user first try
  36. to import the data without creating a database (the <b>-t</b> flag) or
  37. within a subregion (the <b>-r</b> flag) before resorting to the
  38. disabling of topology.
  39. <p>If old version is requested, the <b>output</b> files
  40. from <em><a href="v.out.ascii.html">v.out.ascii</a></em> is placed in
  41. the <tt>$LOCATION/$MAPSET/dig_ascii/</tt>
  42. and <tt>$LOCATION/$MAPSET/dig_att</tt> directory.
  43. <h3>Import of files without category column</h3>
  44. If the input file does not contain a category column, there is the
  45. possibility to auto-generate these IDs (categories). To automatically
  46. add an additional column named 'cat', the <b>cat</b> parameter must be
  47. set to the virtual column number 0 (<tt>cat=0</tt>). This is the
  48. default action if the <b>cat</b> parameter is not set.
  49. <h3>Importing from a spreadsheet</h3>
  50. Data may be imported from many spreadsheet programs by saving the
  51. spreadsheet as a comma separated variable (.csv) text file, and then
  52. using the <b>separator=','</b> or <b>separator=comma</b> option
  53. with <em>v.in.ascii</em> in <b>points</b> mode. If the input file
  54. contains any header lines, such as column headings, the
  55. <b>skip</b> parameter should be used. These skipped header lines will
  56. be written to the map's history file for later reference (read with
  57. <tt>v.info&nbsp;-h</tt>). The skip option only works in <b>points</b> mode.
  58. <p>Any line starting with the hash character ('<tt>#</tt>') will be treated as
  59. a comment and skipped completely if located in the main data file. If located
  60. in the header, as defined by the <b>skip</b> parameter, it will be treated as
  61. a header line and written to the history file.
  62. <h3>Import of sexagesimal degree (degree, minutes, seconds, DMS)</h3>
  63. The import of DMS formatted degrees is supported (in this case no sign
  64. but N/S, E/W characters are used to indicate the hemispheres). While
  65. the positions are internally translated into decimal degrees during
  66. the import, the original DMS values are maintained in the attribute
  67. table. This requires both the latitude and the longitude columns to be
  68. defined as <tt>varchar()</tt>, not as numbers. A warning will be
  69. issued which can be ignored. See <a href="vectorascii.html">GRASS
  70. ASCII vector format specification</a> for details.
  71. <h3>Importing only selected columns</h3>
  72. Although <em>v.in.ascii</em> doesn't have an option to specify which columns
  73. should be imported, you can use a shell filter to achieve the same effect,
  74. e.g.:
  75. <div class="code"><pre>
  76. # Print out the column number for each field, supposing the file has a header
  77. head -1 input_file | tr '&lt;the_field_separator_character&gt;' '\n' | cat -n
  78. # From the listing, select the columns you want and feed them to v.in.ascii
  79. # use input=- to read from stdin
  80. cut -d&lt;the_field_separator_character&gt; -f&lt;comma-separated_list_of_columns&gt; input_file | v.in.ascii in=- &lt;your_options&gt;
  81. </pre></div>
  82. <h2>EXAMPLES</h2>
  83. <h3>Example 1a) - standard format mode</h3>
  84. Sample ASCII polygon vector map for 'standard' format mode.
  85. The two areas will be assigned categories 20 and 21. For details on the structure of
  86. standard format data files see the second reference at the bottom of this page.
  87. <p><div class="code"><pre>
  88. echo "ORGANIZATION: GRASS Development Team
  89. DIGIT DATE: 1/9/2005
  90. DIGIT NAME: -
  91. MAP NAME: test
  92. MAP DATE: 2005
  93. MAP SCALE: 10000
  94. OTHER INFO: Test polygons
  95. ZONE: 0
  96. MAP THRESH: 0.500000
  97. VERTI:
  98. B 6
  99. 5958812.48844435 3400828.84221011
  100. 5958957.29887089 3400877.11235229
  101. 5959021.65906046 3400930.7458436
  102. 5959048.47580612 3400973.65263665
  103. 5959069.92920264 3401032.64947709
  104. 5958812.48844435 3400828.84221011
  105. C 1 1
  106. 5958952.42189184 3400918.23126419
  107. 1 20
  108. B 4
  109. 5959010.9323622 3401338.36037757
  110. 5959096.7459483 3401370.54047235
  111. 5959091.38259917 3401450.99070932
  112. 5959010.9323622 3401338.36037757
  113. C 1 1
  114. 5959063.08352122 3401386.98533277
  115. 1 21" | v.in.ascii in=- format=standard output=test_polygons
  116. </pre></div>
  117. <h3>Example 1b) - standard format mode</h3>
  118. Sample ASCII 3D line vector map for 'standard' format mode with simplified input
  119. (note the space field separator).
  120. Note the <b>-z</b> flag indicating 3D vector input, and the <b>-n</b> flag
  121. indicating no vector header should be expected from the input file.
  122. <div class="code"><pre>
  123. echo "L 5 1
  124. 591336 4927369 1224
  125. 594317 4925341 1292
  126. 599356 4925162 1469
  127. 602396 4926653 1235
  128. 607524 4925431 1216
  129. 1 321 " | v.in.ascii -zn in=- out=line3d format=standard
  130. </pre></div>
  131. This can be used to create a vector line of a GPS track: the GPS points have
  132. to be stored into a file with a preceding 'L' and the number of points (per line).
  133. <h3>Example 2 - point format mode</h3>
  134. Generate a 2D points vector map 'coords.txt' as ASCII file:
  135. <div class="code"><pre>
  136. 1664619|5103481
  137. 1664473|5095782
  138. 1664273|5101919
  139. 1663427|5105234
  140. 1663709|5102614
  141. </pre></div>
  142. <p>Import into GRASS:
  143. <div class="code"><pre>
  144. v.in.ascii input=coords.txt output=mymap
  145. </pre></div>
  146. As the <b>cat</b> option is set to 0 by default, an extra column 'cat'
  147. containing the category numbers will be auto-generated.
  148. <h3>Example 3 - point format mode</h3>
  149. Generate a 2D points vector map 'points.dat' as ASCII file:
  150. <div class="code"><pre>
  151. 1|1664619|5103481|studna
  152. 2|1664473|5095782|kadibudka
  153. 3|1664273|5101919|hruska
  154. 4|1663427|5105234|mysi dira
  155. 5|1663709|5102614|mineralni pramen
  156. </pre></div>
  157. <p>Import into GRASS:
  158. <div class="code"><pre>
  159. cat points.dat | v.in.ascii in=- out=mypoints x=2 y=3 cat=1 \
  160. columns='cat int, x double precision, y double precision, label varchar(20)'
  161. </pre></div>
  162. <p>The module is reading from standard input, using the default '|' (pipe) delimiter.
  163. <h3>Example 4 - point format mode - CSV table</h3>
  164. Import of a 3D points CSV table ('points3d.csv') with attributes:
  165. <div class="code"><pre>
  166. "num","X","Y","Z","T"
  167. 1,2487491.643,5112118.33,120.5,18.62
  168. 2,2481985.459,5109162.78,123.9,18.46
  169. 3,2478284.289,5105331.04,98.3,19.61
  170. </pre></div>
  171. <p>Import into GRASS:
  172. <div class="code"><pre>
  173. # import: skipping the header line, categories generated automatically,
  174. # column names defined with type:
  175. v.in.ascii -z in=points3d.csv out=mypoints3D separator=comma \
  176. columns="num integer, x double precision, y double precision, z double precision, temp double precision" \
  177. x=2 y=3 z=4 skip=1
  178. # verify column types
  179. v.info -c mypoints3D
  180. # verify table content
  181. v.db.select mypoints3D
  182. </pre></div>
  183. <h3>Example 5 - point format mode</h3>
  184. Generating a 3D points vector map from DBMS (idcol must be an integer column):<br>
  185. <div class="code"><pre>
  186. echo "select east,north,elev,idcol from mytable" | db.select -c | v.in.ascii in=- -z out=mymap
  187. </pre></div>
  188. With <b>in=-</b>, the module is reading from standard input, using the default '|' (pipe) delimiter.
  189. <br>
  190. The import works for 2D maps as well (no elev column and no '-z' flag).
  191. <h3>Example 6 - point format mode</h3>
  192. Generate a 3D points vector map 'points3d.dat' with attributes as ASCII file:
  193. <div class="code"><pre>
  194. 593493.1|4914730.2|123.1|studna|well
  195. 591950.2|4923000.5|222.3|kadibudka|outhouse
  196. 589860.5|4922000.0|232.3|hruska|pear
  197. 590400.5|4922820.8|143.2|mysi dira|mouse hole
  198. 593549.3|4925500.7|442.6|mineralni pramen|mineral spring
  199. 600375.7|4925235.6|342.2|kozi stezka|goat path
  200. </pre></div>
  201. <p>Import into GRASS:
  202. <div class="code"><pre>
  203. #As the 'cat' option is set to 0 by default, an extra column 'cat'
  204. #containing the IDs will be auto-generated (no need to define that):
  205. cat points3d.dat | v.in.ascii in=- -z z=3 cat=0 out=mypoints3D \
  206. columns='x double precision, y double precision, z double precision, \
  207. label_cz varchar(20), label_en varchar(20)'
  208. v.info -c mypoints3D
  209. v.info mypoints3D
  210. </pre></div>
  211. <h3>Example 7 - point format mode</h3>
  212. Generate points file by clicking onto the map:
  213. <div class="code"><pre>
  214. #For LatLong locations:
  215. d.where -d -l | awk '{printf "%f|%f|point\n", $1, $2}' | v.in.ascii in=- out=points \
  216. columns='x double precision, y double precision, label varchar(20)'
  217. #For other projections:
  218. d.where | awk '{printf "%f|%f|point\n", $1, $2}' | v.in.ascii in=- out=points \
  219. columns='x double precision, y double precision, label varchar(20)'
  220. </pre></div>
  221. The 'point' string (or some similar entry) is required to generate a database table.
  222. When simply piping the coordinates (and optionally height) without additional column(s)
  223. into <em>v.in.ascii</em>, only the vector map geometry will be generated.
  224. <h3>Example 8 - point format mode</h3>
  225. Convert ground control points into vector points:
  226. <div class="code"><pre>
  227. cat $MAPSET/group/$GROUP/POINTS | v.in.ascii in=- out=$GROUP_gcp separator=space skip=3 \
  228. col='x double precision, y double precision, x_target double precision, \
  229. y_target double precision, ok int'
  230. </pre></div>
  231. <h2>REFERENCES</h2>
  232. <a href="sql.html">SQL command notes</a> for creating databases
  233. <br>
  234. <a href="vectorascii.html">GRASS ASCII vector format</a> specification
  235. <h2>SEE ALSO</h2>
  236. <em>
  237. <a href="db.execute.html">db.execute</a>,
  238. <a href="r.in.ascii.html">r.in.ascii</a>,
  239. <a href="r.in.poly.html">r.in.poly</a>,
  240. <a href="r.in.xyz.html">r.in.xyz</a>,
  241. <a href="v.build.html">v.build</a>,
  242. <a href="v.build.polylines.html">v.build.polylines</a>,
  243. <a href="v.centroids.html">v.centroids</a>,
  244. <a href="v.clean.html">v.clean</a>,
  245. <a href="v.db.connect.html">v.db.connect</a>,
  246. <a href="v.import.html">v.import</a>,
  247. <a href="v.info.html">v.info</a>,
  248. <a href="v.in.lines.html">v.in.lines</a>,
  249. <a href="v.in.mapgen.html">v.in.mapgen</a>,
  250. <a href="v.out.ascii.html">v.out.ascii</a>
  251. </em>
  252. <h2>AUTHORS</h2>
  253. Michael Higgins,
  254. U.S.Army Construction Engineering
  255. Research Laboratory<br>
  256. James Westervelt, U.S.Army Construction Engineering
  257. Research Laboratory<br>
  258. Radim Blazek, ITC-Irst, Trento, Italy
  259. <!--
  260. <p>
  261. <i>Last changed: $Date$</i>
  262. -->