public final class GeoHash extends Object
Utility functions for geohashing.
| Modifier and Type | Field and Description |
|---|---|
static int |
DEFAULT_MAX_HASHES
Default maximum number of hashes for covering a bounding box.
|
static int |
MAX_HASH_LENGTH
The standard practical maximum legnth for geohashes.
|
| Modifier and Type | Method and Description |
|---|---|
static String |
adjacentHash(String hash,
Direction direction)
Returns the adjacent hash in given
Direction. |
static String |
adjacentHash(String hash,
Direction direction,
int steps)
Returns the adjacent hash N steps in the given
Direction. |
static String |
bottom(String hash)
Returns the adjacent hash to the bottom (south).
|
static Coverage |
coverBoundingBox(double topLeftLat,
double topLeftLon,
double bottomRightLat,
double bottomRightLon)
Returns the result of coverBoundingBoxMaxHashes with a maxHashes value of
GeoHash.DEFAULT_MAX_HASHES. |
static Coverage |
coverBoundingBox(double topLeftLat,
double topLeftLon,
double bottomRightLat,
double bottomRightLon,
int length)
Returns the hashes of given length that are required to cover the given
bounding box.
|
static Coverage |
coverBoundingBoxMaxHashes(double topLeftLat,
double topLeftLon,
double bottomRightLat,
double bottomRightLon,
int maxHashes)
Returns the hashes that are required to cover the given bounding box.
|
static LatLong |
decodeHash(String geohash)
Returns a latitude,longitude pair as the centre of the given geohash.
|
static String |
encodeHash(double latitude,
double longitude)
Returns a geohash of length
MAX_HASH_LENGTH (12) for the
given WGS84 point (latitude,longitude). |
static String |
encodeHash(double latitude,
double longitude,
int length)
Returns a geohash of given length for the given WGS84 point
(latitude,longitude).
|
static String |
encodeHash(LatLong p)
Returns a geohash of of length
MAX_HASH_LENGTH (12) for
the given WGS84 point. |
static String |
encodeHash(LatLong p,
int length)
Returns a geohash of given length for the given WGS84 point.
|
static String |
gridAsString(String hash,
int fromRight,
int fromBottom,
int toRight,
int toBottom)
Returns a String of lines of hashes to represent the relative positions
of hashes on a map.
|
static String |
gridAsString(String hash,
int fromRight,
int fromBottom,
int toRight,
int toBottom,
Set<String> highlightThese)
Returns a String of lines of hashes to represent the relative positions
of hashes on a map.
|
static String |
gridAsString(String hash,
int size,
Set<String> highlightThese)
Returns a String of lines of hashes to represent the relative positions
of hashes on a map.
|
static boolean |
hashContains(String hash,
double lat,
double lon)
Returns true if and only if the bounding box corresponding to the hash
contains the given lat and long.
|
static int |
hashLengthToCoverBoundingBox(double topLeftLat,
double topLeftLon,
double bottomRightLat,
double bottomRightLon)
Returns the maximum length of hash that covers the bounding box.
|
static double |
heightDegrees(int n)
Returns height in degrees of all geohashes of length n.
|
static String |
left(String hash)
Returns the adjacent hash to the left (west).
|
static List<String> |
neighbours(String hash)
Returns a list of the 8 surrounding hashes for a given hash in order
left,right,top,bottom,left-top,left-bottom,right-top,right-bottom.
|
static String |
right(String hash)
Returns the adjacent hash to the right (east).
|
static String |
top(String hash)
Returns the adjacent hash to the top (north).
|
static double |
widthDegrees(int n)
Returns width in degrees of all geohashes of length n.
|
public static final int MAX_HASH_LENGTH
public static final int DEFAULT_MAX_HASHES
public static String adjacentHash(String hash, Direction direction)
Direction. Based on
https://github.com/davetroy/geohash-js/blob/master/geohash.js. This
method is an improvement on the original js method because it works at
borders too (at the poles and the -180,180 longitude boundaries).hash - direction - public static String right(String hash)
hash - to checkpublic static String left(String hash)
hash - originpublic static String top(String hash)
hash - originpublic static String bottom(String hash)
hash - originpublic static String adjacentHash(String hash, Direction direction, int steps)
Direction. A
negative N will use the opposite Direction.hash - origin hashdirection - to desired hashsteps - number of hashes distance to desired hashpublic static List<String> neighbours(String hash)
hash - sourcepublic static String encodeHash(double latitude, double longitude)
MAX_HASH_LENGTH (12) for the
given WGS84 point (latitude,longitude).latitude - in decimal degrees (WGS84)longitude - in decimal degrees (WGS84)public static String encodeHash(LatLong p, int length)
p - pointlength - length of hashpublic static String encodeHash(LatLong p)
MAX_HASH_LENGTH (12) for
the given WGS84 point.p - pointpublic static String encodeHash(double latitude, double longitude, int length)
IllegalArgumentException.latitude - in decimal degrees (WGS84)longitude - in decimal degrees (WGS84)length - length of desired hashpublic static LatLong decodeHash(String geohash)
geohash - public static int hashLengthToCoverBoundingBox(double topLeftLat,
double topLeftLon,
double bottomRightLat,
double bottomRightLon)
topLeftLat - topLeftLon - bottomRightLat - bottomRightLon - public static boolean hashContains(String hash, double lat, double lon)
hash - lat - lon - public static Coverage coverBoundingBox(double topLeftLat, double topLeftLon, double bottomRightLat, double bottomRightLon)
GeoHash.DEFAULT_MAX_HASHES.topLeftLat - topLeftLon - bottomRightLat - bottomRightLon - public static Coverage coverBoundingBoxMaxHashes(double topLeftLat, double topLeftLon, double bottomRightLat, double bottomRightLon, int maxHashes)
maxHashes. Returns null if hashes
cannot be found satisfying that condition. Maximum hash length returned
will be GeoHash.MAX_HASH_LENGTH.topLeftLat - topLeftLon - bottomRightLat - bottomRightLon - maxHashes - public static Coverage coverBoundingBox(double topLeftLat, double topLeftLon, double bottomRightLat, double bottomRightLon, int length)
topLeftLat - topLeftLon - bottomRightLat - bottomRightLon - length - public static double heightDegrees(int n)
n - public static double widthDegrees(int n)
n - public static String gridAsString(String hash, int size, Set<String> highlightThese)
Returns a String of lines of hashes to represent the relative positions
of hashes on a map. The grid is of height and width 2*size centred around
the given hash. Highlighted hashes are displayed in upper case. For
example, gridToString("dr",1,Collections.
f0 f2 f8 dp dr dx dn dq dw
hash - size - highlightThese - public static String gridAsString(String hash, int fromRight, int fromBottom, int toRight, int toBottom)
hash - fromRight - top left of the grid in hashes to the right (can be negative).fromBottom - top left of the grid in hashes to the bottom (can be
negative).toRight - bottom righth of the grid in hashes to the bottom (can be
negative).toBottom - bottom right of the grid in hashes to the bottom (can be
negative).public static String gridAsString(String hash, int fromRight, int fromBottom, int toRight, int toBottom, Set<String> highlightThese)
f0 F2 F8 dp dr dx dn dq dw
hash - fromRight - top left of the grid in hashes to the right (can be negative).fromBottom - top left of the grid in hashes to the bottom (can be
negative).toRight - bottom righth of the grid in hashes to the bottom (can be
negative).toBottom - bottom right of the grid in hashes to the bottom (can be
negative).highlightThese - Copyright © 2013–2015. All rights reserved.