Class Geohash
java.lang.Object
org.springframework.data.elasticsearch.utils.geohash.Geohash
Code copied from Elasticsearch 7.10, Apache License V2
https://github.com/elastic/elasticsearch/blob/7.10/libs/geo/src/main/java/org/elasticsearch/geometry/utils/Geohash.java
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). NOTE: this will replace
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). NOTE: this will replace
org.elasticsearch.common.geo.GeoHashUtils
-
Field Summary
Modifier and TypeFieldDescriptionstatic final int
maximum precision for geohash strings -
Method Summary
Modifier and TypeMethodDescriptionstatic <E extends Collection<? super String>>
EaddNeighbors
(String geohash, E neighbors) Add all geohashes of the cells next to a given geohash to a list.static <E extends Collection<? super String>>
EaddNeighborsAtLevel
(String geohash, int level, E neighbors) Add all geohashes of the cells next to a given geohash to a list.static double
decodeLatitude
(long hash) decode latitude value from morton encoded geo pointstatic double
decodeLatitude
(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
(String geohash) returns the latitude value from the string based geohashstatic int
encodeLatitude
(double latitude) encode latitude to integerstatic int
encodeLongitude
(double longitude) encode longitude to integerstatic String
getNeighbor
(String geohash, int level, int dx, int dy) Calculate the geohash of a neighbor of a geohashstatic Collection<? extends CharSequence>
getNeighbors
(String geohash) Calculate all neighbors of a given geohash cell.static String[]
getSubGeohashes
(String baseGeohash) Array of geohashes one level below the baseGeohash.static double
latHeightInDegrees
(int precision) approximate height of geohash tile for a specific precision in degreesstatic 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
(String hash) Encode a string geohash to the geohash based long format (lon/lat interleaved, 4 least significant bits = level)static double
lonWidthInDegrees
(int precision) approximate width of geohash tile for a specific precision in degreesstatic long
mortonEncode
(String hash) Encode to a morton long value from a given geohash stringstatic String
stringEncode
(double lon, double lat) Encode to a geohash string from full resolution longitude, latitude)static String
stringEncode
(double lon, double lat, int level) Encode to a level specific geohash string from full resolution longitude, latitudestatic String
stringEncode
(long geoHashLong) Encode to a geohash string from the geohash based long formatstatic Rectangle
toBoundingBox
(String geohash) Computes the bounding box coordinates from a given geohashstatic String
Converts a geohash to a string in the format "lat,lon"static Point
Returns aPoint
instance from a geohash string
-
Field Details
-
PRECISION
public static final int PRECISIONmaximum precision for geohash strings- See Also:
-
-
Method Details
-
toPoint
Returns aPoint
instance from a geohash string- Throws:
IllegalArgumentException
-
toLatLon
Converts a geohash to a string in the format "lat,lon"- Parameters:
geohash
- the geohash to convert- Returns:
- the lat lon pair in a String
- Since:
- 5.3
-
toBoundingBox
Computes the bounding box coordinates from a given geohash- Parameters:
geohash
- Geohash of the defined cell- Returns:
- GeoRect rectangle defining the bounding box
-
getSubGeohashes
Array of geohashes one level below the baseGeohash. Sorted. -
getNeighbors
Calculate all neighbors of a given geohash cell.- Parameters:
geohash
- Geohash of the defined cell- Returns:
- geohashes of all neighbor cells
-
addNeighbors
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
-
addNeighborsAtLevel
public static <E extends Collection<? super String>> E addNeighborsAtLevel(String geohash, int level, E neighbors) Add all geohashes of the cells next to a given geohash to a list.- Parameters:
geohash
- Geohash of a specified celllevel
- level of the given geohashneighbors
- list to add the neighbors to- Returns:
- the given list
-
getNeighbor
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
-
longEncode
Encode a string geohash to the geohash based long format (lon/lat interleaved, 4 least significant bits = level) -
longEncode
public static 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) -
stringEncode
Encode to a geohash string from full resolution longitude, latitude) -
stringEncode
Encode to a level specific geohash string from full resolution longitude, latitude -
stringEncode
Encode to a geohash string from the geohash based long format -
mortonEncode
Encode to a morton long value from a given geohash string -
lonWidthInDegrees
public static double lonWidthInDegrees(int precision) approximate width of geohash tile for a specific precision in degrees -
latHeightInDegrees
public static double latHeightInDegrees(int precision) approximate height of geohash tile for a specific precision in degrees -
encodeLatitude
public static int encodeLatitude(double latitude) encode latitude to integer -
encodeLongitude
public static int encodeLongitude(double longitude) encode longitude to integer -
decodeLatitude
returns the latitude value from the string based geohash -
decodeLongitude
returns the latitude value from the string based geohash -
decodeLongitude
public static double decodeLongitude(long hash) decode longitude value from morton encoded geo point -
decodeLatitude
public static double decodeLatitude(long hash) decode latitude value from morton encoded geo point
-