use of com.graphhopper.GHRequest in project graphhopper by graphhopper.
the class GraphHopperWebIT method testPathDetails.
@Test
public void testPathDetails() {
GHRequest req = new GHRequest().addPoint(new GHPoint(49.6724, 11.3494)).addPoint(new GHPoint(49.6550, 11.4180));
req.getPathDetails().add("average_speed");
GHResponse res = gh.route(req);
assertFalse("errors:" + res.getErrors().toString(), res.hasErrors());
PathWrapper alt = res.getBest();
assertEquals(1, alt.getPathDetails().size());
List<PathDetail> details = alt.getPathDetails().get("average_speed");
assertFalse(details.isEmpty());
assertTrue((Double) details.get(0).getValue() > 20);
assertTrue((Double) details.get(0).getValue() < 70);
}
use of com.graphhopper.GHRequest in project graphhopper by graphhopper.
the class GraphHopperWebIT method testOutOfBoundsException.
@Test
public void testOutOfBoundsException() {
GHRequest req = new GHRequest().addPoint(new GHPoint(-400.214943, -130.078125)).addPoint(new GHPoint(39.909736, -91.054687));
GHResponse res = gh.route(req);
assertTrue("no erros found?", res.hasErrors());
assertTrue(res.getErrors().get(0) instanceof PointOutOfBoundsException);
}
use of com.graphhopper.GHRequest in project graphhopper by graphhopper.
the class GraphHopperWebIT method testCreateGPXFromInstructionList.
@Test
public void testCreateGPXFromInstructionList() {
GHRequest req = new GHRequest().addPoint(new GHPoint(49.6724, 11.3494)).addPoint(new GHPoint(49.6550, 11.4180));
req.getHints().put("elevation", false);
req.getHints().put("instructions", true);
req.getHints().put("calc_points", true);
GHResponse ghResponse = gh.route(req);
String gpx = ghResponse.getBest().getInstructions().createGPX();
assertTrue(gpx.contains("<gpx"));
assertTrue(gpx.contains("<rtept lat="));
assertTrue(gpx.contains("<trk><name>"));
assertTrue(gpx.endsWith("</gpx>"));
}
use of com.graphhopper.GHRequest in project graphhopper by graphhopper.
the class GraphHopperOSMTest method testGetPathsDirectionEnforcement3.
@Test
public void testGetPathsDirectionEnforcement3() {
instance = createSquareGraphInstance(false);
// Start in middle of edge 4-5
GHPoint start = new GHPoint(0.0015, 0.002);
// End at middle of edge 2-3
GHPoint end = new GHPoint(0.002, 0.0005);
// Via Point betweeen 8-7
GHPoint via = new GHPoint(0.0005, 0.001);
GHRequest req = new GHRequest().addPoint(start).addPoint(via, 0.).addPoint(end);
GHResponse response = new GHResponse();
List<Path> paths = instance.calcPaths(req, response);
assertFalse(response.hasErrors());
assertEquals(IntArrayList.from(9, 5, 6, 7, 11), paths.get(0).calcNodes());
}
use of com.graphhopper.GHRequest in project graphhopper by graphhopper.
the class GraphHopperOSMTest method testFootAndCar.
@Test
public void testFootAndCar() {
// now all ways are imported
instance = new GraphHopperOSM().setStoreOnFlush(false).setEncodingManager(new EncodingManager("car,foot")).setCHEnabled(false).setGraphHopperLocation(ghLoc).setDataReaderFile(testOsm3);
instance.importOrLoad();
assertEquals(5, instance.getGraphHopperStorage().getNodes());
assertEquals(8, instance.getGraphHopperStorage().getAllEdges().getMaxId());
// A to D
GHResponse grsp = instance.route(new GHRequest(11.1, 50, 11.3, 51).setVehicle("car"));
assertFalse(grsp.hasErrors());
PathWrapper rsp = grsp.getBest();
assertEquals(3, rsp.getPoints().getSize());
// => found A and D
assertEquals(50, rsp.getPoints().getLongitude(0), 1e-3);
assertEquals(11.1, rsp.getPoints().getLatitude(0), 1e-3);
assertEquals(51, rsp.getPoints().getLongitude(2), 1e-3);
assertEquals(11.3, rsp.getPoints().getLatitude(2), 1e-3);
// A to D not allowed for foot. But the location index will choose a node close to D accessible to FOOT
grsp = instance.route(new GHRequest(11.1, 50, 11.3, 51).setVehicle("foot"));
assertFalse(grsp.hasErrors());
rsp = grsp.getBest();
assertEquals(2, rsp.getPoints().getSize());
// => found a point on edge A-B
assertEquals(11.680, rsp.getPoints().getLatitude(1), 1e-3);
assertEquals(50.644, rsp.getPoints().getLongitude(1), 1e-3);
// A to E only for foot
grsp = instance.route(new GHRequest(11.1, 50, 10, 51).setVehicle("foot"));
assertFalse(grsp.hasErrors());
rsp = grsp.getBest();
assertEquals(2, rsp.getPoints().size());
// A D E for car
grsp = instance.route(new GHRequest(11.1, 50, 10, 51).setVehicle("car"));
assertFalse(grsp.hasErrors());
rsp = grsp.getBest();
assertEquals(3, rsp.getPoints().getSize());
}
Aggregations