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: 8,456    Faves: 13    Comments: 9


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


Author Info:
canadaka avatar

Member since Jun 8, 2010
29 articles

97 Comments
  • 30 1
 That's awesome! Such a great tool for exploring new areas. I can't wait to see what Trailforks comes up with next! Thanks Trevor!
  • 10 1
 At first I was apprehensive over this whole idea but now I kinda want to get a smartphone. This is really cool.
  • 8 1
 @scott-townes: 27yo and no smartphone? Kudos.
  • 8 1
 Ill be honest. I have no idea what anybody is talking about.
  • 7 1
 @chrisingrassia thanks! my plan is only 20 bucks a month and my phone can last 4 days on a single charge. i highly recommend it.
  • 1 0
 If you want a cheap smart phone plan, I'd look into Republic Wireless, $10 per month unlimited talk and text, and you can pay more if you want data. Great way to have a smartphone and not feel like you are getting mugged every month.
  • 22 1
 GIS GEEKOUT
  • 2 0
 ESRI is based in the town i live in and i imagined all the folk down there getting moist on this post haha
  • 4 0
 Out-freaking-standing. PB not only has amazing content and photographers, but some seriously talented folks writing teh codez - that snapping segment start/end points together is no easy problem! And the route-planning is killer. Would be great to see kind of a hybrid of the two modes, where you could select a bunch of segments that you want to ride and have it fill in the rest (or give multiple options, or find the way to connect them with the least climbing, least distance, etc.) This is essentially how I use Strava but in a much more manual way - I find the bits of trails I want to ride (usually downhills) and end up browsing rides that include those segments to try to find interesting ways of connecting them.

Hopefully features like this are going to inspire more folks to contribute!

Just promise to say no when Strava comes looking to hire you and/or buy out Trailforks.
  • 3 0
 Thanks! There is so many cool things we can do with more and more data.

I do the same thing, but with Trailforks! if I find a new trail I wanna ride, goto the "Ridelogs" tab on that trails page, to see others rides that included that trail. Its better than looking at a trail segment because you see all the other trail names and the trail map.
www.trailforks.com/trails/entrails-929/ridelogs
  • 2 0
 Very nice. I love that you can overlay the OSM data too. You guys should really stateofthemap.us/talk
  • 2 0
 Probably too busy & late this year, but I subscribed to their newsletter for next year. I have heard of the event, bad timing as I might be in PA for a week in May.
We do do a bunch of background stuff with OSM data, and trails can be exported in OSM format by regional admins. One can also bulk import trails using an OSM file. One of the trail data fields is also the osm-way ID, which I might do some syncing with in the future.
  • 4 0
 @canadaka any way you can layer in the strava heat map and potentially route off trails? Also, can i view the created/saved routes on my phone through the mobile site and follow along during my ride?
  • 9 0
 Strava doesn't make their Heatmap available via an API, their image tiles used to be publicly accessible, but they closed. But we have a better solution, we generate our own Heatmaps! www.pinkbike.com/photo/11581963
We just haven't made them public, we are trying to filter out heatmap data around illegal trails. This relies on locals adding illegal trails into the database and marking them hidden. So definitely in the future I can overlay our heatmap on the ride planner.

We are slowly working on the mobile map app, it will have integration with this ride planner. But in the meantime, I can certainly make saved ride plans available on the mobile website, good idea. I should be able to wipe that up tonight.
  • 2 0
 @canadaka Makes sense about the heat mapping, certainly have to be careful. Good to hear you can make them available on the mobile site, i'll have to give it a go! Very excited for the mobile map app... waiting patiently! Keep up the amazing work!!!
  • 8 0
 @canadaka "we are trying to filter out heatmap data around illegal trails.". Thanks for that respect. So refreshing as opposed to Strava's tone-deafnesses
  • 3 0
 As much as I hate Strava, you can opt out of Heat Maps... "settings>privacy>opt out of heatmaps". Spreading the word!
  • 1 0
 This looks like it could well replace strava lol!!!! Something you might want to do is when you hit the clear route icon is have your map come back to the spot you where mapping instead of going back to downtown, Awesome job!
  • 2 0
 Thx jaydawg69 but i get the vibe that too many strava users just dont care Frown
  • 6 0
 Sounds like GIS speak to me. Points, lines, polygons, raster, spatial analyst, least cost path, model builder...Good job!
  • 6 0
 Holy fuck guys. I'm speechless. Once the app exists, I don't see why I'd ever need another resource again.
  • 6 0
 Pinkbike its been amazing seeing you evolve over the years. Nothing but respect.
  • 2 0
 Thanks Steve!
  • 2 0
 It would awesome for race planning if you could create different colors to indicate different sections. For example "climbing" = red, "down, or timed" = blue. Then to also have the ability to assign more colors for a second lap that might use some of the same trails. This way it is much easier to follow. Directional arrows embedded along the route would be awesome as well.

