|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object org.apache.lucene.spatial.DistanceUtils
public class DistanceUtils
NOTE: This API is still in flux and might change in incompatible ways in the next release.
Field Summary | |
---|---|
static double |
DEG_180_AS_RADS
|
static double |
DEG_225_AS_RADS
|
static double |
DEG_270_AS_RADS
|
static double |
DEG_45_AS_RADS
|
static double |
DEG_90_AS_RADS
|
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_MILES
|
static double |
MILES_TO_KM
|
static double |
RADIANS_TO_DEGREES
|
static double |
SIN_45_AS_RADS
|
Constructor Summary | |
---|---|
DistanceUtils()
|
Method Summary | |
---|---|
static double |
angularDistance(double distance,
double radius)
distance/radius. |
static Rectangle |
getBoundary(double x1,
double y1,
double miles)
|
static double |
getDistanceMi(double x1,
double y1,
double x2,
double y2)
|
static double |
getLLMDistance(double x1,
double y1,
double x2,
double y2)
|
static double |
haversine(double x1,
double y1,
double x2,
double y2,
double radius)
|
static double[] |
latLonCorner(double latCenter,
double lonCenter,
double distance,
double[] result,
boolean upperRight,
double sphereRadius)
Uses Haversine to calculate the corner of a box (upper right or lower left) that is the distance away, given a sphere of the specified radius. |
static double[] |
latLonCornerDegs(double latCenter,
double lonCenter,
double distance,
double[] result,
boolean upperRight,
double sphereRadius)
|
static void |
normLat(double[] latLng)
|
static void |
normLng(double[] latLng)
Returns a normalized Lng rectangle shape for the bounding box |
static double[] |
parseLatitudeLongitude(double[] latLon,
String latLonStr)
extract (by calling parsePoint(String[], String, int) and validate the latitude and longitude contained
in the String by making sure the latitude is between 90 & -90 and longitude is between -180 and 180. |
static double[] |
parseLatitudeLongitude(String latLonStr)
|
static String[] |
parsePoint(String[] out,
String externalVal,
int dimension)
Given a string containing dimension values encoded in it, separated by commas, return a String array of length dimension containing the values. |
static double[] |
parsePointDouble(double[] out,
String externalVal,
int dimension)
Given a string containing dimension values encoded in it, separated by commas, return a double array of length dimension containing the values. |
static double[] |
pointOnBearing(double startLat,
double startLon,
double distance,
double bearing,
double[] result,
double sphereRadius)
Given a start point (startLat, startLon) and a bearing on a sphere of radius sphereRadius, return the destination point. |
static double |
squaredEuclideanDistance(double[] vec1,
double[] vec2)
The square of the Euclidean Distance. |
static double[] |
vectorBoxCorner(double[] center,
double[] result,
double distance,
boolean upperRight)
Return the coordinates of a vector that is the corner of a box (upper right or lower left), assuming a Rectangular coordinate system. |
static double |
vectorDistance(double[] vec1,
double[] vec2,
double power)
Calculate the p-norm (i.e. |
static double |
vectorDistance(double[] vec1,
double[] vec2,
double power,
double oneOverPower)
Calculate the p-norm (i.e. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
public static final double DEGREES_TO_RADIANS
public static final double RADIANS_TO_DEGREES
public static final double DEG_45_AS_RADS
public static final double SIN_45_AS_RADS
public static final double DEG_90_AS_RADS
public static final double DEG_180_AS_RADS
public static final double DEG_225_AS_RADS
public static final double DEG_270_AS_RADS
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_MEAN_RADIUS_MI
public static final double EARTH_EQUATORIAL_RADIUS_MI
public static final double EARTH_EQUATORIAL_RADIUS_KM
Constructor Detail |
---|
public DistanceUtils()
Method Detail |
---|
public static double getDistanceMi(double x1, double y1, double x2, double y2)
public static Rectangle getBoundary(double x1, double y1, double miles)
x1
- y1
- miles
-
public static double getLLMDistance(double x1, double y1, double x2, double y2)
public static double angularDistance(double distance, double radius)
distance
- The distance travelledradius
- The radius of the sphere
public static double vectorDistance(double[] vec1, double[] vec2, double power)
vec1
- The first vectorvec2
- The second vectorpower
- The power (2 for Euclidean distance, 1 for manhattan, etc.)
vectorDistance(double[], double[], double, double)
public static double vectorDistance(double[] vec1, double[] vec2, double power, double oneOverPower)
vec1
- The first vectorvec2
- The second vectorpower
- The power (2 for Euclidean distance, 1 for manhattan, etc.)oneOverPower
- If you've precalculated oneOverPower and cached it, use this method to save one division operation over vectorDistance(double[], double[], double)
.
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 double[] latLonCornerDegs(double latCenter, double lonCenter, double distance, double[] result, boolean upperRight, double sphereRadius)
latCenter
- In degreeslonCenter
- In degreesdistance
- The distanceresult
- A preallocated array to hold the results. If null, a new one is constructed.upperRight
- If true, calculate the upper right corner, else the lower leftsphereRadius
- The radius of the sphere to use.
latLonCorner(double, double, double, double[], boolean, double)
public static double[] latLonCorner(double latCenter, double lonCenter, double distance, double[] result, boolean upperRight, double sphereRadius)
latCenter
- In radianslonCenter
- In radiansdistance
- The distanceresult
- A preallocated array to hold the results. If null, a new one is constructed.upperRight
- If true, give lat/lon for the upper right corner, else lower leftsphereRadius
- The radius to use for the calculation
public static double[] pointOnBearing(double startLat, double startLon, double distance, double bearing, double[] result, double sphereRadius)
startLat
- The starting point latitude, in radiansstartLon
- The starting point longitude, in radiansdistance
- The distance to travel along the bearing. The units are assumed to be the same as the sphereRadius units, both of which is up to the caller to knowbearing
- The bearing, in radians. North is a 0 deg. bearing, east is 90 deg, south is 180 deg, west is 270 deg.result
- A preallocated array to hold the results. If null, a new one is constructed.sphereRadius
- The radius of the sphere to use for the calculation.
public static void normLat(double[] latLng)
latLng
- The lat/lon, in radians. lat in position 0, long in position 1public static void normLng(double[] latLng)
latLng
- The lat/lon, in radians, lat in position 0, long in position 1public static double squaredEuclideanDistance(double[] vec1, double[] vec2)
vec1
- The first pointvec2
- The second point
public static double haversine(double x1, double y1, double x2, double y2, double radius)
x1
- The x coordinate of the first point, in radiansy1
- The y coordinate of the first point, in radiansx2
- The x coordinate of the second point, in radiansy2
- The y coordinate of the second point, in radiansradius
- The radius of the sphere
public static String[] parsePoint(String[] out, String externalVal, int dimension) throws InvalidGeoException
out
- A preallocated array. Must be size dimension. If it is not it will be resized.externalVal
- The value to parsedimension
- The expected number of values for the point
InvalidGeoException
- if the dimension specified does not match the number of values in the externalValue.public static double[] parsePointDouble(double[] out, String externalVal, int dimension) throws InvalidGeoException
out
- A preallocated array. Must be size dimension. If it is not it will be resized.externalVal
- The value to parsedimension
- The expected number of values for the point
InvalidGeoException
- if the dimension specified does not match the number of values in the externalValue.public static final double[] parseLatitudeLongitude(String latLonStr) throws InvalidGeoException
InvalidGeoException
public static final double[] parseLatitudeLongitude(double[] latLon, String latLonStr) throws InvalidGeoException
parsePoint(String[], String, int)
and validate the latitude and longitude contained
in the String by making sure the latitude is between 90 & -90 and longitude is between -180 and 180.
The latitude is assumed to be the first part of the string and the longitude the second part.
latLon
- A preallocated array to hold the resultlatLonStr
- The string to parse. Latitude is the first value, longitude is the second.
InvalidGeoException
- if there was an error parsing
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |