Cleaning up GPX tracks with GPSBabel

A GPX track file can become quite large, depending on:

  • the length of the track (obviously) and
  • the recording frequency of the track points

I mostly record tracks with a rather high frequency (to get as many trackpoints "as i can get"), but to publish them, it is often a good idea to minimize the amount of trackpoints. Not only that this can greatly reduce the size of the GPX files, it can actually make them "better" (see below).

To do this, you can use the great (and free) GPSBabel tool.

You can give it a maximum number of trackpoints, and it will reduce your GPX file to that given amount. (You can also use it to do all sorts of other stuff, like correcting / shifting / stripping out timestamps - see the GPSBabel documentation. But that's not the point here.).

(you can also use tools like Garmin's BaseCamp for that same purpose - look here for some instructions.)

1. Reducing the number of trackpoints

Select your GPX file - say, "mytrack.gpx" - as Input file.

Select "mytrack-filtered.gpx" as Output file.

In the Filter options, set the max. number of waypoints to "something reasonable" - try e.g. 500.

Finding out what is "reasonable" depends on your track distance, and whether you recorded it while hiking (=slow), cycling (=medium) or with a motorbike or car (=fast). Note: i have no experience with faster moving things, Space Shuttles or the like :-) 

See the examples below to get an idea on how filtering out trackpoints affects the "quality" of your track.

2. Effects of trackpoint filtering

If you look at the track infos for the track versions below, you will notice that filtering out trackpoints does have some effect on the calculated length, and it has a rather large effect on the up/down altitude differences.

GPSBabel does a pretty good job on filtering, if you don't overdo (that is: don't filter out to much track points).

2.1. Original track (as recorded: almost 2000 track points)

File size: ~313kb

10.9 km, 1 days 4 hrs 05 mins

2.2.  First filtered example: 500 trackpoints

File size: ~82kb

10.7 km, 1 days 4 hrs 05 mins

2.3.  Second filtered example: 250 trackpoints

File size: ~53kb

10.3 km, 1 days 4 hrs 05 mins

2.4.  Third filtered example: 100 trackpoints

File size: ~36kb

9.8 km, 1 days 4 hrs 05 mins

3.  Effects on Track Info accuracy

Note that the 100-point example above still "looks" pretty much like the original one with almost 2000 trackpoints - and is, for most users, still accurate enough so they (or yourself) could follow the track - good job, GPSBabel!

But one thing seems strange: the original file reports 823 m of upward altitude change, while e.g. the 250-point version reports merely 400 m - what's happening here?

The answer lies in two issues: firstly the inaccuracy of the elevation data as recorded by the GPS (a Garmin Oregon in this case), combined with -secondly- the "flattening" of the track that comes from filtering out track points.

Note: It is important to understand that GPS devices (for technical reasons) have a "ripple" or "noise" in the recorded data, which gets more the less you move (!).

This "failure" actually is at it's worst - if you don't move at all (!).

If you look at the original track and the 250-point version with a tool like GPX Editor, you will see the difference:


original gpx file - lots of ripple


250-point filtered version: less ripple

Since GPXTrackMap simply adds up the altitude changes from trackpoint to trackpoint (positive and negative changes individually), it becomes quite clear why the (positive) altitude change calculated from the unfiltered file is much bigger than the one from the filtered version.

4. So what's the truth, then?

 If you want my opinion: it's somewhere in-between - but a "reasonably" filtered file should give you more accurate results than an unfiltered one, because GPSBabel filters out a lot of the (unwanted) ripple in the signals.

This all, of course, also depends on the quality of your GPS receiver, and how it measures the altitude in the first place.

5. Measuring altitude by measuring air pressure (a.k.a. barometer)

Most devices (like my Garmin) do this with a barometer, which is - in the best sense of the word - relatively accurate: the changes in altitude are -mostly- measured quite accurately, while the absolute altitude can be way off - by as much as 100 m or more.

Just a "stupid" test: Set your GPS to record. Put it in a plastic bag. Put it resting on a table. After 2 minutes, blow air into the bag. Put it back on the table. After another 2 minutes, suck the air out again (and put the GPS back on that same table). After yet another 2 minutes, take the GPS out of the bag, and look at the funny "elevation curve" it has recorded - see what i mean? ;-)

Not recommended(!): the "airplane test": I once took my GPS on an airplane flight, just so that i could see where we were flying. At one time (in mid flight, long after the seat belt signs had been switched off!), it showed an altitude of ~2000m - exactly while the captain happily reported we had reached our destination altitude of ~11000m(!). The GPS was trying to calculate the absolute altitude from the cabin pressure. Go figure... The next time i tried to verify my findings, i almost got kicked out of the plane, so "don't try this at home"! ;-)

Adding to this, sudden changes in the weather conditions (like pressure drops, oncoming thunder storms) will have a bad influence on accuracy. That's why you have to calibrate barometric altitude meters directly at the starting point of your trip to get good absolute measurements - you thereby "tune it in" to the current weather conditions.

Barometric altitude measurement follows a simple physical rule: the higher you are, the lower the (air) pressure must be. If you stay at the very same spot while the weather is getting "better" (=higher air pressure) or "worse" (=lower air pressure), your GPS will "think" that you are changing altitude, even though you're not moving an inch in either direction (!).

So even the relative altitude data your GPS records during your trip will only be "somewhat" accurate, IF the air pressure in your traveling region stays the same throughout your trip (that may be true for some parts of the world, but where i live the weather can change from "clear blue skies" to "heavy rain" within hours, or even minutes. In that case: just FORGET about the elevation data from your GPS! :-) )

6. Some final thoughts on altitudes and accuracy...

As some final "food for thought": At the end of the track that you see above, my friend (who recorded it) was walking to and fro on a bridge, taking pictures. Since this bridge is as flat as it can get (altitude-wise), there actually should be NO change in elevation here at all... see my point? :-)

Bottom line: don't take the up/down altitude changes too seriously, they are always just an aproximation of how much meters of terrain you really climbed. Same goes for the track length: it's also merely an aproximation, though it's usually closer to the truth than the elevation. 

As a rule of thumb, i would say that if you record hiking trails, ~250 track points per 10 km are a good compromise between files size and accuracy. I still have to do some tests with my biking trails - as the traveling speed is much higher there, one would need more trackpoints per km - but with GPSBabel you can easily test this yourself.