public PlaneFixedSourceDistance(double sourceLatitude, double sourceLongitude, DistanceUnit unit) { this.sourceLatitude = sourceLatitude; this.sourceLongitude = sourceLongitude; this.distancePerDegree = unit.getDistancePerDegree(); }
@Override public double calculate(double sourceLatitude, double sourceLongitude, double targetLatitude, double targetLongitude, DistanceUnit unit) { double px = targetLongitude - sourceLongitude; double py = targetLatitude - sourceLatitude; return Math.sqrt(px * px + py * py) * unit.getDistancePerDegree(); }
@Override public double getDistance() { String geohash = (String)((ElasticsearchDocument)getDocument()).getSource().get(geoPointField); GeoPoint dstPoint = GeoPoint.fromGeohash(geohash); double unitDist = GeoDistance.ARC.calculate(srcPoint.getLat(), srcPoint.getLon(), dstPoint.getLat(), dstPoint.getLon(), unit); double distance; if (GEOF.UOM_METRE.equals(units)) { distance = unit.toMeters(unitDist); } else if (GEOF.UOM_DEGREE.equals(units)) { distance = unitDist / unit.getDistancePerDegree(); } else if (GEOF.UOM_RADIAN.equals(units)) { distance = DistanceUtils.dist2Radians(unit.convert(unitDist, DistanceUnit.KILOMETERS), DistanceUtils.EARTH_MEAN_RADIUS_KM); } else if (GEOF.UOM_UNITY.equals(units)) { distance = unit.convert(unitDist, DistanceUnit.KILOMETERS) / (Math.PI * DistanceUtils.EARTH_MEAN_RADIUS_KM); } else { throw new UnsupportedOperationException("Unsupported units: " + units); } return distance; } }
unitDist = unit.getDistancePerDegree() * distance;