use of com.graphhopper.GHRequest in project graphhopper by graphhopper.
the class GraphHopperWebTest method testCreateURL.
@Test
public void testCreateURL() throws Exception {
Downloader downloader = new Downloader("GraphHopper Test") {
@Override
public String downloadAsString(String url, boolean readErrorStreamNoException) throws IOException {
assertFalse(url.contains("xy"));
assertFalse(url.contains("algo1"));
assertTrue(url.contains("alternative_route.max_paths=4"));
assertEquals("https://graphhopper.com/api/1/route?point=52.0,13.0&point=52.0,14.0&&type=json&instructions=true&points_encoded=true&calc_points=true&algorithm=&locale=en_US&elevation=false&key=blup&alternative_route.max_paths=4", url);
return Helper.isToString(getClass().getResourceAsStream("test_encoded.json"));
}
};
GraphHopperWeb instance = new GraphHopperWeb();
instance.setKey("blup");
instance.setDownloader(downloader);
GHRequest req = new GHRequest(52, 13, 52, 14);
// should be ignored, use GraphHopperWeb or GHRequest directly instead
req.getHints().put("key", "xy");
req.getHints().put("algorithm", "algo1");
req.getHints().put("alternative_route.max_paths", "4");
instance.route(req);
}
use of com.graphhopper.GHRequest 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.GHRequest 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.GHRequest 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.GHRequest 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());
}
Aggregations