public class GeoUtils
extends java.lang.Object
Modifier and Type | Field | Description |
---|---|---|
static double |
EARTH_AXIS_RATIO |
Earth axis ratio defined by WGS 84 (0.996647189335)
|
static double |
EARTH_EQUATOR |
Earth ellipsoid equator length in meters
|
static double |
EARTH_MEAN_RADIUS |
Earth mean radius defined by WGS 84 in meters
|
static double |
EARTH_POLAR_DISTANCE |
Earth ellipsoid polar distance in meters
|
static double |
EARTH_SEMI_MAJOR_AXIS |
Earth ellipsoid major axis defined by WGS 84 in meters
|
static double |
EARTH_SEMI_MINOR_AXIS |
Earth ellipsoid minor axis defined by WGS 84 in meters
|
static java.lang.String |
GEOHASH |
|
static java.lang.String |
LATITUDE |
|
static java.lang.String |
LONGITUDE |
|
static double |
MAX_LAT |
Maximum valid latitude in degrees.
|
static double |
MAX_LON |
Maximum valid longitude in degrees.
|
static double |
MIN_LAT |
Minimum valid latitude in degrees.
|
static double |
MIN_LON |
Minimum valid longitude in degrees.
|
static double |
TOLERANCE |
rounding error for quantized latitude and longitude values
|
Modifier and Type | Method | Description |
---|---|---|
static double |
arcDistance(double lat1,
double lon1,
double lat2,
double lon2) |
Return the distance (in meters) between 2 lat,lon geo points using the haversine method implemented by lucene
|
static int |
checkPrecisionRange(int precision) |
Checks that the precision is within range supported by elasticsearch - between 1 and 12
Returns the precision value if it is in the range and throws an IllegalArgumentException if it
is outside the range.
|
static SortedNumericDoubleValues |
distanceValues(GeoDistance distance,
DistanceUnit unit,
MultiGeoPointValues geoPointValues,
GeoPoint... fromPoints) |
Return a
SortedNumericDoubleValues instance that returns the distances to a list of geo-points
for each document. |
static double |
geoHashCellHeight(int level) |
Calculate the height (in meters) of geohash cells at a specific level
|
static double |
geoHashCellSize(int level) |
Calculate the size (in meters) of geohash cells at a specific level
|
static double |
geoHashCellWidth(int level) |
Calculate the width (in meters) of geohash cells at a specific level
|
static int |
geoHashLevelsForPrecision(double meters) |
Calculate the number of levels needed for a specific precision.
|
static int |
geoHashLevelsForPrecision(java.lang.String distance) |
Calculate the number of levels needed for a specific precision.
|
static boolean |
isValidLatitude(double latitude) |
Returns true if latitude is actually a valid latitude value.
|
static boolean |
isValidLongitude(double longitude) |
Returns true if longitude is actually a valid longitude value.
|
static double |
maxRadialDistanceMeters(double centerLat,
double centerLon) |
Returns the maximum distance/radius (in meters) from the point 'center' before overlapping
|
static double |
normalizeLat(double lat) |
Normalize latitude to lie within the -90 to 90 (both inclusive) range.
|
static double |
normalizeLon(double lon) |
Normalize longitude to lie within the -180 (exclusive) to 180 (inclusive) range.
|
static void |
normalizePoint(double[] lonLat) |
|
static void |
normalizePoint(double[] lonLat,
boolean normLon,
boolean normLat) |
|
static void |
normalizePoint(GeoPoint point) |
Normalize the geo
Point for its coordinates to lie within their
respective normalized ranges. |
static void |
normalizePoint(GeoPoint point,
boolean normLat,
boolean normLon) |
Normalize the geo
Point for the given coordinates to lie within
their respective normalized ranges. |
static GeoPoint |
parseGeoPoint(java.lang.Object value,
boolean ignoreZValue) |
Parses the value as a geopoint.
|
static GeoPoint |
parseGeoPoint(XContentParser parser) |
Parse a
GeoPoint with a XContentParser : |
static GeoPoint |
parseGeoPoint(XContentParser parser,
GeoPoint point) |
|
static GeoPoint |
parseGeoPoint(XContentParser parser,
GeoPoint point,
boolean ignoreZValue) |
Parse a
GeoPoint with a XContentParser . |
static int |
parsePrecision(XContentParser parser) |
Parse a precision that can be expressed as an integer or a distance measure like "1km", "10m".
|
static double |
planeDistance(double lat1,
double lon1,
double lat2,
double lon2) |
Return the distance (in meters) between 2 lat,lon geo points using a simple tangential plane
this provides a faster alternative to
arcDistance(double, double, double, double) but is inaccurate for distances greater than
4 decimal degrees |
static double |
quadTreeCellHeight(int level) |
Calculate the height (in meters) of quadtree cells at a specific level
|
static double |
quadTreeCellSize(int level) |
Calculate the size (in meters) of quadtree cells at a specific level
|
static double |
quadTreeCellWidth(int level) |
Calculate the width (in meters) of quadtree cells at a specific level
|
static int |
quadTreeLevelsForPrecision(double meters) |
Calculate the number of levels needed for a specific precision.
|
static int |
quadTreeLevelsForPrecision(java.lang.String distance) |
Calculate the number of levels needed for a specific precision.
|
static boolean |
rectangleContainsPoint(org.apache.lucene.geo.Rectangle r,
double lat,
double lon) |
check if point is within a rectangle
todo: move this to lucene Rectangle class
|
public static final double MAX_LAT
public static final double MIN_LAT
public static final double MAX_LON
public static final double MIN_LON
public static final java.lang.String LATITUDE
public static final java.lang.String LONGITUDE
public static final java.lang.String GEOHASH
public static final double EARTH_SEMI_MAJOR_AXIS
public static final double EARTH_SEMI_MINOR_AXIS
public static final double EARTH_MEAN_RADIUS
public static final double EARTH_AXIS_RATIO
public static final double EARTH_EQUATOR
public static final double EARTH_POLAR_DISTANCE
public static final double TOLERANCE
public static boolean isValidLatitude(double latitude)
public static boolean isValidLongitude(double longitude)
public static double geoHashCellWidth(int level)
level
- geohash level must be greater or equal to zeropublic static double quadTreeCellWidth(int level)
level
- quadtree level must be greater or equal to zeropublic static double geoHashCellHeight(int level)
level
- geohash level must be greater or equal to zeropublic static double quadTreeCellHeight(int level)
level
- quadtree level must be greater or equal to zeropublic static double geoHashCellSize(int level)
level
- geohash level must be greater or equal to zeropublic static double quadTreeCellSize(int level)
level
- quadtree level must be greater or equal to zeropublic static int quadTreeLevelsForPrecision(double meters)
meters
- Maximum size of cells in meters (must greater than zero)public static int quadTreeLevelsForPrecision(java.lang.String distance)
distance
- Maximum size of cells as unit string (must greater or equal to zero)public static int geoHashLevelsForPrecision(double meters)
meters
- Maximum size of cells in meters (must greater or equal to zero)public static int geoHashLevelsForPrecision(java.lang.String distance)
distance
- Maximum size of cells as unit string (must greater or equal to zero)public static double normalizeLon(double lon)
lon
- Longitude to normalizepublic static double normalizeLat(double lat)
Note: You should not normalize longitude and latitude separately,
because when normalizing latitude it may be necessary to
add a shift of 180° in the longitude.
For this purpose, you should call the
normalizePoint(GeoPoint)
function.
lat
- Latitude to normalizenormalizePoint(GeoPoint)
public static void normalizePoint(GeoPoint point)
Point
for its coordinates to lie within their
respective normalized ranges.
Note: A shift of 180° is applied in the longitude if necessary, in order to normalize properly the latitude.
point
- The point to normalize in-place.public static void normalizePoint(GeoPoint point, boolean normLat, boolean normLon)
Point
for the given coordinates to lie within
their respective normalized ranges.
You can control which coordinate gets normalized with the two flags.
Note: A shift of 180° is applied in the longitude if necessary, in order to normalize properly the latitude. If normalizing latitude but not longitude, it is assumed that the longitude is in the form x+k*360, with x in ]-180;180], and k is meaningful to the application. Therefore x will be adjusted while keeping k preserved.
point
- The point to normalize in-place.normLat
- Whether to normalize latitude or leave it as is.normLon
- Whether to normalize longitude.public static void normalizePoint(double[] lonLat)
public static void normalizePoint(double[] lonLat, boolean normLon, boolean normLat)
public static GeoPoint parseGeoPoint(XContentParser parser) throws java.io.IOException, ElasticsearchParseException
GeoPoint
with a XContentParser
:parser
- XContentParser
to parse the value fromGeoPoint
parsed from the parsejava.io.IOException
ElasticsearchParseException
public static GeoPoint parseGeoPoint(XContentParser parser, GeoPoint point) throws java.io.IOException, ElasticsearchParseException
java.io.IOException
ElasticsearchParseException
public static GeoPoint parseGeoPoint(java.lang.Object value, boolean ignoreZValue) throws ElasticsearchParseException
Object: has to contain either lat and lon or geohash fields
String: expected to be in "latitude, longitude" format or a geohash
Array: two or more elements, the first element is longitude, the second is latitude, the rest is ignored if ignoreZValue is true
ElasticsearchParseException
public static GeoPoint parseGeoPoint(XContentParser parser, GeoPoint point, boolean ignoreZValue) throws java.io.IOException, ElasticsearchParseException
GeoPoint
with a XContentParser
. A geopoint has one of the following forms:
{"lat": <latitude>, "lon": <longitude>}
"<latitude>,<longitude>"
"<geohash>"
[<longitude>,<latitude>]
parser
- XContentParser
to parse the value frompoint
- A GeoPoint
that will be reset by the values parsedGeoPoint
parsed from the parsejava.io.IOException
ElasticsearchParseException
public static int parsePrecision(XContentParser parser) throws java.io.IOException, ElasticsearchParseException
parser
- XContentParser
to parse the value fromjava.io.IOException
ElasticsearchParseException
public static int checkPrecisionRange(int precision)
public static double maxRadialDistanceMeters(double centerLat, double centerLon)
public static double arcDistance(double lat1, double lon1, double lat2, double lon2)
public static double planeDistance(double lat1, double lon1, double lat2, double lon2)
arcDistance(double, double, double, double)
but is inaccurate for distances greater than
4 decimal degreespublic static boolean rectangleContainsPoint(org.apache.lucene.geo.Rectangle r, double lat, double lon)
public static SortedNumericDoubleValues distanceValues(GeoDistance distance, DistanceUnit unit, MultiGeoPointValues geoPointValues, GeoPoint... fromPoints)
SortedNumericDoubleValues
instance that returns the distances to a list of geo-points
for each document.