Can someone make a video tutorial of how to create & customize a routing profile (or walk through the process in much greater written detail)

I am self-taught in html, css, javascript, arcmap, qgis, leaflet, mapbox gl api, over the past four years. I have been studying and reviewing the documentation for teaching myself how to make a custom bicycle routing algorithm for graphhopper. While the documentation is extensive, it is very far from straight forward.

Can someone just put out a 15 minute video or something or anything that walks through the process of implementing a customized routing profile? Or just write up a detailed reply here and please ELi5 it (Explain it like I’m 5 years old).

What I’m trying to do… I’ve built an interactive webmap with data initially downloaded from OpenStreetMap, modified in QGIS, Uploaded to mapbox, and a webpage built in github pages that visualizes the data layers in the mapbox API… (See image below)

I want to implement my own customized bicycle routing profile that more heavy weights my curated road network and can provide AtoB directions.

As I understand broadly I need to:

  1. Setup my own local graphhopper playground to make my changes to the code
  2. change the code - specifically the weights based on the documentation here. And this is where it begins to be extremely unclear… That link says " Create a subclass of GraphHopper and overwrite createWeighting" There is no createWeighting file… Also All the files I do try to modify in intellij are read-only (even though I clicked File > Make File Writable, and Tools > Vim Emulator box is not checked)…

So I need to modify the createWeighting file? But I also need to create my own FlagEncoderFactory? But I need to extend Graphhopper before that? And it might be easier to do this in a minimum-graphhopper environment which is less confusing?

I am starting to feel very overwhelmed by the process… Please if there was more video documentation, I (and I imagine others would find it very helpful).

Thanks in advance to anyone who can help.

Hi,

I’m certainly no GraphHopper expert, but I’ve recently built trailrouter.com which uses custom weightings and a custom flag encoder quite heavily, so maybe I can give you some pointers. My app biases towards roads/paths surrounded by natural features (e.g. parks, forests, rivers, etc), so it sounds like it could be similar to what you’re doing. I’m actually using Openrouteservice rather than GraphHopper, but since Openrouteservice is built on top of GraphHopper, I know GraphHopper pretty well.

My suggestion on how to proceed would be as follows:

  1. Get GraphHopper up and running in a local IDE by following this: https://github.com/graphhopper/graphhopper/blob/master/docs/core/quickstart-from-source.md - there is actually a video linked right at the top of that page too!

  2. Try out creating a few routes by visiting http://localhost:8989/. Set a breakpoint in the code and step through it.

  3. Try tinkering with some of the features that are similar to what you want. For example, there’s an HTTP API option called “block_area” (see https://docs.graphhopper.com/#tag/Routing-API) which calls this: https://github.com/graphhopper/graphhopper/blob/7acdcf934c362ec956e2d0bc1978d5dc1df17afa/core/src/main/java/com/graphhopper/routing/weighting/BlockAreaWeighting.java - step through and see it working for yourself.

It sounds like you’re not sure on the difference between a FlagEncoder and a Weighting, which is very understandable. The way I understand it, the FlagEncoder is used to either ‘accept’ or ‘reject’ an edge (e.g. a road) or alternatively give it some high/low weight based upon some of the OSM attributes associated with it. For example, an edge that has “bicycle=no” as an attribute on it would be rejected by the cycling FlagEncoder. It might also give an edge with “highway=cycleway” a higher weight than an edge without it.

Conversely, a Weighting allows you to make weighting decisions on an individual edge by edge basis, rather than relying on the attributes associated with the edge. For example, you might want to weight towards the shortest road, or maybe the fastest, or maybe the one with least elevation gain.

Now to your actual task: You said you wanted to create your own cycling profile that more heavily weights towards your curated road network. What is your input data?

If your list of preferred roads is derived purely from OSM attributes (e.g. “highway=cycleway means I want to give it a really high preference!”) then you can just modify the existing cycling FlagEncoder and you should achieve what you want. I don’t think you need a custom Weighting really.

However, if your list is calculated somewhere else externally and you’re getting back something like a CSV of “osm_id,weight” then you will need to use a custom Weighting and a few other things to load that data and use it at runtime. The best example I can think of for this is the GreenWeighting in the Openrouteservice project - https://github.com/GIScience/openrouteservice/blob/d1e158a96f1f8053c16f5d60c49772d8c4ccf784/openrouteservice/src/main/java/org/heigit/ors/routing/graphhopper/extensions/weighting/GreenWeighting.java - this is one of weightings I use in trailrouter.com. Note that this relies on a separate storage engine loading a CSV file, it’s not just that one class.

Hope this helps,

Sam

PS. That “Create a subclass of GraphHopper and overwrite createWeighting” bit in the documentation is a typo. It should say “override createWeighting”. “override” means the same in Java as JS, which it sounds like you’re familiar with.

2 Likes

Hi Sam,

Thank you so much for your reply! Your website is incredible! The user interface, the analytics that pop up, the customization, and variation in length of route, along with the customized route generation alone! It goes to show how much more I have to learn…

Anyway your trailrouter website is in many ways very similar to what I’m trying to do bicycle commuting routes in my website www.tucsonpathways.org . What you must have coded off the OpenRouteService to automatically generate the trails you do is awesome… I’m going to unpack this message and do my best to understand what you wrote over the next week or so, and I may post a more specific question in this thread later this week.

Thanks again,
Dylan

No worries, you’re welcome. Keep me posted, happy to help if I can.

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.

Powered by Discourse