Avoiding road classes and environments

It’s working now! I was stupidly overwriting the EncodingManager so killing the config. Just in case anyone might find this useful, I’m attaching a small snippet of code;

import com.graphhopper.*;
import com.graphhopper.config.Profile;
import com.graphhopper.reader.osm.GraphHopperOSM;
import com.graphhopper.util.details.PathDetail;

import java.io.IOException;
import java.util.Arrays;
import java.util.List;
import java.util.Map;

/*
    README
    wget https://oss.sonatype.org/content/groups/public/com/graphhopper/graphhopper-web/1.0/graphhopper-web-1.0.jar
    wget http://download.geofabrik.de/europe/berlin-latest.osm.pbf
    javac -cp graphhopper-web-1.0.jar TollTest.java
    java -cp ".:graphhopper-web-1.0.jar" TollTest
 */


public class TollTest {

    public static void main(String[] args) throws IOException {

        String osmFile = "berlin-latest.osm.pbf";
        String graphFolder = "berlin-graph";

        GraphHopper hopper = new GraphHopperOSM().forServer();
        hopper.setDataReaderFile(osmFile);
        hopper.init(new GraphHopperConfig().putObject("graph.flag_encoders", "car").putObject("graph.encoded_values", "road_class,road_environment,toll"));
        hopper.setGraphHopperLocation(graphFolder);
        hopper.setProfiles(new Profile("car").setVehicle("car").setWeighting("shortest"));
        hopper.importOrLoad();

        GHRequest request = new GHRequest(52.5373, 13.3603, 52.4983, 13.4066)
            .setProfile("car").setPathDetails(Arrays.asList("road_class", "road_environment", "toll"));
        GHResponse response = hopper.route(request);
        ResponsePath path = response.getBest();
        Map<String, List<PathDetail>> path_details = path.getPathDetails();

    }

}

PS: You are very right @karussell, I should have opened a new topic. Apologies! Thank you all so, so much for your kind help!!

1 Like