It would also be cool if you could mark or indicate the timed sections, climbing sections etc on the elevation profile, and the trail names would pop up as you scroll along the course.
  • 1 0
 I'm already working on a way to indicate timed sections along a route. Arrows get a bit tricky, can get messy looking fast. If you make a ride plan using the 2nd "selecting" method and save it, there is some subtle arrows on that. I like the idea of somehow showing the trails along the elevation chart, gunna hafta think about that one!
  • 2 0
 It would be awesome from a trail managers perspective if suggested routes can be incorporated. There is always a real disconnect between showing trail classification and showing a suggested route.
  • 4 0
 The "routes" feature which uses the same tool as the ride planner is live on the site this weekend, just not announced yet Wink
www.trailforks.com/routes
Routes are for adding suggested rides & race courses to riding areas.
  • 1 0
 Some trails that I ride regularly are not part of the global trail map. For example: www.trailforks.com/ridelog/view/867570
It shows up as "Vail Lake" which is another trail system one city over. How can I add trail systems to your data base? I'm dismayed that Riverside County shows so few trails when I know many exist. Help?

p.s. I met a very cool Trail Forks / Pinkbike guy on the Zen Trail in Saint George. Think his name was Jason? He was visiting after attending Interbike back in September. Anyway, I'm amazed at all the capability of the Trail Forks app. Thank you for your efforts!!
  • 1 0
 Cool idea. I gave it a try however I couldn't get it to work; it never picked the trail that I wanted when going point to point, and when going by trail it missed segments. It would be alot easier if I could drag and drop route markers after pressing esc (like google maps) but I couldn't get this to work. Also every time it messed up and I would clear it by hitting "celar route" it would reset the map to my IP location, so to try again I had to navigate back to the trail area.
Not trying to be negative as I think its a fantastic idea, but I think it will need some refining before it will replace regular maps + strava/trailforks info for me.
  • 2 0
 UI is still in progress. If you want to specifically create a route without it auto routing in a weird way, you can use the "Create route by: Selecting Trails" method that is in the top right corner. This will allow you to choose each segment, even going up trails if you want. This method is more time consuming, but you get to create exactly what you want.
  • 1 0
 If you don't want the map to load back at your IP location, load the planner map from a region page first. there is a green "go to region" search on the right. But most won't do this, so I will change the clear route button to remember your current map location, thanks for the feedback.

You can add route markers after you've pressed ESC, click and drag anywhere along the blue route to create a new marker.
  • 1 0
 hitting clear route now saves your current map location
  • 1 0
 Here is a trail I did last Friday. How do you show how much elevation gained/descended total? It would be nice to show where you are not connected from the Warn.

www.trailforks.com/ridelog/planner/?lat=49.3134&lng=-122.8287&z=16&edges=82723,73838,92159,4859,43836,43835,79321,43840,43841,43845,86251,-4866,4864,4863,4862,4861,86697,4849
  • 1 0
 you can click the "load elevation chart" button under the map to see some of the elevation data. But I will add those numbers to the route stats in the top right. They will only be calculated when you saved a route though. Hopefully will get to that tonight.
  • 1 0
 amazing work on TF. You should be quite proud of it.
  • 1 0
 Nice work! It would be great if you can make the "cost function" customizable by the user. This will allow the user to get the "best" route that is "best" from his perspective Smile I am assuming you modelled the problem as a "Shortest path problem"..
  • 2 0
 Yah I want to add user customization, let limit the trail difficulty allowed, or max grade, popular trails. This is just the first release, hence the Beta title. Shortest Path Dijkstra is used for the routing.
  • 1 0
 Cool, sounds like the future is exiting! There are lots of cool things you can do with the data being added to trailforks.. I have to admit that I'm jealous!
  • 1 0
 This is interesting, seeing much greater potential for the site, goes beyond Strava in many ways.

