[GRASS-dev] v.in.gpsbabel nearly fixed: awk magic needed (RT bug #5478)

Markus Neteler neteler at itc.it
Thu May 10 17:00:19 EDT 2007


HI,

I think I got v.in.gpsbabel for tracks and routes (did that
ever work?). However, I have a final problem which requires
a bit of awk magic:

The GPX tracks file extracted from my Garmin contains a track
which isn't attributed (I dunno why but that's life). The
v.in.gpsbabel scripts successfully creates the map, then fails
on creating the attrib table. Here the problem:


# note: files contains tab delimiters
head -2 12021.0.track_atts
1
2               45.417394638    10.847196579            45.359029770    10.166580677


# make tab delim visible (just for illustration):
head -2 12021.0.track_atts | tr -s '\t' '|'
1 | | | | | |
2 | |45.417394638 |10.847196579 | |45.359029770 |10.166580677


# this is what happens in v.in.gpsbabel (note: it does cat instead of head):
head -2 12021.0.track_atts | awk -F'\t' '{ printf("echo \"INSERT INTO $NAME VALUES (%d, ^%s^, %s, %s, ^%s^, %s, %s)\" | db.execute\n", $1, $2, $3, $4, $5, $6, $7) }' | tr '^' \'
echo "INSERT INTO $NAME VALUES (1, ' ',  ,  , ' ',  , )" | db.execute
echo "INSERT INTO $NAME VALUES (2, ' ', 45.417394638 , 10.847196579 , ' ', 45.359029770 , 10.166580677)" | db.execute


We see that the first line isn't valid SQL. The first line should be:
echo "INSERT INTO $NAME VALUES (1, ' ', NULL  , NULL , ' ', NULL , NULL)" | db.execute

Question: what to ask in the awk line to autoinsert NULL if 0 length is
found in the numeric columns 3, 4, 6, 7?

thanks
Markus




More information about the grass-dev mailing list