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 GraphHopperOSMTest method testFootOnly.
@Test
public void testFootOnly() {
// now only footable ways are imported => no A D C and B D E => the other both ways have pillar nodes!
instance = new GraphHopperOSM().setStoreOnFlush(false).setEncodingManager(new EncodingManager("foot")).setGraphHopperLocation(ghLoc).setDataReaderFile(testOsm3);
instance.importOrLoad();
assertEquals(2, instance.getGraphHopperStorage().getNodes());
assertEquals(2, instance.getGraphHopperStorage().getAllEdges().getMaxId());
// A to E only for foot
GHResponse grsp = instance.route(new GHRequest(11.1, 50, 11.19, 52).setVehicle("foot"));
assertFalse(grsp.hasErrors());
PathWrapper rsp = grsp.getBest();
// the last points snaps to the edge
assertEquals(Helper.createPointList(11.1, 50, 10, 51, 11.194015, 51.995013), rsp.getPoints());
}
use of com.graphhopper.GHRequest in project graphhopper by graphhopper.
the class OSMReaderTest method testRoutingRequestFails_issue665.
@Test
public void testRoutingRequestFails_issue665() {
GraphHopper hopper = new GraphHopperOSM().setDataReaderFile(getClass().getResource(file7).getFile()).setEncodingManager(new EncodingManager("car,motorcycle")).setGraphHopperLocation(dir);
hopper.getCHFactoryDecorator().setEnabled(false);
hopper.importOrLoad();
GHRequest req = new GHRequest(48.977277, 8.256896, 48.978876, 8.254884).setWeighting("curvature").setVehicle("motorcycle");
GHResponse ghRsp = hopper.route(req);
assertFalse(ghRsp.getErrors().toString(), ghRsp.hasErrors());
}
use of com.graphhopper.GHRequest in project graphhopper by graphhopper.
the class GraphHopperWeb method export.
public String export(GHRequest ghRequest) {
String str = "Creating request failed";
try {
Request okRequest = createRequest(ghRequest);
str = getClientForRequest(ghRequest).newCall(okRequest).execute().body().string();
return str;
} catch (Exception ex) {
throw new RuntimeException("Problem while fetching export " + ghRequest.getPoints() + ", error: " + ex.getMessage() + " response: " + str, ex);
}
}
use of com.graphhopper.GHRequest in project graphhopper by graphhopper.
the class GraphHopperWeb method route.
@Override
public GHResponse route(GHRequest request) {
try {
Request okRequest = createRequest(request);
ResponseBody rspBody = getClientForRequest(request).newCall(okRequest).execute().body();
JsonNode json = objectMapper.reader().readTree(rspBody.byteStream());
rspBody.close();
GHResponse res = new GHResponse();
res.addErrors(readErrors(json));
if (res.hasErrors())
return res;
JsonNode paths = json.get("paths");
boolean tmpInstructions = request.getHints().getBool("instructions", instructions);
boolean tmpCalcPoints = request.getHints().getBool("calc_points", calcPoints);
boolean tmpElevation = request.getHints().getBool("elevation", elevation);
boolean tmpTurnDescription = request.getHints().getBool("turn_description", turnDescription);
for (JsonNode path : paths) {
PathWrapper altRsp = createPathWrapper(path, tmpCalcPoints, tmpInstructions, tmpElevation, tmpTurnDescription, !request.getPathDetails().isEmpty());
res.add(altRsp);
}
return res;
} catch (Exception ex) {
throw new RuntimeException("Problem while fetching path " + request.getPoints() + ": " + ex.getMessage(), ex);
}
}
Aggregations