Filter ways using relations on a new Flag Encoder


I’ve started making a bus flag encoder.
I want my path to follow only the ways which have a bus route relation (“route” : “bus”).

I don’t really understant why something like this doesn’t work ?

public long handleRelationTags(long oldRelationFlags, ReaderRelation relation) {
if (relation.hasTag("route", "bus")) {
      code = PriorityCode.BEST.getValue();
           code = PriorityCode.WORST.getValue();

int oldCode = (int) relationCodeEncoder.getValue(oldRelationFlags);
if (oldCode < code)
    return relationCodeEncoder.setValue(0, code);
return oldRelationFlags;


Are there any ways to get a relation object from a ReaderWay object so I can adapt the code above on the getAccess method ?

I hope you can help me on this problem.

And a last thing. Is there a more detailled doc than this about making Flag Encoders ?
Thank you !

I’m parsing the relations and I just found out that some Bus Route relation are not found, do you know why ?
For example, from OSM, 45.4656, 6.9613
When I print every relations on HandleRelationTags, the ones on this way are not found.
On 45.4507, 6.9767 it only find the “Train Rouge” one. The other bus routes are not found.
Any idea why ?

One last question:
How can I edit the code so the path follow only one bus route ?


in your example you are just altering the priority. But all other edges/ways also exist. If GH has no other way, it also uses the worst edges. Due to bus lane not creating a coherent graph it is nether a posibility to throw away all other eges expcpt for bus ones.

Also there is the fact that you pointed out. GH wold not follow one Bus-route in paticular. GH sees all busrouts and can switch routes whenever it is beneficial.

I would use a complete different approch.

I wrote a programm that searches all bus-routes and saves them with their id. If a pedestian wants to use the bus I calculate the eucledian distance to all Bus-Stops and choose the start, end stop with the least walking.
I than get all Busstops inbetween and do a GHReuest with a round-trip to all these stops. I also use a own encoder to allow the use of retricted road that cars are normaly not allowed to use.
The optimal route that GH response is to 95% the official bus-route in OSM.

This is a hacky way and it is more sutible to use the GH-GTFS reader, but the disatwantage is that not every city provides GTFS files. Currently we are thinking about to generate our own GTFS files form OSM and some made up scheduling.

Bus routing is complex. We are still working on our approches to find the best solution.

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