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)));
}
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>"));
}
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());
}
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"));
}
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"));
}
Aggregations