Avoid ferries with Java Code

Hello guys,

I already saw this announcement:

I tried it with this example:
https://graphhopper.com/maps/?point=49.969632%2C7.914028&point=49.979594%2C7.930254&locale=de&vehicle=car&weighting=fastest&elevation=true&details=max_speed&details=toll&debug=true&instructions=false&avoid=ferry&ch.disable=true&use_miles=true&layer=Omniscale

Even though I set “avoid=ferry”, Graphhopper still uses the ferry in the given example.
Did I do something wrong? Is there also a way to avoid ferries in Java Code and not by GET request?

Help would be much appreciated.
Best regards

Welcome to the GraphHopper community :slight_smile:

For those flexible queries you currently need to add “&ch.disable=true” additionally to “&avoid=ferry”. Does this help?

Hello karussell,

thanks for your reply. I already did that, didn’t I? I set “avoid=ferry&ch.disable=true” in my example above, but it still didn’t work.

Best regards

Ah, sorry. I missed that. The problem here is that it is only “avoid ferry” and not “exclude ferry”. I.e. if the detour without the ferry would be too long it still uses the ferry. Excluding ferries is currently only possible for a dedicated setup. For more details about this please contact us per Email.

Thank you for your help. I am using a dedicated setup. I tried excluding ferries by writing my own Encoder:

public class NoFerryCarFlagEncoder extends CarFlagEncoder {
     public NoFerryCarFlagEncoder(int speedBits, int speedFactor, int maxTurnCosts) {
          super(speedBits, speedFactor, maxTurnCosts);
     }
     @Override
     public EncodingManager.Access getAccess(ReaderWay way) {
          if (way.hasTag("route", ferries))
	     return EncodingManager.Access.CAN_SKIP;

          return super.getAccess(way);
     }
}

But I’m not sure if this is the proper way to do it. At least it seemed to work and the routing service didn’t use the ferry.

Best regards