One idea/suggestion I have is to provide a means for users to hold friendly races, where any number of designated stages can be aggregated, within a given date range, and other filters (like gender, age, etc) so that a report/view could be run with results. Obviously with GPS, accuracy is pretty bad, but still, it could be fun to throw a casual enduro, dh, or xc event using tools on this site. I've thought about this a bit and would be glad to expand on the idea if you want to explore it...
  • 3 0
 Its something I've thought about and will probably do in the future. The routes feature is also live now but i'm expanding on it more now, to specify times sections of a route.
  • 1 0
 Still I don't get the difference between TRAIL and ROUTE, a route is pavement or flat road to get into a trail? So what about a trail get into a road and then into a trail againd and then a road? I don't get it, maybe is a translation issue.
  • 1 0
 "A "route" is a collection of trails joined together creating a suggested way to ride."
  • 1 0
 @canadaka: So why my trail "trailforks.com/trails/los-tanques" is showed as a route? is only a ONE trail up and down in another way... Is the same type of "trailforks.com/trails/cerro-fortuna/"... I'm confused.
  • 1 0
 @canadaka
This looks great, nice work Smile

I am always looking for something to help me find my way..

Can I ask how far away an app is Smile not looking for a commitment, just an anticipated timeline Smile
  • 2 0
 2015, lol
  • 1 0
 Well its something to look forward to Smile
  • 1 0
 i can't watch the video as im in work but my main thing i would like for this is for there to be user rated trail difficulties so you can opt in/out of harder trails. especially for the "illegally" built trails.
  • 1 0
 With routes only going off trails, if there is an access trail that we don't want to map out but use for a race route. Could I add a trail as private and then create a route using those trails mixed in?
  • 2 0
 This is great. I need to get busy using it for the Toonie maps. Can I save these and keep the status private so friends that follow me don't get a sneak peak while I build?
  • 1 0
 Saved ride plans are not listed anywhere on the site, except for the block listing your own saved plans. There isn't really anyway for users to discover ride plans. But you can share the URL to a saved ride plan with others, they are public accessible.
No activity feed item is created, nor any PB dashboard notice.

"Routes" are separate from the ride planner and are listed on the site, you would create a permanent route page after you've decided on a route that you may have experimented with using the ride planner tool. A route is like a trail or any other normal content type on the site, it contains many fields and is attached to the region hierarchy. Ride plans are just for personal use.

When you goto add a "route" it uses the same sort of interface as the ride planner. I will add the option to convert a ride plan to a route.
  • 1 0
 made some progress on adding more route features, you can not specify sections/stages on a route and assign a colour. They are shown on the elevation chart & map.
Example: http://www.trailforks.com/route/2014-nsmba-toonie-7/map/
  • 1 0
 @canadaka This is great. For Seymour Toonies we stage at Park Gate park and ride a paved path an a tiny section of Ann Macdonald way. Can I add these in as a section of trail to show the full route?
  • 2 0
 Lol "topologically correct". I think he means topographically correct, unless the maps are in fact accurate in terms of their open sets now...
  • 4 1
 I believe the usage of "topologically correct" is the correct one in this case. Yes, we are saying that all the trails are actually interconnected as a topological space/set. This is the concept necessary to allow us to do routing.
  • 5 0
 ahaha fair enough. I act like a pedantic asshole and get schooled like one. Cheers
  • 5 1
 No I meant Topological. "The name topological map is derived from topology, the branch of mathematics". With routing you convert lat/lon lines into a "Network Topology" (links & nodes). OpenStreetMap uses a topological data structure.
It has nothing to do with "TopoGRAPHY" which is like contour lines, shape & surface of the earth. Maybe the term "topologically correct" isn't the right phrasing to use, what its meant to convey is that the trails are now a network topology.
  • 2 0
 Awesome tool! I've noticed that after completing the route and loading the elevation profile, the elevation doesn't line up with the corresponding point on the trail.
  • 2 0
 thanks for the report, something funky is going on, the lat/lon is correct with the yellow marker, but the elevation is totally bonkers!
  • 1 0
 It doesn't seem totally bonkers. It seems like some sort of distance scaling of offset problem.
  • 1 0
 the elevation profile should be fixed now
  • 1 0
 As a programmer and mtn biker, I've gotta give props to these guys. That's some difficult engineering. I was working on an app myself, but eff that nonsense. These guys have it down.
  • 1 0
 @canadaka what data set(s) are you using for elevation profiles? NED 3 Meter? Will you incorporate LIDAR DEMs if possible?

