Search in sources :

Example 1 with GraphHopperAPI

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

the class GraphHopperServletIT method testGraphHopperWeb.

@Test
public void testGraphHopperWeb() throws Exception {
    GraphHopperAPI hopper = new com.graphhopper.api.GraphHopperWeb();
    assertTrue(hopper.load(getTestRouteAPIUrl()));
    GHResponse rsp = hopper.route(new GHRequest(42.554851, 1.536198, 42.510071, 1.548128));
    assertFalse(rsp.getErrors().toString(), rsp.hasErrors());
    assertTrue(rsp.getErrors().toString(), rsp.getErrors().isEmpty());
    PathWrapper arsp = rsp.getBest();
    assertTrue("distance wasn't correct:" + arsp.getDistance(), arsp.getDistance() > 9000);
    assertTrue("distance wasn't correct:" + arsp.getDistance(), arsp.getDistance() < 9500);
    rsp = hopper.route(new GHRequest().addPoint(new GHPoint(42.554851, 1.536198)).addPoint(new GHPoint(42.531896, 1.553278)).addPoint(new GHPoint(42.510071, 1.548128)));
    assertTrue(rsp.getErrors().toString(), rsp.getErrors().isEmpty());
    arsp = rsp.getBest();
    assertTrue("distance wasn't correct:" + arsp.getDistance(), arsp.getDistance() > 20000);
    assertTrue("distance wasn't correct:" + arsp.getDistance(), arsp.getDistance() < 21000);
    List<Map<String, Object>> instructions = arsp.getInstructions().createJson();
    assertEquals(26, instructions.size());
    assertEquals("Continue onto la Callisa", instructions.get(0).get("text"));
    assertEquals("At roundabout, take exit 2", instructions.get(4).get("text"));
    assertEquals(true, instructions.get(4).get("exited"));
    assertEquals(false, instructions.get(24).get("exited"));
}
Also used : PathWrapper(com.graphhopper.PathWrapper) GraphHopperAPI(com.graphhopper.GraphHopperAPI) GHRequest(com.graphhopper.GHRequest) GHResponse(com.graphhopper.GHResponse) GHPoint(com.graphhopper.util.shapes.GHPoint) Map(java.util.Map) Test(org.junit.Test)

Example 2 with GraphHopperAPI

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

the class GraphHopperServletIT method testInitInstructionsWithTurnDescription.

@Test
public void testInitInstructionsWithTurnDescription() {
    GraphHopperAPI hopper = new com.graphhopper.api.GraphHopperWeb();
    assertTrue(hopper.load(getTestRouteAPIUrl()));
    GHRequest request = new GHRequest(42.554851, 1.536198, 42.510071, 1.548128);
    GHResponse rsp = hopper.route(request);
    assertEquals("Continue onto Carrer Antoni Fiter i Rossell", rsp.getBest().getInstructions().get(3).getName());
    request.getHints().put("turn_description", false);
    rsp = hopper.route(request);
    assertEquals("Carrer Antoni Fiter i Rossell", rsp.getBest().getInstructions().get(3).getName());
}
Also used : GraphHopperAPI(com.graphhopper.GraphHopperAPI) GHRequest(com.graphhopper.GHRequest) GHResponse(com.graphhopper.GHResponse) Test(org.junit.Test)

Example 3 with GraphHopperAPI

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

the class GraphHopperServletIT method testPathDetails.

@Test
public void testPathDetails() throws Exception {
    GraphHopperAPI hopper = new com.graphhopper.api.GraphHopperWeb();
    assertTrue(hopper.load(getTestRouteAPIUrl()));
    GHRequest request = new GHRequest(42.554851, 1.536198, 42.510071, 1.548128);
    request.setPathDetails(Arrays.asList("average_speed", "edge_id", "time"));
    GHResponse rsp = hopper.route(request);
    assertFalse(rsp.getErrors().toString(), rsp.hasErrors());
    assertTrue(rsp.getErrors().toString(), rsp.getErrors().isEmpty());
    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(9, 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(3759L, edgeIdDetails.get(0).getValue());
    assertEquals(2, edgeIdDetails.get(0).getLength());
    assertEquals(881L, 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 : GraphHopperAPI(com.graphhopper.GraphHopperAPI) PathDetail(com.graphhopper.util.details.PathDetail) GHRequest(com.graphhopper.GHRequest) List(java.util.List) GHResponse(com.graphhopper.GHResponse) Test(org.junit.Test)

Example 4 with GraphHopperAPI

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

the class GraphHopperServletIT method testPathDetailsNoConnection.

@Test
public void testPathDetailsNoConnection() throws Exception {
    GraphHopperAPI hopper = new com.graphhopper.api.GraphHopperWeb();
    assertTrue(hopper.load(getTestRouteAPIUrl()));
    GHRequest request = new GHRequest(42.542078, 1.45586, 42.537841, 1.439981);
    request.setPathDetails(Arrays.asList("average_speed"));
    GHResponse rsp = hopper.route(request);
    assertTrue(rsp.getErrors().toString(), rsp.hasErrors());
}
Also used : GraphHopperAPI(com.graphhopper.GraphHopperAPI) GHRequest(com.graphhopper.GHRequest) GHResponse(com.graphhopper.GHResponse) Test(org.junit.Test)

Example 5 with GraphHopperAPI

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

the class GraphHopperServletIT method testPathDetailsSamePoint.

@Test
public void testPathDetailsSamePoint() throws Exception {
    GraphHopperAPI hopper = new com.graphhopper.api.GraphHopperWeb();
    assertTrue(hopper.load(getTestRouteAPIUrl()));
    GHRequest request = new GHRequest(42.554851, 1.536198, 42.554851, 1.536198);
    request.setPathDetails(Arrays.asList("average_speed", "edge_id", "time"));
    GHResponse rsp = hopper.route(request);
    assertFalse(rsp.getErrors().toString(), rsp.hasErrors());
    assertTrue(rsp.getErrors().toString(), rsp.getErrors().isEmpty());
}
Also used : GraphHopperAPI(com.graphhopper.GraphHopperAPI) GHRequest(com.graphhopper.GHRequest) GHResponse(com.graphhopper.GHResponse) Test(org.junit.Test)

Aggregations

GHRequest (com.graphhopper.GHRequest)6 GHResponse (com.graphhopper.GHResponse)6 GraphHopperAPI (com.graphhopper.GraphHopperAPI)6 Test (org.junit.Test)6 GHPoint (com.graphhopper.util.shapes.GHPoint)2 PathWrapper (com.graphhopper.PathWrapper)1 PathDetail (com.graphhopper.util.details.PathDetail)1 List (java.util.List)1 Map (java.util.Map)1