Question

I'm trying to edit the motorway speed to the user's preferences and return a route as a result of this change. I would have an input field labeled 'motorway' on the webpage's form and when submitting, this value would change the speed of all the motorways.

I have see the answer here: Does GraphHopper support dynamic edge weights? , however I would like to know how to edit all edges and through which java file.

The plan is to have user preferences for road speeds (for busy times), regularity of turnings and traffic lights. Any point in the right direction would be appreciated

Was it helpful?

Solution

By default the GraphHopper import process stores only the speed and accessibility (forward+backward) information for an edge.

So, the first step will be to create a custom FlagEncoder which stores the type of the road e.g. an integer somewhere in the long/int flags. You can use the EncodedValue class for this.

The next step is to create a custom Weighting implementation which then calculates the speed from the flag information you stored. The weighting will be called while querytime so you can take into account the user its preferences, which can be changed per query.

Note: you'll need to disable CH when you allow changing the preferences for every query

Note: this change could be valuable for the core GraphHopper, so if you implement it let us know via a pull request ;)

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top