Thanks for the hard work! This is a great tool!
  • 2 0
 We currently only use Google Elevation API for elevation profile data, I believe Google uses SRTM data. We are in the process of creating our own basemaps with basic contours and will be using some NASA data for that.
  • 3 0
 Hi @canadaka, I work in the GIS field myself and this is a very neet application you got/working onSmile )
You should have a look at the CDED data from Canada Naturals Resources:
geogratis.cgdi.gc.ca/geogratis/DownloadDirectory?lang=en

they have a better accuracy then SRTM, free of charge and under the Open Government Licence (you can Copy, modify, publish, translate, adapt, distribute or otherwise use the Information in any medium, mode or format for any lawful purpose.)
open.canada.ca/en/open-government-licence-canada

cheers
  • 1 0
 Is that a purple triangle trail difficulty? Haven't seen that in OZ. Where does that fit in with black diamond and blue square?
  • 2 0
 we use that for access roads
  • 1 0
 Edit - Got the answer! Pretty awesome that you can make a plan so easily and then download it to a GPS for exploring unfamiliar areas.
  • 3 0
 of course
  • 1 0
 Not sure if this is possible, but what if it could automatically pull data from google maps or something so it would automatically have streets and forest road data?
  • 3 0
 it's something I've considered, but that road data for the entire world is pretty massive. And there is a lot of overlap, data in OSM is so poorly tagged a lot of the time as well, hard to filter out what we need. I have a solution in mind, might be awhile though.
  • 1 0
 Cool, Good luck
  • 1 0
 This is pretty incredible! I'm heading out to BC soon. This will definitely help me make the most of what's there!
  • 1 0
 Sounds like a great feature, should try on my coming rides. Thanks for all this'd great work
  • 1 0
 are all segments gpx derived or has any gvt data been imported from those databases?
sick topology brotendo!
  • 1 0
 Not sure what "gvt" is? Government? But all the segments are from the trails in the Trailforks database only. Data is stored in MySQL & Postgres in a mixture of formats for different purposes. Raw Lat/lon CSV, WKT & EncodedPath's.
We are working on our own custom Trailforks basemap, specific for mountain biking. That will use some government sources for data.
  • 1 0
 Yeah, government. I was asking what types of data your system has. I inquire about gvt data because this is generally high resolution data (and free) as apposed to data collected from phones or garmins, which is very low precision.
I'm excited to see the new basmap
Thx!
  • 2 0
 Trailforks > sliced bread.
  • 1 0
 Sweet, how can we add local trail maps and riding areas from small towns that are not listed on the web site?
  • 1 0
 Trailforks trails and riding areas are user generated, so you can add the GPS data yourself, from a dedicated device or a smartphone.

www.trailforks.com/contribute/trail
  • 1 0
 First step is to add your local riding areas as a "region". Then you add trails to it. Some trails don't belong to a trail network, in that case they just get added to the nearest city. Most cities and towns are in the Pinkbike database already so can be selected when adding a trail. A "region" on Trailforks might not exist for it yet, but it will be auto-generated when the first trail is added to that city.
  • 1 0
 @canadaka I'd like to add some trails to the site. Do I have to use strave or are there some other options?
  • 1 0
 many options. You can add by uploading a GPX or KML file. You can connect your Strava account and crop from one of your rides. There is even a bulk upload tool if you have all the trails in an area already assembled in a KML or OSM data file. Making it fast to add many trails at once. You can even manually draw a trail while using a satellite view map as a guide.
  • 1 0
 impressive to say the least. i believe this here to be benchmark and revolutionary.
  • 1 0
 @canadaka when will these maps be able to show my current gps location?
  • 2 0
 most maps whether viewing a region or trail page have a green "expand" button to view in fullscreen. When in fullscreen there is a locate me button in the bottom right. You can also use the mobile website and there is a locate me button in the bottom right as well. m.trailforks.com
  • 1 0
 Amazing work!! Keep it up!
  • 2 0
 Nice work T.
  • 1 0
 Looks sweet!
  • 1 0
 Very cool.
  • 1 3
 You can already do this with strava
Below threshold threads are hidden







Copyright © 2000 - 2024. Pinkbike.com. All rights reserved.
dv56 0.074180
Mobile Version of Website