Search in sources :

Example 16 with GHPoint

use of com.graphhopper.util.shapes.GHPoint in project graphhopper by graphhopper.

the class GHMatrixBatchRequester method createPointList.

protected final ArrayNode createPointList(List<GHPoint> list) {
    // new ArrayList<>(list.size())
    ArrayNode outList = factory.arrayNode(list.size());
    for (GHPoint p : list) {
        ArrayNode entry = factory.arrayNode(2);
        entry.add(p.lon);
        entry.add(p.lat);
        outList.add(entry);
    }
    return outList;
}
Also used : ArrayNode(com.fasterxml.jackson.databind.node.ArrayNode) GHPoint(com.graphhopper.util.shapes.GHPoint)

Example 17 with GHPoint

use of com.graphhopper.util.shapes.GHPoint in project graphhopper by graphhopper.

the class GraphHopperWeb method createRequest.

private Request createRequest(GHRequest request) {
    boolean tmpInstructions = request.getHints().getBool("instructions", instructions);
    boolean tmpCalcPoints = request.getHints().getBool("calc_points", calcPoints);
    String tmpOptimize = request.getHints().get("optimize", optimize);
    if (tmpInstructions && !tmpCalcPoints) {
        throw new IllegalStateException("Cannot calculate instructions without points (only points without instructions). " + "Use calc_points=false and instructions=false to disable point and instruction calculation");
    }
    boolean tmpElevation = request.getHints().getBool("elevation", elevation);
    String places = "";
    for (GHPoint p : request.getPoints()) {
        places += "point=" + round6(p.lat) + "," + round6(p.lon) + "&";
    }
    String type = request.getHints().get("type", "json");
    String url = routeServiceUrl + "?" + places + "&type=" + type + "&instructions=" + tmpInstructions + "&points_encoded=true" + "&calc_points=" + tmpCalcPoints + "&algorithm=" + request.getAlgorithm() + "&locale=" + request.getLocale().toString() + "&elevation=" + tmpElevation + "&optimize=" + tmpOptimize;
    if (!request.getVehicle().isEmpty()) {
        url += "&vehicle=" + request.getVehicle();
    }
    for (String details : request.getPathDetails()) {
        url += "&" + Parameters.DETAILS.PATH_DETAILS + "=" + details;
    }
    if (!key.isEmpty()) {
        url += "&key=" + WebHelper.encodeURL(key);
    }
    for (Map.Entry<String, String> entry : request.getHints().toMap().entrySet()) {
        String urlKey = entry.getKey();
        String urlValue = entry.getValue();
        // use lower case conversion for check only!
        if (ignoreSet.contains(toLowerCase(urlKey))) {
            continue;
        }
        if (urlValue != null && !urlValue.isEmpty()) {
            url += "&" + WebHelper.encodeURL(urlKey) + "=" + WebHelper.encodeURL(urlValue);
        }
    }
    return new Request.Builder().url(url).build();
}
Also used : GHPoint(com.graphhopper.util.shapes.GHPoint)

Example 18 with GHPoint

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

Example 19 with GHPoint

use of com.graphhopper.util.shapes.GHPoint 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);
}
Also used : InstructionList(com.graphhopper.util.InstructionList) GHRequest(com.graphhopper.GHRequest) GHPoint(com.graphhopper.util.shapes.GHPoint) GHResponse(com.graphhopper.GHResponse) Test(org.junit.Test)

Example 20 with GHPoint

use of com.graphhopper.util.shapes.GHPoint in project graphhopper by graphhopper.

the class GraphHopperWebIT method testCannotFindPointException.

@Test
public void testCannotFindPointException() {
    GHRequest req = new GHRequest().addPoint(new GHPoint(-4.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 PointNotFoundException);
}
Also used : PointNotFoundException(com.graphhopper.util.exceptions.PointNotFoundException) GHRequest(com.graphhopper.GHRequest) GHPoint(com.graphhopper.util.shapes.GHPoint) GHResponse(com.graphhopper.GHResponse) Test(org.junit.Test)

Aggregations

GHPoint (com.graphhopper.util.shapes.GHPoint)206 Test (org.junit.jupiter.api.Test)62 GHRequest (com.graphhopper.GHRequest)57 GHResponse (com.graphhopper.GHResponse)50 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)50 Test (org.junit.Test)45 LMProfile (com.graphhopper.config.LMProfile)27 Profile (com.graphhopper.config.Profile)27 CustomProfile (com.graphhopper.routing.weighting.custom.CustomProfile)27 CHProfile (com.graphhopper.config.CHProfile)26 Snap (com.graphhopper.storage.index.Snap)17 QueryResult (com.graphhopper.storage.index.QueryResult)15 GraphHopperWeb (com.graphhopper.api.GraphHopperWeb)13 ResponsePath (com.graphhopper.ResponsePath)11 ArrayList (java.util.ArrayList)11 EnumSource (org.junit.jupiter.params.provider.EnumSource)11 PathWrapper (com.graphhopper.PathWrapper)8 PointNotFoundException (com.graphhopper.util.exceptions.PointNotFoundException)8 ArgumentsSource (org.junit.jupiter.params.provider.ArgumentsSource)8 IntArrayList (com.carrotsearch.hppc.IntArrayList)6