Last week, I blogged about creating routes for a Garmin Zümo, using Google Maps and GPSBabel. The main problem that I was trying to solve, is how to create a “real” route that my Zümo will understand, built out of a minimal amount of route waypoints (that show up as such on the Zümo when navigating), rather than possibly thousands of trackpoints, that are hard to process for the device and don’t give you as much navigation flexibility.
This post is about something else, namely how to convert a GPS track (that you created by driving, downloaded somewhere, etc.) into a route, with the same criteria as last time.
Suppose you have a GPX file, containing a track. Typically, such a track contains many trackpoints. For example, a drive of about 60 km that I took a few weeks back, gave me a track consisting of over 2600 trackpoints. Now, I would like to create a route out of this track, that I can share with others.
I don’t know about you, but in my case, a track always contains some stuff that I don’t want to show up in the end result: mistakes that I made during my ride, like entering dead-end streets, or those extra meters that you make, looking for a place to park for a coffee break. Stuff like that is easily corrected with Viking, a nice GPS/track/waypoint editor, that runs on Linux (POSIX) and Windows, and is available under the GPL v2 license. Maybe later I will post something on using Viking, but that’s besides the scope of this post. Let me continue.
So, now I have a GPX, containing the exact track that I want turned into a route. We will use GPSBabel to do the conversion. The invocation is similar to the one in my previous post, but instead of using waypoints, we convert a track into a route, and we add a filter: simplify. I quote:
The Simplify filter is used to simplify routes and tracks for use with formats that limit the number of points they can contain or just to reduce the complexity of a route.
And that is exactly what we need. Simplify will let you specify a maximum number of waypoints in a route, but we will use another feature: maximum error. It allows us (and again, I quote) to specify the maximum allowable error that may be introduced by removing a single point. That means that the nuber of waypoints can be higher on more complex pieces of our route, and lower on the long stretches.
Here we go:
gpsbabel -i gpx -o gpx -f track.gpx -x transform,rte=trk -x nuketypes,waypoints,tracks -x simplify,error=0.1k -F route.gpx
In the picture, you can see the result. Click to enlarge. In orange is the original track; in green is the resulting route, with dots on the route waypoints. The map is left out for clarity.
I think that this gives us a route, that has enough waypoints not to leave much room for interpretation by the routing engine of a GPS device. My guess is, that most routing engines will calculate identical routes, regardless of your routing parameters, like shortest/quickest route. I haven’t tested this, though.
It speaks for itself, that a higher value for ‘error’ will give you less waypoints, and a lower value will give you more. For example, using ‘error=0.05k’ (50 m), gives me 109 route waypoints. If this is still acceptable, you can profit from the greater accuracy of your route.
Now, the funny thing is, that this can also be applied to tracks from Google Maps’ KML files. Please have a look at this post. So if you want to skip the labour-intensive step of creating placemarks for all your route waypoints, you can use the track instead.
The GPSBabel invocation becomes:
gpsbabel -i kml -o gpx -f Routetest.kml -x transform,rte=trk -x nuketypes,waypoints,tracks -x simplify,error=0.5k -F Routetest.gpx
- Convert KML into GPS
- Convert the track into a route
- Remove as many waypoints as possible, creating maximum error of 500 meters
- Remove tracks and waypoints from the resulting GPX, keeping only the route
With the KML file from my example (a route of some 590 km through some of the best parts of France), this will result in a route, made out of 179 route waypoints, which should be fine for a Garmin Zümo.
There is one drawback when using the track from Google as input for a route for -for example- a Garmin device. The waypoints that remain after the conversion are the result of a mathematical algorithm, and their position on the map is absolute. This means, that if there are differences between Google’s map and Garmin’s (and there are!), it can happen, that a route waypoint ends up in an unfortunate location. For example, the waypoint could end up on the other side of the highway, where traffic drives in the opposite direction.
Since the remaining waypoints will be concentrated around crossroads and curves, it is in fact quite likely that at least a few of these problems will occur.
The route on the Garmin might end up with strange loops as a result. Therefore, it is pretty essential to check the final result, either in MapSource or on your GPS device, to prevent unpleasant surprises.