Tuesday, 3 June 2014

GPX Traces of Long Distance Routes

This post is personal reminder of how to extract GPX Track data from OpenStreetMap.

The UK is full of long distance routes you might want to follow using your GPS.  That could be anything from walking trails like the Pennine Way; parts of the National Cycle Network; or even bus routes.

The most reliable way to follow any recreational route on a GPS is to use a GPX Track. That is just a series of dots joined up with straight lines and drawn over the top of any base map your GPS might have.  Utilising a track instead of a route means your GPS doesn't try to do any clever routing like a car GPS would.

Track data can be tricky to find. But OpenStreetMap can come to the rescue.

OSM Data. A quick primer: 

OpenStreetMap is a database of:
  • Waypoints - single positions with a precise location.
  • Ways - a series of Waypoints that make up any path, road etc. Note that a single road might be split into multiple Ways.
  • Relations - a series of Ways joined together to make a route. Eg Icknield Way. These would typically be over different roads.
  • Waypoints, Ways, and Relations all have key=value pairs to describe what they are.
What I am describing in this page is taking a relation (eg Pennine Way) and converting its collection of Ways (that contain Waypoints) to a single continuous set of Waypoints that can be saved as a Track in a GPX file. Your GPS can then draw those Waypoints/Track as a line over your map for you to follow.

Finding a Relation

If you see a route (Relation) on OpenStreetMap you need to find its database number.  Here's an example, The Pennine Way. Its OpenStreetMap Relation 63872.

A very useful source of Long Distance Path data is in OpenStreetMap's Wiki: UK Long Distance Paths. The Relation number is in the fourth column. Click it to view in OSM.

Another way is on OpenStreetMap itself. If you know a path has a route going over it - lets say you've found a part of the Peddars Way - zoom right in as far as you can (example).  Click the Layers icon on the right hand side. Tick checkbox Map Data, and wait for the lines to be highlighted. Click on line you were looking at. A Panel on the left appears telling you about the line. Scroll to the bottom, and there might be a "Part of Relation ..." listed.  The number is the Relation number you are hunting for.  In the example I gave, that line has two Relations. Peddars Way (walking route) 77958 and Peddars Cycle Way 3144936.

Conversion Process

The overview of the conversion process is:

  1. Get OSM data for one Relation (eg Peddars Way) with its Way and Waypoint data. 
  2. Join the Ways into a single line.
  3. Delete unnecessary key/value attribute data. Delete the Relation.
  4. Save data and convert to GPX Track.
I use JOSM, a powerful OpenStreetMap editor written in Java to do this job. 

Using JOSM

Start JOSM with no data loaded. 
Load your relation data. Choose File -> Download Object.  
In Object ID type in the Relation number you were hunting for.
I leave "Download Referrers" unticked.  
It is important to tick "Download Relation Members".
Click the Download Object Button.

You should now be in the Map view with the shape of your Relation visible.  This normally consists of a number of separate Ways.  You can zoom in and click a line to highlight a single Way.  Note they have a direction - some ways will be pointing in the opposite direction.  We are going to join them together into one single continuous Way.

Highlight everything.  Choose Selection->Select All, or easier press Control-A. Alternatively, zoom out and draw a box around everything.

To make it easy to join all the Ways together. We'll delete the data attributes.  On the right is a Panel titled Tags / Memberships.  The second column probably says <different>.  Delete all the Tags.  You can do this one at a time; highlight the first then shift-click the last; or highlight one, press Control-A to select all, then Delete.

Now we'll check the relation for gaps and fix. One the right, find the "Relations" panel. Highlight the route, and click the pencil button.  This view shows the Ways that are in the relation. Note they are not always in the right order.  Scroll through the list of Ways, most of them will have arrows in the 3rd column, look for any with red squares. You can also highlight in one Way, right click and choose Select Next Gap to make this easier.

If there are any gaps, right click the row, choose Zoom To. In the Main map view, choose the draw line tool and click the squares at each end of the gaps to join. Press escape to stop drawing.  Go back to the Relation editor and repeat.

If you've got this far, you should consider learning how to make a real fix to the data and submit it back, it's not much more work.

If you are certain you've got a contiguous line.  Delete the Relation, highlight it in the panel and Delete.  This leaves just the Ways on the Map view.

