Hack 70. Import Your GPS Waypoints and Tracklogs into GRASS

Use GRASS to tell the story of your travels on a customized map.

GRASS has a reputation as a complicated program that can do anything, but at the cost of hair-pulling pain. Here is a (relatively) simple guide to getting GRASS to do interesting things with your own GPS data. Along the way, we'll also convince GRASS to show us some interesting base-map layers as a way of providing context for our own story. By this point, you've probably loaded some waypoints and tracklogs from your GPS receiver onto your computer: now, let's import them into GRASS!

Before Version 5.7, GRASS referred to point data as "site" data, and there were s. commands to manipulate site data. As of Version 5.7, points are included in the much improved "Vector" format. A point is just the simplest vector. Some of the old s. sites commands now work with point data but store the points in the new vector format.

The s.in.ascii command imports text data into a vector file. You can specify a comma as your input field separator and import data that looks like this:

easting,northing,[attribute]

Data fields provided to s.in.ascii can also be separated by tabs, spaces, or an arbitrary separator of your choice. Meanwhile, here's an example of what we're starting with, a few lines of tracklog data downloaded via gpstrans.

Format: DDD UTC Offset: -8.00 hrs Datum[100]: WGS 84
T 03/03/2004 16:53:01 38.4018946 -122.8440571
T 03/03/2004 16:53:02 38.4018946 -122.8440785

After the header line, each line of data consists of four tab-separated fields: a data type (T, for tracklog), a timestamp, and a latitude/longitude pair. Use this quick Perl script to convert gpstrans output into a form that can be handled by s.in.ascii.

#!/usr/bin/perl
 
while (my $point = <>) {
 chomp $point;
 my ($type, $date, $lat, $long) = split /	/, $point;
 next unless $lat and $long;
 print "$long,$lat,$date
";
}

Note that latitude and longitude are reversed in the output, because "easting" here is measured in degrees of longitude. Here is an extract from a tracklog that has been cleaned up to import into GRASS.

-122.8440571,38.4018946,03/03/2004 16:53:01
-122.8440785,38.4018946,03/03/2004 16:53:02

Now we import the tracklog into GRASS. First start GRASS and load the global data set with the U.S. state boundaries that we assembled in [Hack #69] .

GRASS:~/wa/gps > perl ./fix_track.pl tk_2004-03-03-rino.txt > temp.txt
GRASS:~/wa/gps > s.in.ascii output=tracklog input=temp.txt fs=,

Let's see what's there:

GRASS:~/wa/gps > d.mon start=x0
GRASS:~/wa/gps > d.vect map=tracklog color=green size=2

I've used the d.zoom command to center the map over my area of interest, producing Figure 6-29.

Figure 6-29. Tracklog on Catalina Island

That is a record of a weeklong dive trip around Catalina Island off the coast of Southern California. Now let's add some context.

Here is a bit of a waypoint file.

-121.970944444444 37.3223055555556 HITHAI
-122.829027777778 38.4025277777778 HOME

Note that now it is delimited with spaces, so the field separator (fs) is now set to space. We can import this into GRASS and display the waypoints, along with our states layer, with the commands:

GRASS:~/wa/gps > s.in.ascii output=waypoint input=wy102103.asc fs=space
GRASS:~/wa/gps > d.vect map=states color=grey
GRASS:~/wa/gps > d.vect map=tracklog color=green size=2
GRASS:~/wa/gps > d.vect map=waypoint icon=basic/diamond size=8 
 color=grey fcolor=red

Figure 6-30 shows all the components of our map together: the tracklog, the nearby waypoints, and the state borders underneath provide context.

Figure 6-30. Catalina tracklog with waypoints and base map

This map has one problem: tracks are displayed as discrete points. This gives the resulting maps a faint fairy-tracing appearance. I find the effect soothing, as it hints of an ambiguity in time and place. The GPS seems to speak to me, telling me, "Sure, I knew where you were at this moment, and then at this moment, and on through the day, but between those times, I don't know where you were." It is as though I traveled through a series of quantum jumps, disregarding intervening space (a trick that those driving the Nebraska panhandle will find themselves wanting to add to their travel kits).

See the next hack, [Hack #71] for a way to convert the discrete points to lines.

Mapping Your Life

Mapping Your Neighborhood

Mapping Your World

Mapping (on) the Web

Mapping with Gadgets

Mapping on Your Desktop

Names and Places

Building the Geospatial Web

Mapping with Other People



Mapping Hacks
Mapping Hacks: Tips & Tools for Electronic Cartography
ISBN: 0596007035
EAN: 2147483647
Year: 2004
Pages: 172

Flylib.com © 2008-2020.
If you may any questions please contact us: flylib@qtcs.net