Preparation

Co-ordinates

The first task that has to happen is to read the gpx file containing the routes of the 5 walks. gpx is a specific namespace inside the XML specification and needs a suitable package To handle it. In order to bypass the specifics of XML the data is extracted and accumulated int0 standard javascript objects.

The other thing that has to be managed is that in GPX the position of the waypoints is specified in degrees of latitude and longitude. This is fine for displaying the routes on open street map using leaflet.js but it can’t be used to calculate distances accurately. For instance, 1° of longitude at the equator is 111km decreasing to 0 at the polls.
A set of code obtained from the internet is used to map the waypoints to OSmaps eastings and northings (usually referred to as x and y in the code). The original latitude and longitude is retained because it is needed to display the resulting segments on the map.

Tags

Sometimes the routes have multiple points very close together and not always progressing along the route. I think of them as resembling skin tags, hence the name. I go all long each of the route and remove any points that are too close to their neighbour. It simplified thing a bit in developing the code but I’m not sure that it is absolutely necessary.

Self Overlapping Routes

This view of a small section of the grasmere walk shows the sort of thing we have to handle.

The same path being walked along 5 times and each time it is encoded differently. More importantly, walks 2 & 3 are there twice and so we need to start by simplifying each route to remove any overlap with itself.

In this case, walk 2 did a circular, finishing by entering the town by the same route as it left.

Walk 3 is more complex, because it has a common part in the middle of the walk but used different roads to leave and re-enter Grasmere. We’ll use to illustrate the process.

To find overlaps within the same walk we use a variation of the process described in the previous section. We need to compare the walk with itself. Just doing that in the normal way every point would match because they are the same walks.

The way around this is to make a copy of the walk but with all the waypoints reversed. i.e. we begin by comparing the start of the route with it’s end. In the case of walk starting and finishing along the same track, this approach quickly produces a result.

If we think of these as A and B, then the normal process would be to take each point on A and test it against every point on B looking for a match. That needs modifying because it would eventually hit the same point from the other direction and so match with itself.

The modification is, when working our way along B we stop the search when we get to a point or two before reaching the same point on A. e.g. If there are 100 points on the walk and we currently on the 10th point of A then we stop searching along B at 88th point.This way we never compare a point with it self and only find genuine overlaps in the route.

This is the result of doing this with walk 3.

As with the normal process, the first and last segments may not exist. In the middle, are 3 segments instead of 1. The last of these is the repeat of the first and is replaced by it.