Export Route Relations to GPX Files

In many cases it would be useful to export an OSM route relation data into a GPX track. For example, several biking and hiking routes exists as OSM relations, and the corresponding GPX track on a mobile device would make it easier to follow the route.

There are already some tools that accomplish this: https://wiki.openstreetmap.org/wiki/Relations/Relations_to_GPX

Considering that this is a very simple process (GPX is just an XML file) that does not require much processing power, would it be possible to introduce this to the main interface on the http://www.openstreetmap.org ?

For example, when the route relation is selected using http://www.openstreetmap.org/relation/ URL, then there would be “Export as GPX” link in addition to the “Download XML” and “View History” links.

The main interface is not intended to provide services like this. OSM is mainly the database itself and a lot of tools are available to duplicate the data into other servers or applications for third parties. The main site is mainly for the contributors and the maps, a showcase to appeal new contributors.

However, when you know the route relation, you can export it in OSM format. e.g. this route relation
http://www.openstreetmap.org/relation/27683

click below on “download XML”:
http://www.openstreetmap.org/api/0.6/relation/27683

on the new URL, add “/full” to retrieve all members of the relation (the ways and nodes)
http://www.openstreetmap.org/api/0.6/relation/27683/full

Now you have the route. You just need a tool to convert the OSM file format to a GPX format (search yourself).

For cycling or walking routes, you can use Waymarked Trails. http://waymarkedtrails.org/en/
Click on the routes button in the bottom right, then select the route you want. Then it has an option to export it as a GPX file.

Thanks, this was exactly what I was looking for!

I know how to do the conversion manually, but this kind of service is great for non-technical users.

The GPX tracks produced from OSM routes only work if the route topology is simple (no branches, no roundabouts, no one-way roads).

Try to ride the route “Regione Veneto I-3” (http://cycling.waymarkedtrails.org/en/?zoom=11&lat=45.47286&lon=12.63279&hill=0#)
with your GPS (I presume that the smartphone apps do the same). The GPX tack produced by the WayMarkedTrails site is composed of 148 tracks (load it into Garmin MapSource to check). This is not a specific problem of the WayMarkedTrails web site but a basic problem of expressing as GPX track a complex topology.

It is near to impossible to convert manually the GPX produced from routes with complex topology into something manageable on a GPS device.

Volker

Padova, Italy

I’m new to GPS-dedicated devices and to OSM and I was just looking for this same solution because I live in Brazil and OSM gives the perfect routes for cycling in my region. The OSM interface has two options for cycling: MapQuest and GraphHopper. I couldn’t find the option to export the relations generated through those two options, but when I tried the GraphHopper site, looking for an OSM relations export option, to my surprise I found an “Export to GPX” option instead :slight_smile:

https://graphhopper.com/maps/

The GPX export link is right below the directions input boxes.

Henrique,

I am not sure, but it seems that you use the term “route” differently from the term “route” in “route relation”.

You seem to refer to a route obtained by a routing algorithm like the one that yo find on the graphhopper page that you quote.
There are several other sites that provide this service, using different algorithms.

The topic of this thread is different: it is referring to routes as waymarked (signposted) routes for cycling (or walking). These are present in OSM in large numbers and visualised by different web sites. The discussion was about converting a route relation into a gpx file that represents exactly all ways that form the relation. Example of a bicycle route (in the US): http://cycling.waymarkedtrails.org/it/relation/53722

Volker

Surprisingly, well known tool named GPSBabel can convert OSM data files to GPX format.
The application itself can be found at http://www.gpsbabel.org/ and its online version at http://www.gpsvisualizer.com/gpsbabel/

Ensure you select “Routes” mode, otherwise you’ll get bunch of waypoints with useless osm-id names.
As input file format select “OpenStreetMap data files”
As output file format - “GPX XML”
Upload your full relation osm.xml (which can be downloaded as explained in Pieren’s comment)