Back in the main map window, we'll now join the Ways into one. Make sure all Ways are highlighted (Control-A).  Now join all Ways together, by choosing Tools->Combine Way.  If the lines were contiguous, you'll probably be asked to Reverse and Combine. Do it.  

If this fails, your line is not contiguous. If you get asked complicated questions about tags you didn't delete them, or you may have not deleted the Relation they belonged to.

You might want to change the direction of your Track. See Tools->Reverse Way.

You should name your Way (Track) at this point. Highlight it, in the Tags panel click add.  Key=name Value=<something>

Now export to GPX.  File->Save As.  Name your file <something>.gpx.

If your map data was only that one Way and no relation data it should have exported as a GPX Track which you can use in your GPS.

I like to check my tracks in using OpenRouteConverter.  This program will show multiple tracks, allow you to edit them, join them; and convert from GPX routes to tracks. 

Alternative Export using OSM Route Manager

There is one online tool that looks like it attempts to automate the above process.  I've found in practice it doesn't do a complete job and you have to fix the results in another tool. I use OpenRouteConverter to fix up.

Check out OpenStreetMap Route Manager.

It's fairly obvious how to use it.  Click the plus icon(s) before exporting.

The relation you want might come in (unjoined) sections.

  • The sections are not nicely ordered so piece together in the right way. Each section might have a different direction. You can fix that in OpenRouteConverter.   
  • Each section might have a different direction. OpenRouteConverter can fix this.
  • You can use OpenRouteConverter to join the sections.
  • I've found Route Manager exports as GPX Route. You can use OpenRouteConverter to make this into a GPX Track. 

1 comment:

    Work from home theory is fast gaining popularity because of the freedom and flexibility that comes with it. Since one is not bound by fixed working hours, they can schedule their work at the time when they feel most productive and convenient to them. Women & Men benefit a lot from this concept of work since they can balance their home and work perfectly. People mostly find that in this situation, their productivity is higher and stress levels lower. Those who like isolation and a tranquil work environment also tend to prefer this way of working. Today, with the kind of communication networks available, millions of people worldwide are considering this option.

    Women & Men who want to be independent but cannot afford to leave their responsibilities at home aside will benefit a lot from this concept of work. It makes it easier to maintain a healthy balance between home and work. The family doesn't get neglected and you can get your work done too. You can thus effectively juggle home responsibilities with your career. Working from home is definitely a viable option but it also needs a lot of hard work and discipline. You have to make a time schedule for yourself and stick to it. There will be a time frame of course for any job you take up and you have to fulfill that project within that time frame.

    There are many things that can be done working from home. A few of them is listed below that will give you a general idea about the benefits of this concept.

    This is the most common and highly preferred job that Women & Men like doing. Since in today's competitive world both the parents have to work they need a secure place to leave behind their children who will take care of them and parents can also relax without being worried all the time. In this job you don't require any degree or qualifications. You only have to know how to take care of children. Parents are happy to pay handsome salary and you can also earn a lot without putting too much of an effort.

    For those who have a garden or an open space at your disposal and are also interested in gardening can go for this method of earning money. If given proper time and efforts nursery business can flourish very well and you will earn handsomely. But just as all jobs establishing it will be a bit difficult but the end results are outstanding.

    Freelance can be in different wings. Either you can be a freelance reporter or a freelance photographer. You can also do designing or be in the advertising field doing project on your own. Being independent and working independently will depend on your field of work and the availability of its worth in the market. If you like doing jewellery designing you can do that at home totally independently. You can also work on freelancing as a marketing executive working from home. Wanna know more, email us on workfromhome.otr214428@gmail.com and we will send you information on how you can actually work as a marketing freelancer.

    Internet related work
    This is a very vast field and here sky is the limit. All you need is a computer and Internet facility. Whatever field you are into work at home is perfect match in the software field. You can match your time according to your convenience and complete whatever projects you get. To learn more about how to work from home, contact us today on workfromhome.otr@gmail.comand our team will get you started on some excellent work from home projects.

    Diet food
    Since now a days Women & Men are more conscious of the food that they eat hence they prefer to have homemade low cal food and if you can start supplying low cal food to various offices then it will be a very good source of income and not too much of efforts. You can hire a few ladies who will help you out and this can be a good business.

    Thus think over this concept and go ahead.