Python scripts within gpsbabel

Why ?

As I'm a geek and I own a GPSr, I looked at what was possible in terms of homemade scripting solutions. It turns out that it was not what I expected. The first thing is that the command apt-cache search python gps does not return anything useful.

I first wanted to port an existing application written in php (see the ''moulinette'').

It basically analyzes your gps dumps and generates a file suitable for Google Earth with nice graphs, stats. The first step was then to have the needed data in my favorite language: python.

Instead of rewriting a frontend for gpx, I tried to see how easy it was to reuse code from gpsbabel. The software is written in C, and it seems that devs really want to keep it this way, with good old' ANSI C code. There is some skeleton code for building your own module, so I decided to learn this and how to integrate python from C code, at the same time. It turns out it's rather easy. Now, I use gpsbabel as a frontend that feeds my python module with data. Currently, this module outputs a Google Earth file, but this could be anything else...

The code is not very mature, in fact it's still in an early stage development, and I guess it will stay this way. But it could be useful to other people, so feel free to take it and modify it, everything is GPL ! Of course, I won't track upstream changes on a day to day basis, so expect some problems...

What ?

Ok, simply said, you can write a quick & dirty python script to manipulate your GPS data.

How to use it ?!

Simple, simply ask gpsbabel to use the pykml module as output, and give parameters to the script by following the module name by a list of key=value list.

Simple example ! Take this gpx dump from a flight at the Semnoz, uncompress it, and run:

$ PYTHONPATH=$PATHTOGPSBABEL gpsbabel -i gpx -f semnoz-parapente.gpx -o pykml -F pouet.kml

This will output a nice kml file suitable to use directly in Google Earth:

Output from pykml module of GPSBabel

How it works

The pykml.c is a 'bridge' between gpsbabel and python. You need to give the pykml filter the python module it must use with the pymodule parameter:

$ gpsbabel -i...... -o pykml,pymodule=mymodule -F ....

In the mymodule python module, you must have a classes following a given interface.

Currently, I provide 3 modules:

Ok, you've convinced me, where can I download it ?! How do I build it ??

It's available on github. The clone url is

git://github.com/dkm/gpsbabel-python-filter.git

Then, you have to type these commands:

$ aclocal -Im4 && autoconf && ./configure && make

You may be forced to use the extra --with-python=/usr/bin/python2.5 to ask configure to use python 2.5 (yes, you need python 2.5 or higher because it was easier for me)

Then, you're clear to go, but don't forget to set PYTHONPATH var correctly, or gpsbabel will use this nice mecanism for error handling called "Segmentation fault" :)

Hey, I'm lazy, I don't want to build anything !

Not a problem, you may find some packages for ubuntu on my ppa. Maybe the packages are there, maybe not, you should check before trying to install anything :). If you are very lazy and don't even want to open the ppa page, you can add these lines:

deb http://ppa.launchpad.net/marc-poulhies/ppa/ubuntu jaunty main

to your /etc/apt/sources.list file. Then, simply update and check if there is a gpsbabel package available there.

The gpsbabel package only includes the gpsbabel executable (with python support), but no python code. The python module used with this custom version of gpsbabel are part of the python filters. There is also a package available on my ppa.