Prohibiting U-Turns in GraphHopper Core

Currently I am working on defining route without using U-Turns except when it is completely necessary (etc. It should not be prohibited on the dead end street as vehicle is unable to do U-Turn in the middle of the narrow street ). I saw many examples, however I could not achieve proper results.Below is code snippet that I used. Dependency that I am using is:

implementation ‘com.graphhopper:graphhopper-reader-osm:2.4’

Map that I am using is:

https://download.geofabrik.de/europe/serbia-latest.osm.pbf

What I used as reference:
https://github.com/graphhopper/graphhopper/blob/master/docs/core/turn-restrictions.md
https://docs.graphhopper.com/#operation/getRoute/pass_through

CODE SNIPPET

@Component
@Getter
public class GraphHopperProvider {
    GraphHopper graphHopper;

    public GraphHopperProvider(@Value("${arg.graphhopper.osm.map}") String graphHopperMap,
                               @Value("${arg.graphhopper.osm.base}") String graphHopperBase) {

        GraphHopper gh = new GraphHopperOSM().forServer().setDataReaderFile(graphHopperMap)
                .setGraphHopperLocation(graphHopperBase)
                .setMinNetworkSize(200)
                .setEncodingManager(EncodingManager.create("car|turn_costs=true|edge_based=true|restriction=no_u_turn"));
        gh.getCHPreparationHandler().setPreparationThreads(Runtime.getRuntime().availableProcessors());
        Profile profile = new Profile("car").setVehicle("car").setWeighting("fastest");

        gh.setProfiles(profile);
        graphHopper = gh.importOrLoad();
    }
}

I figured out that I can use GraphHopper request object as solution, for example:

            GHRequest ghRequest = new GHRequest().setPoints(allPointCoordinates.stream().map(e -> new GHPoint(e.getLatitude(), e.getLongitude())).collect(Collectors.toList())).setProfile("car")
                    .putHint(Parameters.CH.DISABLE, true)
                    .putHint(Parameters.Routing.PASS_THROUGH, true)
                    .putHint(Parameters.Routing.HEADING_PENALTY, 300)
                    .setSnapPreventions(List.of("motorway", "trunk", "tunnel", "bridge"));

However, I would like to set this restriction on my vehicle profile, in this case “car”, or on GraphHopper object.

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