1v.in.ascii(1) Grass User's Manual v.in.ascii(1)
2
3
4
6 v.in.ascii - Convert GRASS ascii file or points file to binary vector.
7
9 vector
10
12 v.in.ascii
13 v.in.ascii help
14 v.in.ascii [-ztenb] [input=string] output=name [format=string]
15 [fs=string] [skip=integer] [columns=string] [x=integer]
16 [y=integer] [z=integer] [cat=integer] [--overwrite]
17
18 Flags:
19 -z Create 3D file
20
21 -t Do not create table in points mode
22
23 -e Create a new empty map and exit. Nothing is read from input.
24
25 -n Don't expect a header when reading in standard format
26
27 -b Do not build topology in points mode
28
29 --overwrite
30
31 Parameters:
32 input=string
33 ASCII file to be converted to binary vector file, if not given
34 reads from standard input
35
36 output=name
37 Name for output vector map
38
39 format=string
40 Input file format Options: point,standard Default: point
41
42 fs=string
43 Field separator Default: |
44
45 skip=integer
46 Number of header lines to skip at top of input file (written to map
47 history) Default: 0
48
49 columns=string
50 Columns definition for points mode in SQL style, for example:
51 ’x double precision, y double precision, cat int, name varchar(10)'
52
53 x=integer
54 Number of column used as x coordinate (first column is 1) for
55 points mode Default: 1
56
57 y=integer
58 Number of column used as y coordinate (first column is 1) for
59 points mode Default: 2
60
61 z=integer
62 Number of column used as z coordinate (first column is 1) for
63 points mode. If 0, z coordinate is not used. Default: 0
64
65 cat=integer
66 Number of column used as category (first column is 1) for points
67 mode. If 0, unique category is assigned to each row and written to
68 new column 'cat'. Default: 0
69
71 v.in.ascii converts a vector map in ASCII format to a vector map in
72 binary format. The module may import two formats:
73
74 standard contains all data types, each coordinate on one row
75
76 point (default) reads only points, each point defined on one row.
77 Values are separated by a user definable deliminator. If the
78 'columns' option is not defined, default names are used. It is
79 possible to specify the column order for the x,y,z coordinates
80 and category values.
81
82 The input is read from a file specified by input option or from stan‐
83 dard input.
84
85 Field separator may be a character, the word 'tab' (or '\t') for tab,
86 or 'space' (or ' ') for blank.
87
88 In special cases of data import, such as the import of large points map
89 from LIDAR, it will be desired to disable topology support (GRASS vec‐
90 tor level 1). This can be done by setting the -b flag. Only very few
91 vector modules support points data processing at vector level 1, usu‐
92 ally topology is required (vector level 2).
93
94 The v.out.ascii GRASS module performs the function of v.in.ascii in
95 reverse; i.e., it converts vector files in binary format to ASCII for‐
96 mat. These two companion programs are useful both for importing and
97 exporting vector files between GRASS and other software, and for trans‐
98 ferring data between machines.
99
101 Use the -z flag to convert ASCII data into a 3D binary vector map.
102
103 A GRASS ASCII vector file (in standard mode) may contain a mix of prim‐
104 itives including points, lines, boundaries, centroids, areas, faces,
105 and kernels. On top a header can be defined (see example below).
106
107 The primitive codes are as follows:
108 ’P': point ’L': line ’B': boundary ’C': centroid ’F': face (3D
109 boundary) ’K': kernel (3D centroid) ’A': area (boundary) - bet‐
110 ter use 'B'; kept only for backward compatibility
111 The coordinates are listed following the initial line containing the
112 primitive code, the total number of vectors in the series, and the num‐
113 ber of categories (1 for a single layer, higher for multiple layers).
114 Below that 1 or several lines follow to indicate the layer number and
115 the category number (ID).
116 The order of coordinates is
117 X Y [Z]
118
119 Import of files without category ID column
120 If the input file does not contain any vector ID column, there is the
121 possibility to auto-generate these IDs (categories). To automatically
122 add an additional column named 'cat', the cat parameter must be set to
123 the virtual column number 0 (cat=0). This is the default action if the
124 cat parameter is not set.
125
126 Importing from a spreadsheet
127 Data may be imported from many spreadsheet programs by saving the
128 spreadsheet as a comma separated variable (.csv) text file, and then
129 using the fs=',' option with v.in.ascii in points mode. If the input
130 file contains any header lines, such as column headings, the skip
131 parameter should be used. These skipped header lines will be written to
132 the map's history file for later reference (read with v.info -h).
133
134 Any line starting with the hash character ('#') will be treated as a
135 comment and skipped completely if located in the main data file. If
136 located in the header, as defined by the skip parameter, it will be
137 treated as a header line and written to the history file.
138
139 Import of sexagesimal degree (degree, minutes, seconds, DMS)
140 The import of DMS formatted degrees is supported (in this case no sign
141 but N/S, E/W characters are used to indicate the hemispheres). While
142 the positions are internally translated into decimal degrees during the
143 import, the original DMS values are maintained in the attribute table.
144 This requires both the latitude and the longitude columns to be defined
145 as varchars(), not as numbers. A warning will be issued which can be
146 ignored.
147
148 Importing only selected columns
149 Although v.in.ascii doesn't have an option to specify which columns
150 should be imported, you can use a shell filter to achieve the same
151 effect, e.g.:
152 # Print out the column number for each field, supposing the file has a
153 header
154 head -1 input_file | tr '<the_field_separator_character>' '\n' | cat -n
155 # From the listing, select the columns you want and feed them to
156 v.in.ascii
157 # do not use the input= option
158 cut -d<the_field_separator_character> -f<comma-separated_list_of_col‐
159 umns> input_file | v.in.ascii <your_options>
160
161
163 Example 1a) - standard mode
164 Sample ASCII polygon vector map for 'standard' mode. Note the blank
165 before entering vertex coordinates. The example can be tested in the
166 Spearfish sample dataset:
167
168
169 ORGANIZATION: GRASS Development Team
170 DIGIT DATE: 1/9/2005
171 DIGIT NAME: -
172 MAP NAME: test
173 MAP DATE: 2005
174 MAP SCALE: 10000
175 OTHER INFO: Test polygons
176 ZONE: 0
177 MAP THRESH: 0.500000
178 VERTI:
179 B 6 1
180 5958812.48844435 3400828.84221011
181 5958957.29887089 3400877.11235229
182 5959021.65906046 3400930.7458436
183 5959048.47580612 3400973.65263665
184 5959069.92920264 3401032.64947709
185 5958812.48844435 3400828.84221011
186 1 1
187 B 4 1
188 5959010.9323622 3401338.36037757
189 5959096.7459483 3401370.54047235
190 5959091.38259917 3401450.99070932
191 5959010.9323622 3401338.36037757
192 1 2
193
194
195 Example 1b) - standard mode
196 Sample ASCII 3D line vector map for 'standard' mode with simplified
197 input (no header). The example can be tested in the Spearfish sample
198 dataset:
199 echo "L 5 1
200 591336 4927369 1224
201 594317 4925341 1292
202 599356 4925162 1469
203 602396 4926653 1235
204 607524 4925431 1216
205 1 321 " | v.in.ascii -zn out=line3d format=standard
206 This can be used to create a vector line of a GPS track: the GPS
207 points have to be stored into a file with a preceding 'L' and the num‐
208 ber of points (per line).
209
210 Example 2
211 Generate a 2D points vector file 'coords.txt' as ASCII file:
212 1664619|5103481
213 1664473|5095782
214 1664273|5101919
215 1663427|5105234
216 1663709|5102614
217
218
219 Import into GRASS:
220 v.in.ascii input=coords.txt output=mymap
221 As the cat option is set to 0 by default, an extra column 'cat' con‐
222 taining the IDs will be auto-generated.
223
224 Example 3
225 Generate a 2D points vector file 'points.dat' as ASCII file:
226 1|1664619|5103481|studna
227 2|1664473|5095782|kadibudka
228 3|1664273|5101919|hruska
229 4|1663427|5105234|mysi dira
230 5|1663709|5102614|mineralni pramen
231
232
233 Import into GRASS:
234 cat points.dat | v.in.ascii out=mypoints x=2 y=3 cat=1 \
235 columns='cat int, x double, y double, label varchar(20)'
236
237
238 The module is reading from standard input, using the default '|' (pipe)
239 delimiter.
240
241 Example 4
242 Generating a 3D points vector map from DBMS (idcol must be an integer
243 column):
244
245 echo "select east,north,elev,idcol from mytable" | db.select -c |
246 v.in.ascii -z out=mymap
247 The module is reading from standard input, using the default '|'
248 (pipe) delimiter.
249 The import works for 2D maps as well (no elev column and no '-z' flag).
250
251 Example 5
252 Generate a 3D points vector file 'points3d.dat' with attributes as
253 ASCII file:
254 593493.1|4914730.2|123.1|studna|well
255 591950.2|4923000.5|222.3|kadibudka|closet
256 589860.5|4922000.0|232.3|hruska|pear
257 590400.5|4922820.8|143.2|mysi dira|mouse hole
258 593549.3|4925500.7|442.6|mineralni pramen|mineral spring
259 600375.7|4925235.6|342.2|kozi stezka|goat path
260
261
262 Import into GRASS:
263 #As the cat option is set to 0 by default, an extra column 'cat'
264 #containing the IDs will be auto-generated (no need to define that):
265 cat points3d.dat | v.in.ascii -z z=3 cat=0 out=mypoints3D \
266 columns='x double, y double, z double, label_cz varchar(20),
267 label_en varchar(20)'
268 v.info -c mypoints3D
269 v.info mypoints3D
270
271
272 Example 6
273 Generate points file by clicking onto the map:
274 #For LatLong locations:
275 d.where -d -l | awk '{printf "%f|%f|point\n", $1, $2}' | v.in.ascii
276 out=points \
277 columns='x double, y double, label varchar(20)'
278 #For other projections:
279 d.where | awk '{printf "%f|%f|point\n", $1, $2}' | v.in.ascii
280 out=points \
281 columns='x double, y double, label varchar(20)'
282 The 'point' string (or some similar entry) is required to generate a
283 database table. When simply piping the coordinates (and optionally
284 height) without additional column(s) into v.in.ascii, only the vector
285 map geometry will be generated.
286
287 Example 7
288 Convert ground control points from i.points into vector points:
289 cat $MAPSET/group/$GROUP/POINTS | v.in.ascii out=$GROUP_gcp fs=space
290 skip=3 \
291 col='x double, y double, x_target double, y_target double, ok int'
292
293
295 db.execute
296 v.db.connect
297 v.out.ascii
298 v.info
299 v.build
300 v.build.polylines
301 v.clean
302 SQL command notes for creating databases
303 Vector ASCII Format Specification
304
306 Michael Higgins, U.S.Army Construction Engineering Research Laboratory
307 James Westervelt, U.S.Army Construction Engineering Research Laboratory
308 Radim Blazek, ITC-Irst, Trento, Italy
309
310 Last changed: $Date: 2006/05/31 13:03:57 $
311
312 Full index
313
314
315
316GRASS 6.2.2 v.in.ascii(1)