Search in sources :

Example 1 with OSMMaxSpeedParser

use of com.graphhopper.routing.util.parsers.OSMMaxSpeedParser in project graphhopper by graphhopper.

the class GraphHopperTest method simplifyWithInstructionsAndPathDetails.

@Test
public void simplifyWithInstructionsAndPathDetails() {
    final String profile = "profile";
    GraphHopper hopper = new GraphHopper();
    hopper.getEncodingManagerBuilder().setEnableInstructions(true).add(new OSMMaxSpeedParser()).add(new CarFlagEncoder());
    hopper.setOSMFile(BAYREUTH).setProfiles(new Profile(profile).setVehicle("car").setWeighting("fastest")).setGraphHopperLocation(GH_LOCATION);
    hopper.importOrLoad();
    GHRequest req = new GHRequest().addPoint(new GHPoint(50.026932, 11.493201)).addPoint(new GHPoint(50.016895, 11.4923)).addPoint(new GHPoint(50.003464, 11.49157)).setProfile(profile).setPathDetails(Arrays.asList("street_name", "max_speed"));
    req.putHint("elevation", true);
    GHResponse rsp = hopper.route(req);
    assertFalse(rsp.hasErrors(), rsp.getErrors().toString());
    ResponsePath path = rsp.getBest();
    // check path was simplified (without it would be more like 58)
    assertEquals(41, path.getPoints().size());
    // check instructions
    InstructionList instructions = path.getInstructions();
    int totalLength = 0;
    for (Instruction instruction : instructions) {
        totalLength += instruction.getLength();
    }
    assertEquals(40, totalLength);
    assertInstruction(instructions.get(0), "KU 11", "[0, 4[", 4, 4);
    assertInstruction(instructions.get(1), "B 85", "[4, 16[", 12, 12);
    // via instructions have length = 0, but the point list must not be empty!
    assertInstruction(instructions.get(2), "", "[16, 17[", 0, 1);
    assertInstruction(instructions.get(3), "B 85", "[16, 32[", 16, 16);
    assertInstruction(instructions.get(4), "", "[32, 34[", 2, 2);
    assertInstruction(instructions.get(5), "KU 18", "[34, 37[", 3, 3);
    assertInstruction(instructions.get(6), "St 2189", "[37, 38[", 1, 1);
    assertInstruction(instructions.get(7), "", "[38, 40[", 2, 2);
    // finish instructions have length = 0, but the point list must not be empty!
    assertInstruction(instructions.get(8), "", "[40, 41[", 0, 1);
    // check max speeds
    List<PathDetail> speeds = path.getPathDetails().get("max_speed");
    assertDetail(speeds.get(0), "null [0, 4]");
    assertDetail(speeds.get(1), "70.0 [4, 6]");
    assertDetail(speeds.get(2), "100.0 [6, 31]");
    assertDetail(speeds.get(3), "80.0 [31, 32]");
    assertDetail(speeds.get(4), "null [32, 37]");
    assertDetail(speeds.get(5), "50.0 [37, 38]");
    assertDetail(speeds.get(6), "null [38, 40]");
    // check street_names
    List<PathDetail> streetNames = path.getPathDetails().get("street_name");
    assertDetail(streetNames.get(0), "KU 11 [0, 4]");
    assertDetail(streetNames.get(1), "B 85 [4, 32]");
    assertDetail(streetNames.get(2), " [32, 34]");
    assertDetail(streetNames.get(3), "KU 18 [34, 37]");
    assertDetail(streetNames.get(4), "St 2189 [37, 38]");
    assertDetail(streetNames.get(5), " [38, 40]");
}
Also used : CustomProfile(com.graphhopper.routing.weighting.custom.CustomProfile) Profile(com.graphhopper.config.Profile) CHProfile(com.graphhopper.config.CHProfile) LMProfile(com.graphhopper.config.LMProfile) GHPoint(com.graphhopper.util.shapes.GHPoint) PathDetail(com.graphhopper.util.details.PathDetail) OSMMaxSpeedParser(com.graphhopper.routing.util.parsers.OSMMaxSpeedParser) GHPoint(com.graphhopper.util.shapes.GHPoint) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Aggregations

CHProfile (com.graphhopper.config.CHProfile)1 LMProfile (com.graphhopper.config.LMProfile)1 Profile (com.graphhopper.config.Profile)1 OSMMaxSpeedParser (com.graphhopper.routing.util.parsers.OSMMaxSpeedParser)1 CustomProfile (com.graphhopper.routing.weighting.custom.CustomProfile)1 PathDetail (com.graphhopper.util.details.PathDetail)1 GHPoint (com.graphhopper.util.shapes.GHPoint)1 Test (org.junit.jupiter.api.Test)1 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)1