Adding bus lanes

Hello,

I am trying to configure GraphHopper so that routing happens through bus lanes.

The specific road that I am trying to allow is: http://www.openstreetmap.org/way/8102480#map=19/52.92203/-1.47563

Currently if I used the code below any attempt to route through this street will fail.

Would really appreciate any help with this.

Here is the restrictions configuration for CarFlagEncoder.java (the only difference being the added “bus” and “psv” at the start of the restrictions array):

public CarFlagEncoder( int speedBits, double speedFactor, int maxTurnCosts )
{
    super(speedBits, speedFactor, maxTurnCosts);
    restrictions.addAll(Arrays.asList("bus", "psv", "motorcar", "motor_vehicle", "vehicle", "access"));
    restrictedValues.add("private");
    restrictedValues.add("agricultural");
    restrictedValues.add("forestry");
    restrictedValues.add("no");
    restrictedValues.add("restricted");
    restrictedValues.add("delivery");
    restrictedValues.add("military");

    intendedValues.add("yes");
    intendedValues.add("permissive");

    potentialBarriers.add("gate");
    potentialBarriers.add("lift_gate");
    potentialBarriers.add("kissing_gate");
    potentialBarriers.add("swing_gate");

    absoluteBarriers.add("bollard");
    absoluteBarriers.add("stile");
    absoluteBarriers.add("turnstile");
    absoluteBarriers.add("cycle_barrier");
    absoluteBarriers.add("motorcycle_barrier");
    absoluteBarriers.add("block");

    trackTypeSpeedMap.put("grade1", 20); // paved
    trackTypeSpeedMap.put("grade2", 15); // now unpaved - gravel mixed with ...
    trackTypeSpeedMap.put("grade3", 10); // ... hard and soft materials
    trackTypeSpeedMap.put("grade4", 5); // ... some hard or compressed materials
    trackTypeSpeedMap.put("grade5", 5); // ... no hard materials. soil/sand/grass

    badSurfaceSpeedMap.add("cobblestone");
    badSurfaceSpeedMap.add("grass_paver");
    badSurfaceSpeedMap.add("gravel");
    badSurfaceSpeedMap.add("sand");
    badSurfaceSpeedMap.add("paving_stones");
    badSurfaceSpeedMap.add("dirt");
    badSurfaceSpeedMap.add("ground");
    badSurfaceSpeedMap.add("grass");

    maxPossibleSpeed = 140;

    // autobahn
    defaultSpeedMap.put("motorway", 100);
    defaultSpeedMap.put("motorway_link", 70);
    defaultSpeedMap.put("motorroad", 90);
    // bundesstraße
    defaultSpeedMap.put("trunk", 70);
    defaultSpeedMap.put("trunk_link", 65);
    // linking bigger town
    defaultSpeedMap.put("primary", 65);
    defaultSpeedMap.put("primary_link", 60);
    // linking towns + villages
    defaultSpeedMap.put("secondary", 60);
    defaultSpeedMap.put("secondary_link", 50);
    // streets without middle line separation
    defaultSpeedMap.put("tertiary", 50);
    defaultSpeedMap.put("tertiary_link", 40);
    defaultSpeedMap.put("unclassified", 30);
    defaultSpeedMap.put("residential", 30);
    // spielstraße
    defaultSpeedMap.put("living_street", 5);
    defaultSpeedMap.put("service", 20);
    // unknown road
    defaultSpeedMap.put("road", 20);
    // forestry stuff
    defaultSpeedMap.put("track", 15);
}

Bump? Would really appreciate help with this.

You want to route this through the specific road?

Grab a small area around the street from osm.org and then debug the acceptWay method and stop when you get the specific OSM ID of the way and see why it is not accepting it. Also watch out for barriers.

Another simpler&faster method is to create a new unit test and see if the specific tag set passes the acceptWay.

Thanks Peter. It’s not just that road that we want to route through, we want to route through all lanes where the bus tag is present, so essentially the router will go through the bus lanes (the link I provided is just one bus lane as an example). Could you possibly just provide a snippet of code to show how to accept the bus tag?

Do you have any tutorials on how to set up a unit test? I’m representing a small organisation that creates bus apps and we’re not massively Java-savvy, but GraphHopper is incredibly useful for us.

If you have any documentation that would cover how to go about setting up unit testing that would be great, if not no worries.

we want to route through all lanes where the bus tag is present

Yes, sure. I meant, that you want to route through this kind of streets. Modifying GraphHopper currently needs a bit of Java knowledge, we’ll improve here hopefully soon. For now, make sure you can debug your modified flagencoder version and that it is actually used.

There are currently only a few documents about this available, e.g. here on how to create such a flag encoder.

To help you more here, we would need more specific problems or even just unit tests showing a problem or misunderstanding which we then can solve.

If you have any documentation that would cover how to go about setting up unit testing that would be great, if not no worries.

I meant just see e.g. the CarFlagEncoderTest where the access tests should show you how that would work in your case. In every Java IDE like NetBeans you can easily execute these tests with one keyboard shortcut or via maven on the CLI.