public boolean contains(Circle c) { double res = radiusInMeter - c.radiusInMeter; if (res < 0) { return false; } return calc.calcDist(lat, lon, c.lat, c.lon) <= res; }
public static int calcIndexSize(BBox graphBounds) { if (!graphBounds.isValid()) throw new IllegalArgumentException("Bounding box is not valid to calculate index size: " + graphBounds); double dist = DIST_EARTH.calcDist(graphBounds.maxLat, graphBounds.minLon, graphBounds.minLat, graphBounds.maxLon); // convert to km and maximum is 50000km => 1GB dist = Math.min(dist / 1000, 50000); return Math.max(2000, (int) (dist * dist)); }
@GET public Response doGet(@QueryParam("point") GHPoint point, @QueryParam("elevation") @DefaultValue("false") boolean elevation) { QueryResult qr = index.findClosest(point.lat, point.lon, EdgeFilter.ALL_EDGES); if (qr.isValid()) { GHPoint3D snappedPoint = qr.getSnappedPoint(); double[] coordinates = hasElevation && elevation ? new double[]{snappedPoint.lon, snappedPoint.lat, snappedPoint.ele} : new double[]{snappedPoint.lon, snappedPoint.lat}; return new Response(coordinates, calc.calcDist(point.lat, point.lon, snappedPoint.lat, snappedPoint.lon)); } else { throw new WebApplicationException("Nearest point cannot be found!"); } }
void initAlgo(int lat, int lon) { this.latSize = lat; this.lonSize = lon; BBox b = graph.getBounds(); keyAlgo = new LinearKeyAlgo(lat, lon).setBounds(b); double max = Math.max(distCalc.calcDist(b.minLat, b.minLon, b.minLat, b.maxLon), distCalc.calcDist(b.minLat, b.minLon, b.maxLat, b.minLon)); maxRasterWidth2InMeterNormed = distCalc.calcNormalizedDist(max / Math.sqrt(getCapacity()) * 2); // as long as we have "dist < PI*R/2" it is save to compare the normalized distances instead of the real // distances. because sin(x) is only monotonic increasing for x <= PI/2 (and positive for x >= 0) }
void queryIndex(Graph g, LocationIndex idx, double lat, double lon, double expectedDist) { QueryResult res = idx.findClosest(lat, lon, EdgeFilter.ALL_EDGES); if (!res.isValid()) { errors.add("node not found for " + lat + "," + lon); return; } GHPoint found = res.getSnappedPoint(); double dist = distCalc.calcDist(lat, lon, found.lat, found.lon); if (Math.abs(dist - expectedDist) > .1) { errors.add("queried lat,lon=" + (float) lat + "," + (float) lon + " (found: " + (float) found.lat + "," + (float) found.lon + ")" + "\n expected distance:" + expectedDist + ", but was:" + dist); } }
final double calcMinDistance(double queryLat, double queryLon, GHIntHashSet pointset) { double min = Double.MAX_VALUE; Iterator<IntCursor> itr = pointset.iterator(); while (itr.hasNext()) { int node = itr.next().value; double lat = nodeAccess.getLat(node); double lon = nodeAccess.getLon(node); double dist = distCalc.calcDist(queryLat, queryLon, lat, lon); if (dist < min) { min = dist; } } return min; }
continue; double dist = distCalc.calcDist(q.start.lat, q.start.lon, q.end.lat, q.end.lon); if (dist < tooShortDistance) { skippedTooShort++;
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 double approximate(int fromNode) { double fromLat = nodeAccess.getLatitude(fromNode); double fromLon = nodeAccess.getLongitude(fromNode); double dist2goal = distanceCalc.calcDist(toLat, toLon, fromLat, fromLon); double weight2goal = weighting.getMinWeight(dist2goal); return weight2goal * epsilon; }
distSum.addAndGet(dist); airDistSum.addAndGet((long) distCalc.calcDist(fromLat, fromLon, toLat, toLon));
public double calcDistance(DistanceCalc calc) { double prevLat = Double.NaN; double prevLon = Double.NaN; double prevEle = Double.NaN; double dist = 0; for (int i = 0; i < size(); i++) { if (i > 0) { if (is3D()) dist += distCalc3D.calcDist(prevLat, prevLon, prevEle, getLat(i), getLon(i), getEle(i)); else dist += calc.calcDist(prevLat, prevLon, getLat(i), getLon(i)); } prevLat = getLat(i); prevLon = getLon(i); if (is3D()) prevEle = getEle(i); } return dist; }
prevEle = ele; } else if (!distCalc.isCrossBoundary(lon, prevLon)) towerNodeDistance += distCalc.calcDist(prevLat, prevLon, lat, lon);
double lastLat = getTmpLatitude(last), lastLon = getTmpLongitude(last); if (!Double.isNaN(firstLat) && !Double.isNaN(firstLon) && !Double.isNaN(lastLat) && !Double.isNaN(lastLon)) { double estimatedDist = distCalc.calcDist(firstLat, firstLon, lastLat, lastLon);
if (prev != null) { Stop fromStop = feed.stops.get(prev.stop_id); double distance = distCalc.calcDist( fromStop.stop_lat, fromStop.stop_lon,
@Test public void testRMin() { Graph graph = createTestGraph(encodingManager); LocationIndexTree index = createIndex(graph, 50000); //query: 0.05 | -0.3 DistanceCalc distCalc = new DistancePlaneProjection(); double rmin = index.calculateRMin(0.05, -0.3); double check = distCalc.calcDist(0.05, Math.abs(graph.getNodeAccess().getLon(2)) - index.getDeltaLon(), -0.3, -0.3); assertTrue((rmin - check) < 0.0001); double rmin2 = index.calculateRMin(0.05, -0.3, 1); double check2 = distCalc.calcDist(0.05, Math.abs(graph.getNodeAccess().getLat(0)), -0.3, -0.3); assertTrue((rmin2 - check2) < 0.0001); GHIntHashSet points = new GHIntHashSet(); assertEquals(Double.MAX_VALUE, index.calcMinDistance(0.05, -0.3, points), 1e-1); points.add(0); points.add(1); assertEquals(54757.03, index.calcMinDistance(0.05, -0.3, points), 1e-1); /*GraphVisualizer gv = new GraphVisualizer(graph, index.getDeltaLat(), index.getDeltaLon(), index.getCenter(0, 0).lat, index.getCenter(0, 0).lon); try { Thread.sleep(4000); } catch(InterruptedException ie) {}*/ }
double fullLat = na.getLatitude(fullId); double fullLon = na.getLongitude(fullId); float fullDist = (float) dist.calcDist(lat, lon, fullLat, fullLon); int newId = findID(idx, lat, lon); double newLat = na.getLatitude(newId); double newLon = na.getLongitude(newId); float newDist = (float) dist.calcDist(lat, lon, newLat, newLon);
void initAlgo(int lat, int lon) { this.latSize = lat; this.lonSize = lon; BBox b = graph.getBounds(); keyAlgo = new LinearKeyAlgo(lat, lon).setBounds(b); double max = Math.max(distCalc.calcDist(b.minLat, b.minLon, b.minLat, b.maxLon), distCalc.calcDist(b.minLat, b.minLon, b.maxLat, b.minLon)); maxRasterWidth2InMeterNormed = distCalc.calcNormalizedDist(max / Math.sqrt(getCapacity()) * 2); // as long as we have "dist < PI*R/2" it is save to compare the normalized distances instead of the real // distances. because sin(x) is only monotonic increasing for x <= PI/2 (and positive for x >= 0) }