Search in sources :

Example 1 with PointDistanceExceededException

use of com.graphhopper.util.exceptions.PointDistanceExceededException in project graphhopper by graphhopper.

the class GraphHopper method checkNonChMaxWaypointDistance.

private void checkNonChMaxWaypointDistance(List<GHPoint> points) {
    if (nonChMaxWaypointDistance == Integer.MAX_VALUE) {
        return;
    }
    GHPoint lastPoint = points.get(0);
    GHPoint point;
    double dist;
    DistanceCalc calc = Helper.DIST_3D;
    for (int i = 1; i < points.size(); i++) {
        point = points.get(i);
        dist = calc.calcDist(lastPoint.getLat(), lastPoint.getLon(), point.getLat(), point.getLon());
        if (dist > nonChMaxWaypointDistance) {
            Map<String, Object> detailMap = new HashMap<>(2);
            detailMap.put("from", i - 1);
            detailMap.put("to", i);
            throw new PointDistanceExceededException("Point " + i + " is too far from Point " + (i - 1) + ": " + point, detailMap);
        }
        lastPoint = point;
    }
}
Also used : PointDistanceExceededException(com.graphhopper.util.exceptions.PointDistanceExceededException) GHPoint(com.graphhopper.util.shapes.GHPoint) GHPoint(com.graphhopper.util.shapes.GHPoint)

Example 2 with PointDistanceExceededException

use of com.graphhopper.util.exceptions.PointDistanceExceededException in project graphhopper by graphhopper.

the class GraphHopperIT method testMonacoNonChMaxWaypointDistanceMultiplePoints.

@Test
public void testMonacoNonChMaxWaypointDistanceMultiplePoints() {
    GHPoint from = new GHPoint(43.741069, 7.426854);
    GHPoint via = new GHPoint(43.744445, 7.429483);
    GHPoint to = new GHPoint(43.727697, 7.419199);
    GHRequest req = new GHRequest().addPoint(from).addPoint(via).addPoint(to).setVehicle(vehicle).setWeighting("fastest");
    // Fail since points are too far
    hopper.setNonChMaxWaypointDistance(1000);
    GHResponse rsp = hopper.route(req);
    assertTrue(rsp.hasErrors());
    PointDistanceExceededException exception = (PointDistanceExceededException) rsp.getErrors().get(0);
    assertEquals(2, exception.getDetails().get("to"));
    // Suceed since points are not far anymore
    hopper.setNonChMaxWaypointDistance(Integer.MAX_VALUE);
    rsp = hopper.route(req);
    assertFalse(rsp.hasErrors());
}
Also used : PointDistanceExceededException(com.graphhopper.util.exceptions.PointDistanceExceededException) GHPoint(com.graphhopper.util.shapes.GHPoint)

Aggregations

PointDistanceExceededException (com.graphhopper.util.exceptions.PointDistanceExceededException)2 GHPoint (com.graphhopper.util.shapes.GHPoint)2