Search in sources :

Example 91 with GHRequest

use of com.graphhopper.GHRequest in project graphhopper by graphhopper.

the class RouteResourceClientHCTest method readFinishInstruction.

@ParameterizedTest
@EnumSource(value = TestParam.class)
public void readFinishInstruction(TestParam p) {
    GraphHopperWeb gh = createGH(p);
    GHRequest req = new GHRequest().addPoint(new GHPoint(42.507065, 1.529846)).addPoint(new GHPoint(42.510383, 1.533392)).putHint("vehicle", "car");
    GHResponse res = gh.route(req);
    InstructionList instructions = res.getBest().getInstructions();
    String finishInstructionName = instructions.get(instructions.size() - 1).getName();
    assertEquals("Arrive at destination", finishInstructionName);
}
Also used : InstructionList(com.graphhopper.util.InstructionList) GHRequest(com.graphhopper.GHRequest) GraphHopperWeb(com.graphhopper.api.GraphHopperWeb) GHPoint(com.graphhopper.util.shapes.GHPoint) GHResponse(com.graphhopper.GHResponse) EnumSource(org.junit.jupiter.params.provider.EnumSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 92 with GHRequest

use of com.graphhopper.GHRequest in project graphhopper by graphhopper.

the class RouteResourceClientHCTest method testPointHints.

@ParameterizedTest
@EnumSource(value = TestParam.class)
public void testPointHints(TestParam p) {
    GraphHopperWeb gh = createGH(p);
    GHRequest req = new GHRequest().addPoint(new GHPoint(42.50856, 1.528451)).addPoint(new GHPoint(42.510383, 1.533392)).setProfile("my_car");
    GHResponse response = gh.route(req);
    isBetween(890, 900, response.getBest().getDistance());
    req.setPointHints(Arrays.asList("Carrer Bonaventura Armengol", ""));
    response = gh.route(req);
    isBetween(520, 550, response.getBest().getDistance());
}
Also used : GHRequest(com.graphhopper.GHRequest) GraphHopperWeb(com.graphhopper.api.GraphHopperWeb) GHPoint(com.graphhopper.util.shapes.GHPoint) GHResponse(com.graphhopper.GHResponse) EnumSource(org.junit.jupiter.params.provider.EnumSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 93 with GHRequest

use of com.graphhopper.GHRequest in project graphhopper by graphhopper.

the class RouteResourceTest method testSnapPreventionsAndPointHints.

@Test
public void testSnapPreventionsAndPointHints() {
    GraphHopperWeb hopper = new GraphHopperWeb(clientUrl(app, "/route"));
    GHRequest request = new GHRequest(42.511139, 1.53285, 42.508165, 1.532271);
    request.setProfile("my_car");
    request.setSnapPreventions(Collections.singletonList("tunnel"));
    request.setPointHints(Arrays.asList("Avinguda Fiter i Rossell", ""));
    GHResponse rsp = hopper.route(request);
    assertFalse(rsp.hasErrors(), rsp.getErrors().toString());
    assertEquals(1590, rsp.getBest().getDistance(), 2);
    // contradicting hints should still allow routing
    request.setSnapPreventions(Collections.singletonList("tunnel"));
    request.setPointHints(Arrays.asList("Tunèl del Pont Pla", ""));
    rsp = hopper.route(request);
    assertEquals(490, rsp.getBest().getDistance(), 2);
}
Also used : GHRequest(com.graphhopper.GHRequest) GraphHopperWeb(com.graphhopper.api.GraphHopperWeb) GHResponse(com.graphhopper.GHResponse) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 94 with GHRequest

use of com.graphhopper.GHRequest in project graphhopper by graphhopper.

the class RouteResourceTest method testPathDetails.

@Test
public void testPathDetails() {
    GraphHopperWeb client = new GraphHopperWeb(clientUrl(app, "/route"));
    GHRequest request = new GHRequest(42.554851, 1.536198, 42.510071, 1.548128).setProfile("my_car");
    request.setPathDetails(Arrays.asList("average_speed", "edge_id", "time"));
    GHResponse rsp = client.route(request);
    assertFalse(rsp.hasErrors(), rsp.getErrors().toString());
    assertTrue(rsp.getErrors().isEmpty(), rsp.getErrors().toString());
    Map<String, List<PathDetail>> pathDetails = rsp.getBest().getPathDetails();
    assertFalse(pathDetails.isEmpty());
    assertTrue(pathDetails.containsKey("average_speed"));
    assertTrue(pathDetails.containsKey("edge_id"));
    assertTrue(pathDetails.containsKey("time"));
    List<PathDetail> averageSpeedList = pathDetails.get("average_speed");
    assertEquals(13, averageSpeedList.size());
    assertEquals(30.0, averageSpeedList.get(0).getValue());
    assertEquals(14, averageSpeedList.get(0).getLength());
    assertEquals(60.0, averageSpeedList.get(1).getValue());
    assertEquals(5, averageSpeedList.get(1).getLength());
    List<PathDetail> edgeIdDetails = pathDetails.get("edge_id");
    assertEquals(77, edgeIdDetails.size());
    assertEquals(882L, edgeIdDetails.get(0).getValue());
    assertEquals(2, edgeIdDetails.get(0).getLength());
    assertEquals(883L, edgeIdDetails.get(1).getValue());
    assertEquals(8, edgeIdDetails.get(1).getLength());
    long expectedTime = rsp.getBest().getTime();
    long actualTime = 0;
    List<PathDetail> timeDetails = pathDetails.get("time");
    for (PathDetail pd : timeDetails) {
        actualTime += (Long) pd.getValue();
    }
    assertEquals(expectedTime, actualTime);
}
Also used : PathDetail(com.graphhopper.util.details.PathDetail) GHRequest(com.graphhopper.GHRequest) InstructionList(com.graphhopper.util.InstructionList) GraphHopperWeb(com.graphhopper.api.GraphHopperWeb) GHResponse(com.graphhopper.GHResponse) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 95 with GHRequest

use of com.graphhopper.GHRequest in project graphhopper by graphhopper.

the class RouteResourceTest method testPathDetailsSamePoint.

@Test
public void testPathDetailsSamePoint() {
    GraphHopperWeb hopper = new GraphHopperWeb(clientUrl(app, "/route"));
    GHRequest request = new GHRequest(42.554851, 1.536198, 42.554851, 1.536198).setPathDetails(Arrays.asList("average_speed", "edge_id", "time")).setProfile("my_car");
    GHResponse rsp = hopper.route(request);
    assertFalse(rsp.hasErrors(), rsp.getErrors().toString());
    assertTrue(rsp.getErrors().isEmpty(), rsp.getErrors().toString());
}
Also used : GHRequest(com.graphhopper.GHRequest) GraphHopperWeb(com.graphhopper.api.GraphHopperWeb) GHResponse(com.graphhopper.GHResponse) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Aggregations

GHRequest (com.graphhopper.GHRequest)106 GHResponse (com.graphhopper.GHResponse)86 GHPoint (com.graphhopper.util.shapes.GHPoint)59 Test (org.junit.Test)35 Test (org.junit.jupiter.api.Test)35 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)26 GraphHopperWeb (com.graphhopper.api.GraphHopperWeb)22 ResponsePath (com.graphhopper.ResponsePath)13 EnumSource (org.junit.jupiter.params.provider.EnumSource)11 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)9 JsonNode (com.fasterxml.jackson.databind.JsonNode)8 PathWrapper (com.graphhopper.PathWrapper)8 GraphHopper (com.graphhopper.GraphHopper)7 InstructionList (com.graphhopper.util.InstructionList)7 PathDetail (com.graphhopper.util.details.PathDetail)7 GraphHopperAPI (com.graphhopper.GraphHopperAPI)6 Profile (com.graphhopper.config.Profile)5 Graph (com.graphhopper.storage.Graph)5 NodeAccess (com.graphhopper.storage.NodeAccess)5 LMProfile (com.graphhopper.config.LMProfile)4