use of com.graphhopper.GHResponse in project graphhopper by graphhopper.
the class GraphHopperWebTest method testReadEncoded.
// see also GraphHopperServletIT.testGraphHopperWeb for real routes against local jetty service
@Test
public void testReadEncoded() throws Exception {
Downloader downloader = new Downloader("GraphHopper Test") {
@Override
public InputStream fetch(HttpURLConnection conn, boolean readErrorStreamNoException) throws IOException {
return getClass().getResourceAsStream("test_encoded.json");
}
};
GraphHopperWeb instance = new GraphHopperWeb();
instance.setDownloader(downloader);
GHResponse rsp = instance.route(new GHRequest(52.47379, 13.362808, 52.4736925, 13.3904394));
PathWrapper arsp = rsp.getBest();
assertEquals(2138.3, arsp.getDistance(), 1e-1);
assertEquals(17, arsp.getPoints().getSize());
assertEquals(5, arsp.getInstructions().getSize());
assertEquals("(0,Geradeaus auf A 100,1268.519329705091,65237)", arsp.getInstructions().get(0).toString());
assertEquals(11, arsp.getInstructions().get(0).getPoints().size());
assertEquals(43.73595, arsp.getWaypoints().getLat(0), 1e-4);
assertEquals(7.42015, arsp.getWaypoints().getLon(0), 1e-4);
assertEquals(43.73761, arsp.getWaypoints().getLat(1), 1e-4);
}
use of com.graphhopper.GHResponse in project graphhopper by graphhopper.
the class GraphHopperOSMTest method testLoadingWithDifferentCHConfig_issue471.
@Test
public void testLoadingWithDifferentCHConfig_issue471() {
// with CH should not be loadable without CH configured
GraphHopper gh = new GraphHopperOSM().setStoreOnFlush(true).setEncodingManager(new EncodingManager("car")).setGraphHopperLocation(ghLoc).setDataReaderFile(testOsm);
gh.importOrLoad();
GHResponse rsp = gh.route(new GHRequest(51.2492152, 9.4317166, 51.2, 9.4));
assertFalse(rsp.hasErrors());
assertEquals(3, rsp.getBest().getPoints().getSize());
gh.close();
gh = new GraphHopperOSM().setStoreOnFlush(true).setCHEnabled(false).setEncodingManager(new EncodingManager("car"));
try {
gh.load(ghLoc);
assertTrue(false);
} catch (Exception ex) {
assertTrue(ex.getMessage(), ex.getMessage().startsWith("Configured graph.ch.weightings:"));
}
Helper.removeDir(new File(ghLoc));
// without CH should not be loadable with CH enabled
gh = new GraphHopperOSM().setStoreOnFlush(true).setCHEnabled(false).setEncodingManager(new EncodingManager("car")).setGraphHopperLocation(ghLoc).setDataReaderFile(testOsm);
gh.importOrLoad();
rsp = gh.route(new GHRequest(51.2492152, 9.4317166, 51.2, 9.4));
assertFalse(rsp.hasErrors());
assertEquals(3, rsp.getBest().getPoints().getSize());
gh.close();
gh = new GraphHopperOSM().setStoreOnFlush(true).setEncodingManager(new EncodingManager("car"));
try {
gh.load(ghLoc);
assertTrue(false);
} catch (Exception ex) {
assertTrue(ex.getMessage(), ex.getMessage().startsWith("Configured graph.ch.weightings:"));
}
}
use of com.graphhopper.GHResponse in project graphhopper by graphhopper.
the class GraphHopperOSMTest method testLoadOSMNoCH.
@Test
public void testLoadOSMNoCH() {
GraphHopper gh = new GraphHopperOSM().setStoreOnFlush(true).setCHEnabled(false).setEncodingManager(new EncodingManager("car")).setGraphHopperLocation(ghLoc).setDataReaderFile(testOsm);
gh.importOrLoad();
assertFalse(gh.getAlgorithmFactory(new HintsMap("fastest")) instanceof PrepareContractionHierarchies);
GHResponse rsp = gh.route(new GHRequest(51.2492152, 9.4317166, 51.2, 9.4));
assertFalse(rsp.hasErrors());
assertEquals(3, rsp.getBest().getPoints().getSize());
gh.close();
gh = new GraphHopperOSM().setStoreOnFlush(true).setCHEnabled(false).setEncodingManager(new EncodingManager("car"));
assertTrue(gh.load(ghLoc));
rsp = gh.route(new GHRequest(51.2492152, 9.4317166, 51.2, 9.4));
assertFalse(rsp.hasErrors());
assertEquals(3, rsp.getBest().getPoints().getSize());
gh.close();
gh = new GraphHopperOSM().setGraphHopperLocation(ghLoc).setDataReaderFile(testOsm).init(new CmdArgs().put("graph.flag_encoders", "car").put(Parameters.CH.PREPARE + "weightings", "no"));
assertFalse(gh.getAlgorithmFactory(new HintsMap("fastest")) instanceof PrepareContractionHierarchies);
gh.close();
}
use of com.graphhopper.GHResponse in project graphhopper by graphhopper.
the class GraphHopperWebIT method testSimpleRoute.
@Test
public void testSimpleRoute() {
// https://graphhopper.com/maps/?point=49.6724%2C11.3494&point=49.655%2C11.418
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 res = gh.route(req);
assertFalse("errors:" + res.getErrors().toString(), res.hasErrors());
PathWrapper alt = res.getBest();
isBetween(200, 250, alt.getPoints().size());
isBetween(11000, 12000, alt.getDistance());
isBetween(310, 320, alt.getAscend());
isBetween(235, 245, alt.getDescend());
isBetween(1000, 1500, alt.getRouteWeight());
// change vehicle
res = gh.route(new GHRequest(49.6724, 11.3494, 49.6550, 11.4180).setVehicle("bike"));
alt = res.getBest();
assertFalse("errors:" + res.getErrors().toString(), res.hasErrors());
isBetween(9000, 9500, alt.getDistance());
}
use of com.graphhopper.GHResponse in project graphhopper by graphhopper.
the class GraphHopperWebIT method readFinishInstruction.
@Test
public void readFinishInstruction() {
GHRequest req = new GHRequest().addPoint(new GHPoint(52.261434, 13.485718)).addPoint(new GHPoint(52.399067, 13.469238));
GHResponse res = gh.route(req);
InstructionList instructions = res.getBest().getInstructions();
String finishInstructionName = instructions.get(instructions.size() - 1).getName();
assertEquals("Arrive at destination", finishInstructionName);
}
Aggregations