Trailforks Trail Routing

Mar 11, 2015
by Trevor May  
example ride plan

All trailforks data is now topologically correct, which means we can have full routing abilities. Check out the video demo showing how easy it is to create routes that span multiple trails, get full route elevation profile, distance, etc. A great planning tool for creating and sharing your favorite route, rides, and planning race courses.

Trailforks has a new tool called the Ride Planner, this came about while developing the upcoming "routes" feature. I wanted to create an easy method to create a route, point and click to add trails to the route. But then came the problem of how to do this, thus started the road towards routing of the Trailforks database.

I needed to create a routing topology of the trails to be used in a routing engine and then write my own routing functions. First problem is the trails on Trailforks are not a topology, they don't connect or share points, they are all just separate gps tracks. Some might visually connect, but they aren't really. So I created a system to snap start and end points of trails nearby other trails together, all automated in the backend, which saves a ton of work doing it manually. Of course its not perfect so some manual edits will be required over time. Now that I have all the trails connected, they then need to be sliced into segments at each intersection and the topology generated.

trail topology

The routing function takes into consideration a couple factors when choosing the best route. It assigns a "cost" to traverse a segment of a trail. This cost is initially set by the distance of that segment, I then can use the trails direction to modify that cost. Trails are marked as downhill, downhill only, uphill only and so on. So to route up a downhill trail will cost significantly more than going up an uphill trail, even it it's a lot longer distance. For trails that are uphill only, they will never allow routing down them, because I set the cost SUPER high. I will continue to modify factors that adjust the routing cost. Such as the avg grade, desired difficulty rating and so on.

In the Postgres database there are currently over 94,000 trail segments & 46,000 intersections that are used.

Now I needed an interface to create the routes, a point and click A to B type thing. Thus the Ride Planner was born, it was a way for me to test and develop the trail routing. But the ride planner itself turned out to be a super useful tool, so I spent some time adding features to it.


RIDE PLANNER FEATURES

The ride planner does what it says, helps plan a ride. Click to add points and let the routing engine find the best path, add & edit points until you get your desired output. Planning a ride will give you stats on how long the route will be, which trails, turn-by-turn directions and elevation chart. It will also show you the current conditions of trails along the ride and inform you of any recent trail reports that flag potential issues or closures on trails. You can then share your ride plan with friends by passing along the URL it generates, or download the GPX file and transfer to your GPS device. In the future there will be an option to view ride plans on the Trailforks mobile app.

Another great use-case is if you want to visually explain something to a friend about a trail route. You know the story... you turn right by that rock by the tree! Now with a couple clicks you can cut through the trail talk obscurity and show what you mean. Its also super useful for planning race courses, not having to think of a route and then go ride it, only to find out that route was too long or short.

detailed trail itinerary

The routing is not going to be perfect and a lot of areas won't route properly. It first relies on all the trails for an area being added to Trailforks! This includes connectors and access roads used for mtn biking. So you can help by adding any missing trails. Also some existing trails might be too far away from an intersection for the automated snapping function that runs in the background to work. If you come across a trail that should connect to another one and allow routing, you can fix the problem by editing the trail and moving the start or end point closer.

When new trails are added or edited they don't get added to the routing topology instantly. It takes some time to re-generate, so this only happens once a day.

If you have any suggestions, let me know! Otherwise start playing around with it and here is a demo video.

Views: 5,622    Faves: 12    Comments: 7


ALTERNATIVE RIDE PLANNER METHOD

Sometimes you want more control when planning a ride or demonstrating a route to someone. So there is an alternative ride planner method you can toggle that allows you to manually select each trail segment in sequence to build a route.
The ride planner will let you know if a segment doesn't connect to the previous segment. But you can continue creating a plan even if segments don't connect, the gps track will just draw a straight line between the 2 points.

create route by selecting each trail segment