errors.add(new IllegalStateException(exMessage)); else if (exClass.equals(RuntimeException.class.getName())) errors.add(new DetailedRuntimeException(exMessage, toMap(error))); else if (exClass.equals(IllegalArgumentException.class.getName())) errors.add(new DetailedIllegalArgumentException(exMessage, toMap(error))); else if (exClass.equals(ConnectionNotFoundException.class.getName())) { errors.add(new ConnectionNotFoundException(exMessage, toMap(error))); } else if (exClass.equals(PointNotFoundException.class.getName())) { int pointIndex = error.get("point_index").asInt(); errors.add(new PointNotFoundException(exMessage, pointIndex)); } else if (exClass.equals(PointOutOfBoundsException.class.getName())) { int pointIndex = error.get("point_index").asInt(); errors.add(new PointOutOfBoundsException(exMessage, pointIndex)); } else if (exClass.isEmpty()) errors.add(new DetailedRuntimeException(exMessage, toMap(error))); else errors.add(new DetailedRuntimeException(exClass + " " + exMessage, toMap(error)));
private void checkNonChMaxWaypointDistance(List<GHPoint> points) { if (nonChMaxWaypointDistance == Integer.MAX_VALUE) { return; } GHPoint lastPoint = points.get(0); GHPoint point; double dist; DistanceCalc calc = 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; } }
private void checkIfPointsAreInBounds(List<GHPoint> points) { BBox bounds = getGraphHopperStorage().getBounds(); for (int i = 0; i < points.size(); i++) { GHPoint point = points.get(i); if (!bounds.contains(point.getLat(), point.getLon())) { throw new PointOutOfBoundsException("Point " + i + " is out of bounds: " + point, i); } } }
@Override public List<QueryResult> lookup(List<GHPoint> points, FlagEncoder encoder) { if (points.size() < 2) throw new IllegalArgumentException("At least 2 points have to be specified, but was:" + points.size()); EdgeFilter edgeFilter = DefaultEdgeFilter.allEdges(encoder); queryResults = new ArrayList<>(points.size()); for (int placeIndex = 0; placeIndex < points.size(); placeIndex++) { GHPoint point = points.get(placeIndex); QueryResult qr = null; if (ghRequest.hasPointHints()) qr = locationIndex.findClosest(point.lat, point.lon, new NameSimilarityEdgeFilter(edgeFilter, ghRequest.getPointHints().get(placeIndex))); if (qr == null || !qr.isValid()) qr = locationIndex.findClosest(point.lat, point.lon, edgeFilter); if (!qr.isValid()) ghResponse.addError(new PointNotFoundException("Cannot find point " + placeIndex + ": " + point, placeIndex)); queryResults.add(qr); } return queryResults; }
return false; if (subnetworkFrom != subnetworkTo) { throw new ConnectionNotFoundException("Connection between locations not found. Different subnetworks " + subnetworkFrom + " vs. " + subnetworkTo, new HashMap<String, Object>());
@Override public void serialize(MultiException e, JsonGenerator jsonGenerator, SerializerProvider serializerProvider) throws IOException { List<Throwable> errors = e.getErrors(); ObjectNode json = JsonNodeFactory.instance.objectNode(); json.put("message", getMessage(errors.get(0))); ArrayNode errorHintList = json.putArray("hints"); for (Throwable t : errors) { ObjectNode error = errorHintList.addObject(); error.put("message", getMessage(t)); error.put("details", t.getClass().getName()); if (t instanceof GHException) { ((GHException) t).getDetails().forEach(error::putPOJO); } } jsonGenerator.writeObject(json); }
@Override public List<QueryResult> lookup(List<GHPoint> points, FlagEncoder encoder) { if (points.size() != 1 || ghRequest.getPoints().size() != 1) throw new IllegalArgumentException("For round trip calculation exactly one point is required"); final double distanceInMeter = ghRequest.getHints().getDouble(RoundTrip.DISTANCE, 10000); final long seed = ghRequest.getHints().getLong(RoundTrip.SEED, 0L); double initialHeading = ghRequest.getFavoredHeading(0); final int roundTripPointCount = Math.min(20, ghRequest.getHints().getInt(RoundTrip.POINTS, 2 + (int) (distanceInMeter / 50000))); final GHPoint start = points.get(0); TourStrategy strategy = new MultiPointTour(new Random(seed), distanceInMeter, roundTripPointCount, initialHeading); queryResults = new ArrayList<>(2 + strategy.getNumberOfGeneratedPoints()); EdgeFilter edgeFilter = DefaultEdgeFilter.allEdges(encoder); QueryResult startQR = locationIndex.findClosest(start.lat, start.lon, edgeFilter); if (!startQR.isValid()) throw new PointNotFoundException("Cannot find point 0: " + start, 0); queryResults.add(startQR); GHPoint last = start; for (int i = 0; i < strategy.getNumberOfGeneratedPoints(); i++) { double heading = strategy.getHeadingForIteration(i); QueryResult result = generateValidPoint(last, strategy.getDistanceForIteration(i), heading, edgeFilter); if (result == null) { ghResponse.addError(new IllegalStateException("Could not find a valid point after " + maxRetries + " tries, for the point:" + last)); return Collections.emptyList(); } last = result.getSnappedPoint(); queryResults.add(result); } queryResults.add(startQR); return queryResults; }
altRsp.addError(new ConnectionNotFoundException("Connection between locations not found", Collections.<String, Object>emptyMap()));
private void checkIfPointsAreInBounds(List<GHPoint> points) { BBox bounds = getGraphHopperStorage().getBounds(); for (int i = 0; i < points.size(); i++) { GHPoint point = points.get(i); if (!bounds.contains(point.getLat(), point.getLon())) { throw new PointOutOfBoundsException("Point " + i + " is out of bounds: " + point, i); } } }
private void checkNonChMaxWaypointDistance(List<GHPoint> points) { if (nonChMaxWaypointDistance == Integer.MAX_VALUE) { return; } GHPoint lastPoint = points.get(0); GHPoint point; double dist; DistanceCalc calc = 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; } }
@Override public void serialize(MultiException e, JsonGenerator jsonGenerator, SerializerProvider serializerProvider) throws IOException { List<Throwable> errors = e.getErrors(); ObjectNode json = JsonNodeFactory.instance.objectNode(); json.put("message", getMessage(errors.get(0))); ArrayNode errorHintList = json.putArray("hints"); for (Throwable t : errors) { ObjectNode error = errorHintList.addObject(); error.put("message", getMessage(t)); error.put("details", t.getClass().getName()); if (t instanceof GHException) { ((GHException) t).getDetails().forEach(error::putPOJO); } } jsonGenerator.writeObject(json); }
private QueryResult findClosest(GHPoint point, int indexForErrorMessage) { final EdgeFilter filter = DefaultEdgeFilter.allEdges(graphHopperStorage.getEncodingManager().getEncoder("foot")); QueryResult source = locationIndex.findClosest(point.lat, point.lon, filter); if (!source.isValid()) { throw new PointNotFoundException("Cannot find point: " + point, indexForErrorMessage); } if (flagEncoder.getEdgeType(source.getClosestEdge().getFlags()) != GtfsStorage.EdgeType.HIGHWAY) { throw new RuntimeException(flagEncoder.getEdgeType(source.getClosestEdge().getFlags()).name()); } return source; }
return false; if (subnetworkFrom != subnetworkTo) { throw new ConnectionNotFoundException("Connection between locations not found. Different subnetworks " + subnetworkFrom + " vs. " + subnetworkTo, new HashMap<String, Object>());
private void checkIfPointsAreInBounds(List<GHPoint> points) { BBox bounds = getGraphHopperStorage().getBounds(); for (int i = 0; i < points.size(); i++) { GHPoint point = points.get(i); if (!bounds.contains(point.getLat(), point.getLon())) { throw new PointOutOfBoundsException("Point " + i + " is ouf of bounds: " + point, i); } } }
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; } }
@Override public List<QueryResult> lookup(List<GHPoint> points, FlagEncoder encoder) { if (points.size() < 2) throw new IllegalArgumentException("At least 2 points have to be specified, but was:" + points.size()); EdgeFilter edgeFilter = DefaultEdgeFilter.allEdges(encoder); queryResults = new ArrayList<>(points.size()); for (int placeIndex = 0; placeIndex < points.size(); placeIndex++) { GHPoint point = points.get(placeIndex); QueryResult qr = null; if (ghRequest.hasPointHints()) qr = locationIndex.findClosest(point.lat, point.lon, new NameSimilarityEdgeFilter(edgeFilter, ghRequest.getPointHints().get(placeIndex))); if (qr == null || !qr.isValid()) qr = locationIndex.findClosest(point.lat, point.lon, edgeFilter); if (!qr.isValid()) ghResponse.addError(new PointNotFoundException("Cannot find point " + placeIndex + ": " + point, placeIndex)); queryResults.add(qr); } return queryResults; }
return false; if (subnetworkFrom != subnetworkTo) { throw new ConnectionNotFoundException("Connection between locations not found. Different subnetworks " + subnetworkFrom + " vs. " + subnetworkTo, new HashMap<String, Object>());
@Override public List<QueryResult> lookup(List<GHPoint> points, FlagEncoder encoder) { if (points.size() < 2) throw new IllegalArgumentException("At least 2 points have to be specified, but was:" + points.size()); EdgeFilter edgeFilter = new DefaultEdgeFilter(encoder); queryResults = new ArrayList<>(points.size()); for (int placeIndex = 0; placeIndex < points.size(); placeIndex++) { GHPoint point = points.get(placeIndex); QueryResult res; if (ghRequest.hasPointHints()) { res = locationIndex.findClosest(point.lat, point.lon, new NameSimilarityEdgeFilter(edgeFilter, ghRequest.getPointHints().get(placeIndex))); if (!res.isValid()) { res = locationIndex.findClosest(point.lat, point.lon, edgeFilter); } } else { res = locationIndex.findClosest(point.lat, point.lon, edgeFilter); } if (!res.isValid()) ghResponse.addError(new PointNotFoundException("Cannot find point " + placeIndex + ": " + point, placeIndex)); queryResults.add(res); } return queryResults; }
altRsp.addError(new ConnectionNotFoundException("Connection between locations not found", Collections.<String, Object>emptyMap()));
@Override public List<QueryResult> lookup(List<GHPoint> points, FlagEncoder encoder) { if (points.isEmpty()) throw new IllegalStateException("For round trip calculation one point is required"); final double distanceInMeter = ghRequest.getHints().getDouble(RoundTrip.DISTANCE, 10000); final long seed = ghRequest.getHints().getLong(RoundTrip.SEED, 0L); final double initialHeading = ghRequest.getHints().getDouble(RoundTrip.HEADING, Double.NaN); final int roundTripPointCount = Math.min(20, ghRequest.getHints().getInt(Algorithms.ROUND_TRIP + ".points", 2 + (int) (distanceInMeter / 50000))); final GHPoint start = ghRequest.getPoints().get(0); TourStrategy strategy = new MultiPointTour(new Random(seed), distanceInMeter, roundTripPointCount, initialHeading); queryResults = new ArrayList<>(2 + strategy.getNumberOfGeneratedPoints()); EdgeFilter edgeFilter = new DefaultEdgeFilter(encoder); QueryResult startQR = locationIndex.findClosest(start.lat, start.lon, edgeFilter); if (!startQR.isValid()) throw new PointNotFoundException("Cannot find point 0: " + start, 0); queryResults.add(startQR); GHPoint last = points.get(0); for (int i = 0; i < strategy.getNumberOfGeneratedPoints(); i++) { double heading = strategy.getHeadingForIteration(i); QueryResult result = generateValidPoint(last, strategy.getDistanceForIteration(i), heading, edgeFilter); if (result == null) { ghResponse.addError(new IllegalStateException("Could not find a valid point after " + maxRetries + " tries, for the point:" + last)); return Collections.emptyList(); } last = result.getSnappedPoint(); queryResults.add(result); } queryResults.add(startQR); return queryResults; }