v.in.ascii.html 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388
  1. <h2>DESCRIPTION</h2>
  2. <em>v.in.ascii</em> converts a vector map in ASCII format to a vector map in
  3. binary format. The module may import two formats:
  4. <ul>
  5. <li><b>standard</b> contains all data types, each coordinate on one row</li>
  6. <li><b>point</b> (default) reads only points, each point defined on
  7. one row. Values are separated by a user-definable delimiter. If
  8. the <b>columns</b> option is not defined, default names are used. It
  9. is possible to specify the column order for the x,y,z coordinates
  10. and category values.</li>
  11. </ul>
  12. <p>
  13. The <a HREF="v.out.ascii.html">v.out.ascii</a> GRASS module performs
  14. the function of <em>v.in.ascii</em> in reverse; i.e., it converts
  15. vector maps in binary format to ASCII format. These two companion
  16. programs are useful both for importing and exporting vector maps
  17. between GRASS and other software, and for transferring data between
  18. machines.
  19. <h2>NOTES</h2>
  20. The input is read from the file specified by the <b>input</b> option or
  21. from standard input.
  22. <p>
  23. The field separator may be a character, the word '<tt>tab</tt>'
  24. (or '<tt>\t</tt>') for tab, '<tt>space</tt>' (or '&nbsp;') for a blank,
  25. or '<tt>comma</tt>' (or ',') for a comma.
  26. <p>
  27. An attribute table is only created if it is needed, i.e. when at
  28. least one attribute column is present in the input file besides
  29. geometry columns. The attribute column will be auto-scanned for type, but
  30. may be explicitly declared along with the geometry columns using the
  31. <b>columns</b> parameter.
  32. <p>
  33. Latitude/Longitude data may be given in a number of ways.
  34. Decimal degrees must be positive or negative instead of using a hemisphere
  35. letter. Mixed coordinates must use a hemisphere letter. Whole minutes and
  36. seconds must always contain two digits (example: use <tt>167:03:04.567</tt>;
  37. and not <tt>167:3:4.567</tt>).
  38. <br><br>
  39. Acceptable formats:<br>
  40. <i>key: D=Degrees; M=Minutes; S=Seconds; h=Hemisphere (N,S,E,W)</i>
  41. <ul>
  42. <li><tt>(+/-)DDD.DDDDD</tt>
  43. <li><tt>DDDh</tt>
  44. <li><tt>DDD:MMh</tt>
  45. <li><tt>DDD:MM.MMMMMh</tt>
  46. <li><tt>DDD:MM:SSh</tt>
  47. <li><tt>DDD:MM:SS.SSSSSh</tt>
  48. </ul>
  49. <p>
  50. Use the <b>-z</b> flag to convert ASCII data into a 3D vector map.
  51. <p>
  52. In special cases of data import, such as the import of large LIDAR datasets
  53. (millions of data points), it may be necessary to disable topology support
  54. (creating a GRASS vector level 1 vector map) due to memory constraints.
  55. This is done with the <b>-b</b> flag. As only very few vector modules
  56. support points data processing at vector level 1, usually topology is
  57. required (vector level 2). Therefore it is recommened that the user first
  58. try to import the data without creating a database (the <b>-t</b> flag)
  59. or within a subregion (the <b>-r</b> flag) before resorting the to
  60. disabling of topology.
  61. <p>
  62. A GRASS ASCII vector map (in <b>standard format</b> mode) may contain a mix
  63. of primitives including points, lines, boundaries, centroids, areas,
  64. faces, and kernels.
  65. <!--This format is described in the
  66. <a HREF="http://freegis.org/cgi-bin/viewcvs.cgi/~checkout~/grass6/doc/vector/vector.html#ascii">GRASS
  67. Vector ASCII Format Specification</a>.--> The GRASS ASCII vector format
  68. may contain a header with various metadata (see example below).
  69. The header is not required if the <b>-n</b> flag is used.
  70. <p>The header is similar as the head file of vector binary format but
  71. contains bounding box also. Key words are:
  72. <pre>
  73. ORGANIZATION
  74. DIGIT DATE
  75. DIGIT NAME
  76. MAP NAME
  77. MAP DATE
  78. MAP SCALE
  79. OTHER INFO
  80. ZONE
  81. WEST EDGE
  82. EAST EDGE
  83. SOUTH EDGE
  84. NORTH EDGE
  85. MAP THRESH
  86. </pre>
  87. <p>The body begins with the row:
  88. <pre>
  89. VERTI:
  90. </pre>
  91. followed by records of primitives:
  92. <pre>
  93. TYPE NUMBER_OF_COORDINATES [NUMBER_OF_CATEGORIES]
  94. X Y [Z]
  95. ....
  96. X Y [Z]
  97. [ LAYER CATEGORY]
  98. ....
  99. [ LAYER CATEGORY]
  100. </pre>
  101. Everything above in <tt>[&nbsp;]</tt> is optional.
  102. <p>
  103. The primitive codes are as follows:
  104. <ul>
  105. <li>'P': point</li>
  106. <li>'L': line</li>
  107. <li>'B': boundary</li>
  108. <li>'C': centroid</li>
  109. <li>'F': face (3D boundary)</li>
  110. <li>'K': kernel (3D centroid)</li>
  111. <li>'A': area (boundary) - better use 'B'; kept only for backward compatibility</li>
  112. </ul>
  113. The coordinates are listed following the initial line containing the
  114. primitive code, the total number of vectors in the series, and (optionally)
  115. the number of categories (1 for a single layer, higher for multiple layers).
  116. Below that 1 or several lines follow to indicate the layer number and
  117. the category number (ID).
  118. <br>
  119. The order of coordinates is
  120. <div class="code"><pre>
  121. X Y [Z]
  122. </pre></div>
  123. In pre-GRASS 6 versions of the ASCII file, the order of coordinates is:
  124. <div class="code"><pre>
  125. Y X
  126. </pre></div>
  127. If old version is requested, the <b>output</b> files from <em>v.out.ascii</em> is placed
  128. in the <tt>$LOCATION/$MAPSET/dig_ascii/</tt> and <tt>$LOCATION/$MAPSET/dig_att</tt> directory.
  129. <h3>Import of files without category ID column</h3>
  130. If the input file does not contain a vector ID column,
  131. there is the possibility to auto-generate these IDs (categories).
  132. To automatically add an additional column named 'cat', the
  133. <b>cat</b> parameter must be set to the virtual column number 0
  134. (<tt>cat=0</tt>). This is the default action if the <b>cat</b> parameter
  135. is not set.
  136. <h3>Importing from a spreadsheet</h3>
  137. Data may be imported from many spreadsheet programs by saving the
  138. spreadsheet as a comma separated variable (.csv) text file, and then
  139. using the <b>fs=','</b> option with <em>v.in.ascii</em> in <b>points</b> mode.
  140. If the input file contains any header lines, such as column headings, the
  141. <b>skip</b> parameter should be used. These skipped header lines will be
  142. written to the map's history file for later reference (read with
  143. <tt>v.info&nbsp;-h</tt>). The skip option only works in <tt>points</tt> mode.
  144. <P>
  145. Any line starting with the hash character ('<tt>#</tt>') will be treated as
  146. a comment and skipped completely if located in the main data file. If located
  147. in the header, as defined by the <b>skip</b> parameter, it will be treated as
  148. a header line and written to the history file.
  149. <h3>Import of sexagesimal degree (degree, minutes, seconds, DMS)</h3>
  150. The import of DMS formatted degrees is supported (in this case no
  151. sign but N/S, E/W characters are used to indicate the hemispheres).
  152. While the positions are internally translated into decimal degrees
  153. during the import, the original DMS values are maintained in the
  154. attribute table. This requires both the latitude and
  155. the longitude columns to be defined as varchars(), not as numbers.
  156. A warning will be issued which can be ignored.
  157. <h3>Importing only selected columns</h3>
  158. Although <em>v.in.ascii</em> doesn't have an option to specify which columns
  159. should be imported, you can use a shell filter to achieve the same effect,
  160. e.g.:
  161. <div class="code"><pre>
  162. # Print out the column number for each field, supposing the file has a header
  163. head -1 input_file | tr '&lt;the_field_separator_character&gt;' '\n' | cat -n
  164. # From the listing, select the columns you want and feed them to v.in.ascii
  165. # do not use the input= option
  166. cut -d&lt;the_field_separator_character&gt; -f&lt;comma-separated_list_of_columns&gt; input_file | v.in.ascii &lt;your_options&gt;
  167. </pre></div>
  168. <h2>EXAMPLES</h2>
  169. <h3>Example 1a) - standard format mode</h3>
  170. Sample ASCII polygon vector map for 'standard' format mode.
  171. The two areas will be assigned categories 20 and 21.
  172. The example can be tested in the Spearfish sample dataset:
  173. <p>
  174. <div class="code"><pre>
  175. echo "ORGANIZATION: GRASS Development Team
  176. DIGIT DATE: 1/9/2005
  177. DIGIT NAME: -
  178. MAP NAME: test
  179. MAP DATE: 2005
  180. MAP SCALE: 10000
  181. OTHER INFO: Test polygons
  182. ZONE: 0
  183. MAP THRESH: 0.500000
  184. VERTI:
  185. B 6
  186. 5958812.48844435 3400828.84221011
  187. 5958957.29887089 3400877.11235229
  188. 5959021.65906046 3400930.7458436
  189. 5959048.47580612 3400973.65263665
  190. 5959069.92920264 3401032.64947709
  191. 5958812.48844435 3400828.84221011
  192. C 1 1
  193. 5958952.42189184 3400918.23126419
  194. 1 20
  195. B 4
  196. 5959010.9323622 3401338.36037757
  197. 5959096.7459483 3401370.54047235
  198. 5959091.38259917 3401450.99070932
  199. 5959010.9323622 3401338.36037757
  200. C 1 1
  201. 5959063.08352122 3401386.98533277
  202. 1 21" | v.in.ascii format=standard output=test_polygons
  203. </pre></div>
  204. <h3>Example 1b) - standard format mode</h3>
  205. Sample ASCII 3D line vector map for 'standard' format mode with simplified input.
  206. Note the <b>-z</b> flag indicating 3D vector input, and the <b>-n</b> flag
  207. indicating no vector header should be expected from the input file.
  208. The example can be tested in the Spearfish sample dataset:
  209. <div class="code"><pre>
  210. echo "L 5 1
  211. 591336 4927369 1224
  212. 594317 4925341 1292
  213. 599356 4925162 1469
  214. 602396 4926653 1235
  215. 607524 4925431 1216
  216. 1 321 " | v.in.ascii -zn out=line3d format=standard
  217. </pre></div>
  218. This can be used to create a vector line of a GPS track: the GPS points have
  219. to be stored into a file with a preceding 'L' and the number of points (per line).
  220. <h3>Example 2</h3>
  221. Generate a 2D points vector map 'coords.txt' as ASCII file:
  222. <div class="code"><pre>
  223. 1664619|5103481
  224. 1664473|5095782
  225. 1664273|5101919
  226. 1663427|5105234
  227. 1663709|5102614
  228. </pre></div>
  229. <p>
  230. Import into GRASS:
  231. <div class="code"><pre>
  232. v.in.ascii input=coords.txt output=mymap
  233. </pre></div>
  234. As the <b>cat</b> option is set to 0 by default, an extra column 'cat'
  235. containing the IDs will be auto-generated.
  236. <h3>Example 3</h3>
  237. Generate a 2D points vector map 'points.dat' as ASCII file:
  238. <div class="code"><pre>
  239. 1|1664619|5103481|studna
  240. 2|1664473|5095782|kadibudka
  241. 3|1664273|5101919|hruska
  242. 4|1663427|5105234|mysi dira
  243. 5|1663709|5102614|mineralni pramen
  244. </pre></div>
  245. <p>
  246. Import into GRASS:
  247. <div class="code"><pre>
  248. cat points.dat | v.in.ascii out=mypoints x=2 y=3 cat=1 \
  249. columns='cat int, x double precision, y double precision, label varchar(20)'
  250. </pre></div>
  251. <p>
  252. The module is reading from standard input, using the default '|' (pipe) delimiter.
  253. <h3>Example 4</h3>
  254. Generating a 3D points vector map from DBMS (idcol must be an integer column):<br>
  255. <div class="code"><pre>
  256. echo "select east,north,elev,idcol from mytable" | db.select -c | v.in.ascii -z out=mymap
  257. </pre></div>
  258. The module is reading from standard input, using the default '|' (pipe) delimiter.
  259. <br>
  260. The import works for 2D maps as well (no elev column and no '-z' flag).
  261. <h3>Example 5</h3>
  262. Generate a 3D points vector map 'points3d.dat' with attributes as ASCII file:
  263. <div class="code"><pre>
  264. 593493.1|4914730.2|123.1|studna|well
  265. 591950.2|4923000.5|222.3|kadibudka|closet
  266. 589860.5|4922000.0|232.3|hruska|pear
  267. 590400.5|4922820.8|143.2|mysi dira|mouse hole
  268. 593549.3|4925500.7|442.6|mineralni pramen|mineral spring
  269. 600375.7|4925235.6|342.2|kozi stezka|goat path
  270. </pre></div>
  271. <P>
  272. Import into GRASS:
  273. <div class="code"><pre>
  274. #As the 'cat' option is set to 0 by default, an extra column 'cat'
  275. #containing the IDs will be auto-generated (no need to define that):
  276. cat points3d.dat | v.in.ascii -z z=3 cat=0 out=mypoints3D \
  277. columns='x double precision, y double precision, z double precision, \
  278. label_cz varchar(20), label_en varchar(20)'
  279. v.info -c mypoints3D
  280. v.info mypoints3D
  281. </pre></div>
  282. <h3>Example 6</h3>
  283. Generate points file by clicking onto the map:
  284. <div class="code"><pre>
  285. #For LatLong locations:
  286. d.where -d -l | awk '{printf "%f|%f|point\n", $1, $2}' | v.in.ascii out=points \
  287. columns='x double precision, y double precision, label varchar(20)'
  288. #For other projections:
  289. d.where | awk '{printf "%f|%f|point\n", $1, $2}' | v.in.ascii out=points \
  290. columns='x double precision, y double precision, label varchar(20)'
  291. </pre></div>
  292. The 'point' string (or some similar entry) is required to generate a database table.
  293. When simply piping the coordinates (and optionally height) without additional column(s)
  294. into <em>v.in.ascii</em>, only the vector map geometry will be generated.
  295. <h3>Example 7</h3>
  296. Convert ground control points from i.points into vector points:
  297. <div class="code"><pre>
  298. cat $MAPSET/group/$GROUP/POINTS | v.in.ascii out=$GROUP_gcp fs=space skip=3 \
  299. col='x double precision, y double precision, x_target double precision, \
  300. y_target double precision, ok int'
  301. </pre></div>
  302. <h2>REFERENCES</h2>
  303. <a HREF="sql.html">SQL command notes</a> for creating databases
  304. <h2>SEE ALSO</h2>
  305. <em>
  306. <a HREF="db.execute.html">db.execute</a>,
  307. <a HREF="r.in.ascii.html">r.in.ascii</a>,
  308. <a HREF="r.in.xyz.html">r.in.xyz</a>,
  309. <a HREF="v.build.html">v.build</a>,
  310. <a HREF="v.build.polylines.html">v.build.polylines</a>,
  311. <a HREF="v.centroids.html">v.centroids</a>,
  312. <a HREF="v.clean.html">v.clean</a>,
  313. <a HREF="v.db.connect.html">v.db.connect</a>,
  314. <a HREF="v.info.html">v.info</a>,
  315. <a HREF="v.out.ascii.html">v.out.ascii</a>,
  316. </em>
  317. <h2>AUTHORS</h2>
  318. Michael Higgins,
  319. U.S.Army Construction Engineering
  320. Research Laboratory<br>
  321. James Westervelt, U.S.Army Construction Engineering
  322. Research Laboratory<br>
  323. Radim Blazek, ITC-Irst, Trento, Italy
  324. <p>
  325. <i>Last changed: $Date$</i>