Custom model - road_access == private

Hiya,

I thought I had a solution for private road access but it appears not :frowning:
Is this the correct method to add private road access for foot vehicle? GH 4.0

customModel model = new CustomModel();
model.addToPriority(If("road_access == PRIVATE", MULTIPLY, 1.0));

graphHopper.setProfiles(Arrays.asList(
                    new CustomProfile("van").setCustomModel(new CustomModel(model)).setVehicle("car").setTurnCosts(true).putHint("u_turn_costs", 3),
                    new CustomProfile("newWalk").setCustomModel(new CustomModel(model)).setVehicle("foot")
                ));

image

Thanks,

Do you want to exclude roads with road_access=private for your model? If yes you need to multiply the priority by 0, not 1. Multiplying by 1 has no effect.

1 Like

I think the requirement is to include private roads, which are excluded by default. Currently this is only possible on the encoder level:

graph.flag_encoders=foot|block_private=false

Or for Java:

encoder = new FootFlagEncoder(new PMap().put("block_private", false));
1 Like

Ah, thanks guys. I confused myself by thinking 0 disables and 1 enables.
But 0 x 1 is still …[checks notes]… 0 facepalm

How is this implemented in v4? Are there any examples?
Is it a case of having to use GraphHopperStorage in order to implement the Encoding Manager?

Or can you add the FlagEncoder somehow to GraphHopper object?

        GraphHopper hopper = new GraphHopper();
        hopper.getEncodingManagerBuilder()
                      .add(new FootFlagEncoder(new PMap().put("block_private", false));
        hopper.setOSMFile("berlin.osm.pbf");
        hopper.setProfiles(new CustomProfile("foot").setVehicle("foot").setCustomModel(model));
        hopper.importOrLoad();
1 Like