Search in sources :

Example 6 with GHRequest

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();
}
Also used : CmdArgs(com.graphhopper.util.CmdArgs) PrepareContractionHierarchies(com.graphhopper.routing.ch.PrepareContractionHierarchies) GHRequest(com.graphhopper.GHRequest) GraphHopper(com.graphhopper.GraphHopper) GHResponse(com.graphhopper.GHResponse) Test(org.junit.Test)

Example 7 with GHRequest

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());
}
Also used : PathWrapper(com.graphhopper.PathWrapper) GHRequest(com.graphhopper.GHRequest) GHResponse(com.graphhopper.GHResponse) Test(org.junit.Test)

Example 8 with GHRequest

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());
}
Also used : GHRequest(com.graphhopper.GHRequest) GraphHopper(com.graphhopper.GraphHopper) GHResponse(com.graphhopper.GHResponse) Test(org.junit.Test)

Example 9 with GHRequest

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);
    }
}
Also used : Request(okhttp3.Request) GHRequest(com.graphhopper.GHRequest)

Example 10 with GHRequest

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);
    }
}
Also used : PathWrapper(com.graphhopper.PathWrapper) Request(okhttp3.Request) GHRequest(com.graphhopper.GHRequest) JsonNode(com.fasterxml.jackson.databind.JsonNode) GHResponse(com.graphhopper.GHResponse) ResponseBody(okhttp3.ResponseBody)

Aggregations

GHRequest (com.graphhopper.GHRequest)50 Test (org.junit.Test)43 GHResponse (com.graphhopper.GHResponse)42 GHPoint (com.graphhopper.util.shapes.GHPoint)26 PathWrapper (com.graphhopper.PathWrapper)13 GraphHopperAPI (com.graphhopper.GraphHopperAPI)6 GraphHopper (com.graphhopper.GraphHopper)4 CHGraph (com.graphhopper.storage.CHGraph)3 Graph (com.graphhopper.storage.Graph)3 NodeAccess (com.graphhopper.storage.NodeAccess)3 CmdArgs (com.graphhopper.util.CmdArgs)3 IOException (java.io.IOException)3 FastestWeighting (com.graphhopper.routing.weighting.FastestWeighting)2 Weighting (com.graphhopper.routing.weighting.Weighting)2 LocationIndex (com.graphhopper.storage.index.LocationIndex)2 LocationIndexTree (com.graphhopper.storage.index.LocationIndexTree)2 QueryResult (com.graphhopper.storage.index.QueryResult)2 Downloader (com.graphhopper.util.Downloader)2 InstructionList (com.graphhopper.util.InstructionList)2 PathDetail (com.graphhopper.util.details.PathDetail)2