public class DistanceUtils extends Object
DistanceCalculator
, retrieved from SpatialContext.getDistCalc()
should be used in preference to calling
these methods directly.
This code came from Apache Lucene, LUCENE-1387, which in turn came from "LocalLucene".
Modifier and Type | Field and Description |
---|---|
static double |
DEG_180_AS_RADS |
static double |
DEG_225_AS_RADS
Deprecated.
|
static double |
DEG_270_AS_RADS
Deprecated.
|
static double |
DEG_45_AS_RADS
Deprecated.
|
static double |
DEG_90_AS_RADS |
static double |
DEG_TO_KM
Equivalent to degrees2Dist(1, EARTH_MEAN_RADIUS_KM)
|
static double |
DEGREES_TO_RADIANS |
static double |
EARTH_EQUATORIAL_RADIUS_KM |
static double |
EARTH_EQUATORIAL_RADIUS_MI |
static double |
EARTH_MEAN_RADIUS_KM
The International Union of Geodesy and Geophysics says the Earth's mean radius in KM is:
[1] http://en.wikipedia.org/wiki/Earth_radius
|
static double |
EARTH_MEAN_RADIUS_MI |
static double |
KM_TO_DEG |
static double |
KM_TO_MILES |
static double |
MILES_TO_KM |
static double |
RADIANS_TO_DEGREES |
static double |
SIN_45_AS_RADS
Deprecated.
|
Modifier and Type | Method and Description |
---|---|
static double |
calcBoxByDistFromPt_deltaLonDEG(double lat,
double lon,
double distDEG)
The delta longitude of a point-distance.
|
static double |
calcBoxByDistFromPt_latHorizAxisDEG(double lat,
double lon,
double distDEG)
The latitude of the horizontal axis (e.g.
|
static Rectangle |
calcBoxByDistFromPtDEG(double lat,
double lon,
double distDEG,
SpatialContext ctx,
Rectangle reuse)
Calculates the bounding box of a circle, as specified by its center point
and distance.
|
static double |
calcLonDegreesAtLat(double lat,
double dist)
Calculates the degrees longitude distance at latitude
lat to cover
a distance dist . |
static double |
degrees2Dist(double degrees,
double radius)
Converts
degrees (1/360th of circumference of a circle) into a
distance as measured by the units of the radius. |
static double |
dist2Degrees(double dist,
double radius)
Converts a distance in the units of the radius to degrees (360 degrees are
in a circle).
|
static double |
dist2Radians(double dist,
double radius)
Converts a distance in the units of
radius (e.g. |
static double |
distHaversineRAD(double lat1,
double lon1,
double lat2,
double lon2) |
static double |
distLawOfCosinesRAD(double lat1,
double lon1,
double lat2,
double lon2)
Calculates the distance between two lat-lon's using the Law of Cosines.
|
static double |
distSquaredCartesian(double[] vec1,
double[] vec2)
Deprecated.
|
static double |
distVincentyRAD(double lat1,
double lon1,
double lat2,
double lon2)
Calculates the great circle distance using the Vincenty Formula, simplified for a spherical model.
|
static double |
normLatDEG(double lat_deg)
Puts in range -90 <= lat_deg <= 90.
|
static double |
normLonDEG(double lon_deg)
Puts in range -180 <= lon_deg <= +180.
|
static Point |
pointOnBearingRAD(double startLat,
double startLon,
double distanceRAD,
double bearingRAD,
SpatialContext ctx,
Point reuse)
Given a start point (startLat, startLon), distance, and a bearing on a sphere, return the destination point.
|
static double |
radians2Dist(double radians,
double radius)
Converts
radians (multiples of the radius ) to
distance in the units of the radius (e.g. |
static double |
toDegrees(double radians)
Same as
Math.toDegrees(double) but 3x faster (multiply vs. |
static double |
toRadians(double degrees)
Same as
Math.toRadians(double) but 3x faster (multiply vs. |
static double[] |
vectorBoxCorner(double[] center,
double[] result,
double distance,
boolean upperRight)
Deprecated.
|
static double |
vectorDistance(double[] vec1,
double[] vec2,
double power)
Deprecated.
|
static double |
vectorDistance(double[] vec1,
double[] vec2,
double power,
double oneOverPower)
Deprecated.
|
@Deprecated public static final double DEG_45_AS_RADS
@Deprecated public static final double SIN_45_AS_RADS
public static final double DEG_90_AS_RADS
public static final double DEG_180_AS_RADS
@Deprecated public static final double DEG_225_AS_RADS
@Deprecated public static final double DEG_270_AS_RADS
public static final double DEGREES_TO_RADIANS
public static final double RADIANS_TO_DEGREES
public static final double KM_TO_MILES
public static final double MILES_TO_KM
public static final double EARTH_MEAN_RADIUS_KM
public static final double EARTH_EQUATORIAL_RADIUS_KM
public static final double DEG_TO_KM
public static final double KM_TO_DEG
public static final double EARTH_MEAN_RADIUS_MI
public static final double EARTH_EQUATORIAL_RADIUS_MI
@Deprecated public static double vectorDistance(double[] vec1, double[] vec2, double power)
See Lp space
vec1
- The first vectorvec2
- The second vectorpower
- The power (2 for cartesian distance, 1 for manhattan, etc.)vectorDistance(double[], double[], double, double)
@Deprecated public static double vectorDistance(double[] vec1, double[] vec2, double power, double oneOverPower)
vec1
- The first vectorvec2
- The second vectorpower
- The power (2 for cartesian distance, 1 for manhattan, etc.)oneOverPower
- If you've pre-calculated oneOverPower and cached it, use this method to save
one division operation over vectorDistance(double[], double[], double)
.@Deprecated public static double[] vectorBoxCorner(double[] center, double[] result, double distance, boolean upperRight)
center
- The center pointresult
- Holds the result, potentially resizing if needed.distance
- The d from the center to the cornerupperRight
- If true, return the coords for the upper right corner, else return the lower left.public static Point pointOnBearingRAD(double startLat, double startLon, double distanceRAD, double bearingRAD, SpatialContext ctx, Point reuse)
startLat
- The starting point latitude, in radiansstartLon
- The starting point longitude, in radiansdistanceRAD
- The distance to travel along the bearing in radians.bearingRAD
- The bearing, in radians. North is a 0, moving clockwise till radians(360).reuse
- A preallocated object to hold the results.public static double normLonDEG(double lon_deg)
public static double normLatDEG(double lat_deg)
public static Rectangle calcBoxByDistFromPtDEG(double lat, double lon, double distDEG, SpatialContext ctx, Rectangle reuse)
reuse
is an optional argument to store the
results to avoid object creation.public static double calcBoxByDistFromPt_deltaLonDEG(double lat, double lon, double distDEG)
public static double calcBoxByDistFromPt_latHorizAxisDEG(double lat, double lon, double distDEG)
from.getY()
but, perhaps surprisingly, on a sphere it is going
to be slightly different.public static double calcLonDegreesAtLat(double lat, double dist)
lat
to cover
a distance dist
.
Used to calculate a new expanded buffer distance to account for skewing effects for shapes that use the lat-lon space as a 2D plane instead of a sphere. The expanded buffer will be sure to cover the intended area, but the shape is still skewed and so it will cover a larger area. For latitude 0 (the equator) the result is the same buffer. At 60 (or -60) degrees, the result is twice the buffer, meaning that a shape at 60 degrees is twice as high as it is wide when projected onto a lat-lon plane even if in the real world it's equal all around.
If the result added to abs(lat
) is >= 90 degrees, then skewing is
so severe that the caller should consider tossing the shape and
substituting a spherical cap instead.
lat
- latitude in degreesdist
- distance in degrees@Deprecated public static double distSquaredCartesian(double[] vec1, double[] vec2)
vec1
- The first pointvec2
- The second pointpublic static double distHaversineRAD(double lat1, double lon1, double lat2, double lon2)
lat1
- The y coordinate of the first point, in radianslon1
- The x coordinate of the first point, in radianslat2
- The y coordinate of the second point, in radianslon2
- The x coordinate of the second point, in radianspublic static double distLawOfCosinesRAD(double lat1, double lon1, double lat2, double lon2)
The arguments and return value are in radians.
public static double distVincentyRAD(double lat1, double lon1, double lat2, double lon2)
The arguments are in radians, and the result is in radians.
public static double dist2Degrees(double dist, double radius)
public static double degrees2Dist(double degrees, double radius)
degrees
(1/360th of circumference of a circle) into a
distance as measured by the units of the radius. A spherical earth model
is assumed.public static double dist2Radians(double dist, double radius)
radius
(e.g. kilometers)
to radians (multiples of the radius). A spherical earth model is assumed.public static double radians2Dist(double radians, double radius)
radians
(multiples of the radius
) to
distance in the units of the radius (e.g. kilometers).public static double toRadians(double degrees)
Math.toRadians(double)
but 3x faster (multiply vs. divide).
See CompareRadiansSnippet.java in tests.public static double toDegrees(double radians)
Math.toDegrees(double)
but 3x faster (multiply vs. divide).
See CompareRadiansSnippet.java in tests.Copyright © 2020 LocationTech. All rights reserved.