Search in sources :

Example 56 with GHRequest

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

the class RoutingAdditivityTest method testBoundedAdditivityOfGraphhopperTravelTimes.

@Test
public void testBoundedAdditivityOfGraphhopperTravelTimes() {
    ResponsePath route1 = graphHopper.route(new GHRequest(new GHPoint(51.23, 12.18), new GHPoint(51.45, 12.59)).setProfile("my_profile")).getBest();
    // Re-route from snapped point to snapped point.
    // It's the only way to be sure.
    ResponsePath route2 = graphHopper.route(new GHRequest(route1.getWaypoints().get(0), route1.getWaypoints().get(1)).setProfile("my_profile")).getBest();
    assertThat(route1.getTime(), is(equalTo(route2.getTime())));
    long travelTime = 0L;
    for (int i = 0; i < route2.getPoints().size() - 1; i++) {
        ResponsePath segment = graphHopper.route(new GHRequest(route2.getPoints().get(i), route2.getPoints().get(i + 1)).setProfile("my_profile")).getBest();
        travelTime += segment.getTime();
    }
    // Even though I route from node to node, and travel times are longs, not doubles,
    // I apparently don't get the exact result if I sum up the travel times between segments.
    // But it's within one second.
    assertThat(Math.abs(travelTime - route2.getTime()), is(lessThan(1000L)));
}
Also used : ResponsePath(com.graphhopper.ResponsePath) GHRequest(com.graphhopper.GHRequest) GHPoint(com.graphhopper.util.shapes.GHPoint) GHPoint(com.graphhopper.util.shapes.GHPoint) Test(org.junit.jupiter.api.Test)

Example 57 with GHRequest

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

the class RouteResourceTest method testExportWithoutTrack.

@Test
public void testExportWithoutTrack() {
    GHRequest req = new GHRequest(42.554851, 1.536198, 42.510071, 1.548128);
    req.putHint("elevation", false);
    req.putHint("instructions", true);
    req.putHint("calc_points", true);
    req.putHint("type", "gpx");
    req.putHint("gpx.track", false);
    GraphHopperWeb gh = new GraphHopperWeb(clientUrl(app, "/route")).setPostRequest(false);
    String res = gh.export(req);
    assertTrue(res.contains("<gpx"));
    assertTrue(res.contains("<rtept lat="));
    assertFalse(res.contains("<trk><name>GraphHopper Track</name><trkseg>"));
    assertTrue(res.endsWith("</gpx>"));
}
Also used : GHRequest(com.graphhopper.GHRequest) GraphHopperWeb(com.graphhopper.api.GraphHopperWeb) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 58 with GHRequest

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

the class RouteResourceTest method testInitInstructionsWithTurnDescription.

@Test
public void testInitInstructionsWithTurnDescription() {
    GraphHopperWeb hopper = new GraphHopperWeb(clientUrl(app, "/route"));
    GHRequest request = new GHRequest(42.554851, 1.536198, 42.510071, 1.548128);
    request.setProfile("my_car");
    GHResponse rsp = hopper.route(request);
    assertFalse(rsp.hasErrors(), rsp.getErrors().toString());
    assertEquals("Continue onto Carrer Antoni Fiter i Rossell", rsp.getBest().getInstructions().get(3).getName());
    request.getHints().putObject("turn_description", false);
    rsp = hopper.route(request);
    assertFalse(rsp.hasErrors());
    assertEquals("Carrer Antoni Fiter i Rossell", rsp.getBest().getInstructions().get(3).getName());
}
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 59 with GHRequest

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

the class RouteResourceTest method testGPXExport.

@Test
public void testGPXExport() {
    GHRequest req = new GHRequest(42.554851, 1.536198, 42.510071, 1.548128);
    req.putHint("elevation", false);
    req.putHint("instructions", true);
    req.putHint("calc_points", true);
    req.putHint("gpx.millis", "300000000");
    req.putHint("type", "gpx");
    GraphHopperWeb gh = new GraphHopperWeb(clientUrl(app, "/route")).setPostRequest(false);
    String res = gh.export(req);
    assertTrue(res.contains("<gpx"));
    assertTrue(res.contains("<rtept lat="));
    assertTrue(res.contains("<trk><name>GraphHopper Track</name><trkseg>"));
    assertTrue(res.endsWith("</gpx>"));
    // this is due to `gpx.millis` we set (dates are shifted by the given (ms!) value from 1970-01-01)
    assertTrue(res.contains("1970-01-04"));
}
Also used : GHRequest(com.graphhopper.GHRequest) GraphHopperWeb(com.graphhopper.api.GraphHopperWeb) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 60 with GHRequest

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

the class RouteResourceTest method testGraphHopperWeb.

@Test
public void testGraphHopperWeb() {
    GraphHopperWeb hopper = new GraphHopperWeb(clientUrl(app, "/route"));
    GHResponse rsp = hopper.route(new GHRequest(42.554851, 1.536198, 42.510071, 1.548128).setProfile("my_car"));
    assertFalse(rsp.hasErrors(), rsp.getErrors().toString());
    assertTrue(rsp.getErrors().isEmpty(), rsp.getErrors().toString());
    ResponsePath res = rsp.getBest();
    assertTrue(res.getDistance() > 9000, "distance wasn't correct:" + res.getDistance());
    assertTrue(res.getDistance() < 9500, "distance wasn't correct:" + res.getDistance());
    rsp = hopper.route(new GHRequest().setProfile("my_car").addPoint(new GHPoint(42.554851, 1.536198)).addPoint(new GHPoint(42.531896, 1.553278)).addPoint(new GHPoint(42.510071, 1.548128)));
    assertTrue(rsp.getErrors().isEmpty(), rsp.getErrors().toString());
    res = rsp.getBest();
    assertTrue(res.getDistance() > 20000, "distance wasn't correct:" + res.getDistance());
    assertTrue(res.getDistance() < 21000, "distance wasn't correct:" + res.getDistance());
    InstructionList instructions = res.getInstructions();
    assertEquals(24, instructions.size());
    assertEquals("Continue onto la Callisa", instructions.get(0).getTurnDescription(null));
    assertEquals("At roundabout, take exit 2", instructions.get(4).getTurnDescription(null));
    assertEquals(true, instructions.get(4).getExtraInfoJSON().get("exited"));
    assertEquals(false, instructions.get(22).getExtraInfoJSON().get("exited"));
}
Also used : ResponsePath(com.graphhopper.ResponsePath) InstructionList(com.graphhopper.util.InstructionList) GHRequest(com.graphhopper.GHRequest) GraphHopperWeb(com.graphhopper.api.GraphHopperWeb) GHResponse(com.graphhopper.GHResponse) GHPoint(com.graphhopper.util.shapes.GHPoint) 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