Package org.elasticsearch.common.geo
Class GeoHashUtils
- java.lang.Object
-
- org.elasticsearch.common.geo.GeoHashUtils
-
public class GeoHashUtils extends java.lang.Object
Utilities for converting to/from the GeoHash standard The geohash long format is represented as lon/lat (x/y) interleaved with the 4 least significant bits representing the level (1-12) [xyxy...xyxyllll] This differs from a morton encoded value which interleaves lat/lon (y/x).*
-
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static <E extends java.util.Collection<? super java.lang.String>>
EaddNeighbors(java.lang.String geohash, int length, E neighbors)
Add all geohashes of the cells next to a given geohash to a list.static <E extends java.util.Collection<? super java.lang.String>>
EaddNeighbors(java.lang.String geohash, E neighbors)
Add all geohashes of the cells next to a given geohash to a list.static org.apache.lucene.geo.Rectangle
bbox(java.lang.String geohash)
Computes the bounding box coordinates from a given geohashstatic double
decodeLatitude(long hash)
decode latitude value from morton encoded geo pointstatic double
decodeLatitude(java.lang.String geohash)
returns the latitude value from the string based geohashstatic double
decodeLongitude(long hash)
decode longitude value from morton encoded geo pointstatic double
decodeLongitude(java.lang.String geohash)
returns the latitude value from the string based geohashstatic long
encodeLatLon(double lat, double lon)
31 bit encoding utils *static long
fromMorton(long morton, int level)
Convert from a morton encoded long from a geohash encoded longstatic long
longEncode(double lon, double lat, int level)
Encode lon/lat to the geohash based long format (lon/lat interleaved, 4 least significant bits = level)static long
longEncode(long geohash, int level)
Encode an existing geohash long to the provided precisionstatic long
mortonEncode(long geoHashLong)
Encode to a morton long value from a given geohash long valuestatic long
mortonEncode(java.lang.String hash)
Encode to a morton long value from a given geohash stringstatic java.lang.String
neighbor(java.lang.String geohash, int level, int dx, int dy)
Calculate the geohash of a neighbor of a geohashstatic java.util.Collection<? extends java.lang.CharSequence>
neighbors(java.lang.String geohash)
Calculate all neighbors of a given geohash cell.static java.lang.String
stringEncode(double lon, double lat)
Encode to a geohash string from full resolution longitude, latitude)static java.lang.String
stringEncode(double lon, double lat, int level)
Encode to a level specific geohash string from full resolution longitude, latitudestatic java.lang.String
stringEncode(long geoHashLong)
Encode to a geohash string from the geohash based long formatstatic java.lang.String
stringEncodeFromMortonLong(long hashedVal)
Encode to a full precision geohash string from a given morton encoded long valuestatic java.lang.String
stringEncodeFromMortonLong(long hashedVal, int level)
Encode to a geohash string at a given level from a morton long
-
-
-
Field Detail
-
PRECISION
public static final int PRECISION
maximum precision for geohash strings- See Also:
- Constant Field Values
-
BITS
public static final short BITS
number of bits used for quantizing latitude and longitude values- See Also:
- Constant Field Values
-
-
Method Detail
-
encodeLatLon
public static long encodeLatLon(double lat, double lon)
31 bit encoding utils *
-
longEncode
public static final long longEncode(double lon, double lat, int level)
Encode lon/lat to the geohash based long format (lon/lat interleaved, 4 least significant bits = level)
-
longEncode
public static long longEncode(long geohash, int level)
Encode an existing geohash long to the provided precision
-
fromMorton
public static long fromMorton(long morton, int level)
Convert from a morton encoded long from a geohash encoded long
-
stringEncode
public static final java.lang.String stringEncode(long geoHashLong)
Encode to a geohash string from the geohash based long format
-
stringEncode
public static final java.lang.String stringEncode(double lon, double lat)
Encode to a geohash string from full resolution longitude, latitude)
-
stringEncode
public static final java.lang.String stringEncode(double lon, double lat, int level)
Encode to a level specific geohash string from full resolution longitude, latitude
-
stringEncodeFromMortonLong
public static final java.lang.String stringEncodeFromMortonLong(long hashedVal) throws java.lang.Exception
Encode to a full precision geohash string from a given morton encoded long value- Throws:
java.lang.Exception
-
stringEncodeFromMortonLong
public static final java.lang.String stringEncodeFromMortonLong(long hashedVal, int level)
Encode to a geohash string at a given level from a morton long
-
mortonEncode
public static final long mortonEncode(java.lang.String hash)
Encode to a morton long value from a given geohash string
-
mortonEncode
public static final long mortonEncode(long geoHashLong)
Encode to a morton long value from a given geohash long value
-
bbox
public static org.apache.lucene.geo.Rectangle bbox(java.lang.String geohash)
Computes the bounding box coordinates from a given geohash- Parameters:
geohash
- Geohash of the defined cell- Returns:
- GeoRect rectangle defining the bounding box
-
neighbors
public static java.util.Collection<? extends java.lang.CharSequence> neighbors(java.lang.String geohash)
Calculate all neighbors of a given geohash cell.- Parameters:
geohash
- Geohash of the defined cell- Returns:
- geohashes of all neighbor cells
-
neighbor
public static final java.lang.String neighbor(java.lang.String geohash, int level, int dx, int dy)
Calculate the geohash of a neighbor of a geohash- Parameters:
geohash
- the geohash of a celllevel
- level of the geohashdx
- delta of the first grid coordinate (must be -1, 0 or +1)dy
- delta of the second grid coordinate (must be -1, 0 or +1)- Returns:
- geohash of the defined cell
-
addNeighbors
public static final <E extends java.util.Collection<? super java.lang.String>> E addNeighbors(java.lang.String geohash, E neighbors)
Add all geohashes of the cells next to a given geohash to a list.- Parameters:
geohash
- Geohash of a specified cellneighbors
- list to add the neighbors to- Returns:
- the given list
-
addNeighbors
public static final <E extends java.util.Collection<? super java.lang.String>> E addNeighbors(java.lang.String geohash, int length, E neighbors)
Add all geohashes of the cells next to a given geohash to a list.- Parameters:
geohash
- Geohash of a specified celllength
- level of the given geohashneighbors
- list to add the neighbors to- Returns:
- the given list
-
decodeLongitude
public static final double decodeLongitude(long hash)
decode longitude value from morton encoded geo point
-
decodeLatitude
public static final double decodeLatitude(long hash)
decode latitude value from morton encoded geo point
-
decodeLatitude
public static final double decodeLatitude(java.lang.String geohash)
returns the latitude value from the string based geohash
-
decodeLongitude
public static final double decodeLongitude(java.lang.String geohash)
returns the latitude value from the string based geohash
-
-