GPSBabel/Using filters

From OpenStreetMap Wiki
Jump to navigation Jump to search

This page covers using the GPSBabel program to edit tracks by using filters. There's also some more information in Making GPX Tracks.

This page describes using the filters on the command line. For GUI-based options, see the alternative programs in editing GPX Tracks.


Note: You should read about "using GPSBabel from the command line" before to understand working with GPSBabel in general (since this page is focussed only on the filters).

GPSBabel lets you filter your results. It can modify tracks, routes and waypoints, not all of the filters can handle all three dataforms, check with the gpsbabel capabilities page before trying.

The filter parameter is placed between input and output parameters and takes the format

-x <filter_name>,<filter_parameter1>,<filter_parameter2>...

A word about parsing issues in JOSM

gpsbabel may create GPX files that JOSM fails to load with the following error message :

In the error window : Could not parse file
On the console : The prefix "gpxdata" for element "gpxdata:hr" is not bound.

In this case, a workaround is to remove all the strings "gpxdata:" from the GPX file. On Unix based systems, the following command does the trick :

sed 's/gpxdata://g' IN.gpx > OUT.gpx

Include points within radius filter

This command takes two GPX files as input and then outputs those waypoints within 5 miles of 40.75N, 119.25 W into the GPX file merge.gpx.

gpsbabel -i gpx -f way_iii.gpx -f way_rino.gpx \
    -x radius,distance=5M,lat=40.75,lon=-119.25 \
    -o gpx -F merge.gpx

Exclude points within given radius (ie. privacy issue)

When uploading tracks, you might (or should) be concerned that your start and end location can be determined easily and/or precisely, because they might be the places where you or your relatives live or work.

The following command will filter out all the points within a circle around these "privacy hot spots". Adapt lat, long and radius to your own needs.

gpsbabel -i gpx -f in.gpx \
    -x transform,wpt=trk,del \
    -x radius,distance=1.1K,lat=40.01,lon=10.001,nosort,exclude \
    -x transform,trk=wpt,del \
    -o gpx -F out.gpx

Distance is kilometers (K) or Miles (M). (The command combines several tracks in to one.)

You can also chain several "-x radius" commands, eg. :

  • for both the start and end of tracks
  • if you have several hot spots (home, office, friends...)
  • if you feel paranoid : as a matter of fact, if you have one track where you enter and leave the circle several times, it's pretty easy to find out from the truncated track where the hot spot is. To address this, place randomly several filters with random centers around the real hot spot.

Remove all saved tracks filter

On the Garmin units old tracks can be saved and compressed. These tracks will always be downloaded unless they are filtered. As they have no time data and are compressed they also cause issues in JOSM when trying to geotag images. The following filter will only keep the tracks with ACTIVE in the title.

-x track,name="ACTIVE *"

Remove duplicates and nearby points filter

To remove duplicate points, use a filter of

-x duplicate,location

To remove points that are closer than 5 meters to earlier points, use a filter of

-x position,distance=5m

Arc filter

You can convert a track log to a GPSBabel arc file and then filter waypoints based on their proximity to that 'arc' or route by using the '-x arc filter'.

Simplifying tracks

It's very easy to use gpsbabel to simplify track just this will reduce your track to 400 points, depending on your track this will not affect the accuracy much. E.g. on my biking trips the GPS captures 2 points/s I was able to simplify 8000 points to 400 or even 100 without much effect.

gpsbabel -i gpx -f way_iii.gpx  \
    -x simplify,count=400 \
    -o gpx -F merge.gpx

Another option is to use crosstrack error filter. It discards points that are close enough to the line drawn between two points adjacent to them, so the overall track's shape is not disturbed too much. If we treat simplifying tracks as a compression process, then the above example makes the track fit into specified size while the command below preserves its quality regardless of the size. Points will be removed if they are no farther than 1 metre (0.001 of kilometre) from the track.

gpsbabel -i gpx -f way_iv.gpx  \
    -x simplify,crosstrack,error=0.001k \
    -o gpx -F merge.gpx

You can also use Potlatch to simplify a track. Upload it to OSM, then click the "edit" link next to the uploaded track (not the edit tab at the top of the page), and click "Track" when Potlatch opens.

Remove unreliable points filter

-x discard,hdop=4

To only filter the tracks (while keeping all waypoints, which may be your survey notes) add "track" to the filter options:

-x track,discard,hdop=4

Of course, you need to adjust the HDOP value to suit your needs.

Time filters

Only include data recorded after 2008-07-23 20:00

gpsbabel -t -w -i garmin -f /dev/ttyUSB0 -x track,start=2008072320 -o gpx -F waypoint.gpx 

Merge tracks

To merge several GPX track files into one (this doesn’t actually combine tracks, but rather creates a file containing several tracks):

gpsbabel -t -i gpx -f track1.gpx -f track2.gpx -f track3.gpx -o gpx -F combined-tracks.gpx

Instead of listing each single gpx-file one can also use a small script like this:

# Append multiple gpx files easily
# Save this as
# Use: for example, to merge all files that start with 'track_2013' in the current folder, do:
# track_2013*.gpx

gpsbabel -i gpx $(echo $* | for GPX; do echo -n " -f $GPX "; done) -o gpx -F appended.gpx