3
############################################################################
7
# AUTHOR(S): Hamish Bowman
9
# PURPOSE: Import point data as lines ('v.in.mapgen -f' wrapper script)
11
# COPYRIGHT: (c) 2009-2010 The GRASS Development Team
13
# This program is free software under the GNU General Public
14
# License (>=v2). Read the file COPYING that comes with GRASS
17
#############################################################################
19
#% description: Imports ASCII x,y[,z] coordinates as a series of lines.
27
#% description: Create a 3D line from 3 column data
29
#%option G_OPT_F_INPUT
30
#% description: Name of input file (or "-" to read from stdin)
32
#%option G_OPT_V_OUTPUT
41
from grass.script.utils import separator, try_remove
42
from grass.script import core as grass
50
fs = separator(options['separator'])
61
tmp = grass.tempfile()
64
#### set up input file
65
if options['input'] == '-':
69
infile = options['input']
70
if not os.path.exists(infile):
71
grass.fatal(_("Unable to read input file <%s>") % infile)
72
grass.debug("input file=[%s]" % infile)
76
# read from stdin and write to tmpfile (v.in.mapgen wants a real file)
79
if len(line.lstrip()) == 0 or line[0] == '#':
81
outf.write(line.replace(fs, ' '))
86
# read from a real file
94
if len(line.lstrip()) == 0 or line[0] == '#':
96
outf.write(line.replace(fs, ' '))
103
##### check that there are at least two columns (three if -z is given)
106
if len(line.lstrip()) == 0 or line[0] == '#':
108
numcols = len(line.split())
111
if (do3D and numcols < 3) or (not do3D and numcols < 2):
112
grass.fatal(_("Not enough data columns. (incorrect fs setting?)"))
115
grass.run_command('v.in.mapgen', flags = 'f' + do3D,
116
input = runfile, output = options['output'])
119
if __name__ == "__main__":
120
options, flags = grass.parser()
121
atexit.register(cleanup)