Tuesday, April 2, 2024

GPSBabel

GPX / Travel.

I made an earlier reference to GPSBabel. It's a tool to 'fool around' with some .GPX files.

There is a full manual in PDF available here. or an online version here (lots of ads, unfortunately).


Why not use the GUI?

Some options can't be used from the GUI, and sometimes the GUI doesn't work properly.


Basic format

gpsbabel -i <format> -f <sourcefile> [lots of options] -o <outputformat> -F <outputfile>

Pleae note! The parameters for gpsbabel are CASE SENSITIVE!


Tips / Notes

MRA Routeplanner (Gold) users have some similar functions available in the routeplanner. The 'Reverse Route' unction requires a Gold subscription.

Kurviger (even the free version) allows you to reverse routes, and it has an option to snap routepoints to the roads nearest by.


Reformat the GPX file 

Read it in, then export it again:

gpsbabel -i gpx -f "d:\gpx\2 - mra routeplanner.gpx" -o gpx -F "d:\gpx\basis.gpx"

This makes some changes to the header and reformats the .XML, but otherwise all data seems to stay intact.

My 'basic' file looks like this in GPXSee:


(Click on image to enlarge.)


Filters

Remove a data type

Nuke (removes) waypoints and routes from the source file:

gpsbabel -i gpx -f "d:\gpx\basis.gpx" -x nuketypes,waypoints,routes -o gpx -F "d:\gpx\trackonly.gpx"

-x - enable / apply filter

nuketypes - type of filter, in this case remove certain types

waypoints,routes - type of data to be removed


Result:


Transform a data type

Turn a track into a route:

gpsbabel -i gpx -f "d:\gpx\basis.gpx" -x nuketypes,waypoints,routes -x transform,rte=trk -o gpx -F "d:\gpx\routefromtrack.gpx"

-x - enable / apply filter

transform - transform one data type to another

rte=trk - convert trak to route

wpt=trk - convert track to waypoint

rte=wpt - convert wapypoint to route


By converting a track into a route you can quickly see how many track points are actually used in a (generated) .GPX file, and how they are spread. In this case the route contains 398 route points (these were the 398 track points, converted to route points):

As the source was generated on basis of a route by MRA Routeplanner the 'track points' are only there to highlight the track. More track points are used to represent curves - for example the roundabouts.

A real-life recording would have a more even spacing of the track points, but it would be more 'jittery' due to poor GPS reception or equipment inaccuracies.


Simplify

Try to reduce the number of waypoints.

You might end up with points in the odd location, like just off the highway etcetera, so always load the resulting route back into MRA Routeplanner or something similar and make sure the waypoints are exactly on the roads and not in the odd location.

gpsbabel -i gpx -f "d:\gpx\basis.gpx" -x nuketypes,waypoints,routes -x transform,rte=trk -x simplify,count=50 -o gpx -F "d:\gpx\simplified_50.gpx"

simplify - try to reduce the number of waypoints

count=50 - specify the max number of waypoints


Unless a route is very long or complex a 50 to 100 waypoints (route points) should suffice. Notice that your app or device may have a limit. I lost one point in the resulting file, but I admit that specific one was a bit tricky 😏


gpsbabel -i gpx -f "d:\gpx\basis.gpx" -x nuketypes,waypoints,routes -x transform,rte=trk -x simplify,count=50 -o gpx -F "d:\gpx\simplified_100m.gpx"

simplify,error=0.02k - specify max distance error of 20 meters

This resulted in an acceptable route. Note that you can always remove some superfluous waypoints by hand, and should always check the output by hand for mistakes.


Heuvelrug route

Armed with all the knowledge above, we can try to convert a downloaded actual track to an editable route.

The source is here: https://www.anwb.nl/eropuit/dagje-uit/autoroute/routes/anwb-heuvelrugroute.


It contains tracks and waypoints, but no route. The tracks often do not match the actual road, but meander around a bit.


A quick check with Windows' Notepad showed that the file contained waypoints. I converted the waypoints to a route using...

gpsbabel -i gpx -f "d:\gpx\heuvelrug_anwb.gpx" -x nuketypes,tracks,routes -x transform,rte=wpt -o gpx -F "d:\gpx\heuvelrug_routefromwaypoints.gpx"

... but they weren't properly sorted, nor matching the route. So, instead I turned the track into a route, using...

gpsbabel -i gpx -f "d:\gpx\heuvelrug_anwb.gpx" -x nuketypes,routes,waypoints -x transform,rte=trk -x simplify,count=100 -o gpx -F "d:\gpx\heuvelrug_simplify_100.gpx"

... and then manually checked all the route points (which took me about 15 minutes in MRA Routeplanner, using a dual monitor setup, with on one screen MRA Routeplanner, and on the other screen GPXSee).


Result:


(Click to enlarge.)


Why the ANWB didn't clean up their routes is a mystery to me...


Reverse a route

Swap start and ending points. 

gpsbabel -i gpx -f "d:\gpx\input.gpx" -r -x reverse -o gpx -F "d:\gpx\output.gpx"

-r - route mode (may not be required when using nuketypes)

nuketypes,waypoints,tracks - remove track and waypoint information

reverse - reverse 'filter'

Note that reversing a route doesn't adjust highway ramps and oneway streets, so make sure to re-check your file!

It also doesn't change any of the timestamps (causing the trip to go backwards in time...) If that is a problem, then you have to create artificial timestamps (see next section).

The free version of Kurviger allows you to reverse routes as well.


Redo timestamps

Create artificial timestamps for a track.

gpsbabel -i gpx -f "d:\gpx\input.gpx" -t -x nuketypes,waypoints,routes -x track,faketime=f20100705200000+2 -o gpx -F "d:\gpx\output.gpx"

-t - makes sure it only affects tracks (may not be required when using nuketypes)

 track,faketime - create / replace track timestamps

faketime=fYYYYMMDDHHMMSS+SS - starting time + step per track point


Use the right map!

Note that you still have to make sure you're using the right map! More about that here.


No comments:

Post a Comment