Class GeoHashUtil
java.lang.Object
org.infinispan.server.resp.commands.geo.GeoHashUtil
Geohash encoding/decoding utilities for Redis GEO commands.
Redis uses a 52-bit geohash (26 bits for longitude, 26 bits for latitude) stored as a sorted set score (double). This class provides the encoding/decoding algorithms to convert between (longitude, latitude) coordinates and geohash values.
- Since:
- 16.2
- See Also:
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final intNumber of bits used for each coordinate (longitude and latitude).static final doubleMaximum valid latitude (Web Mercator limit).static final doubleMinimum valid latitude (Web Mercator limit).static final doubleMaximum valid longitude.static final doubleMinimum valid longitude. -
Method Summary
Modifier and TypeMethodDescriptionstatic double[]decode(long geohash) Decode a 52-bit geohash to longitude and latitude.static longencode(double longitude, double latitude) Encode longitude and latitude to a 52-bit geohash.static doublegeohashToScore(long geohash) Convert a geohash (long) to a sorted set score (double).static booleanisValidLatitude(double latitude) Check if the given latitude is valid.static booleanisValidLongitude(double longitude) Check if the given longitude is valid.static longscoreToGeohash(double score) Convert a sorted set score (double) to a geohash (long).static StringtoBase32(long geohash) Convert a 52-bit geohash to an 11-character base32 string.
-
Field Details
-
GEO_STEP
public static final int GEO_STEPNumber of bits used for each coordinate (longitude and latitude). Redis uses 26 bits each for a total of 52 bits.- See Also:
-
LON_MIN
public static final double LON_MINMinimum valid longitude.- See Also:
-
LON_MAX
public static final double LON_MAXMaximum valid longitude.- See Also:
-
LAT_MIN
public static final double LAT_MINMinimum valid latitude (Web Mercator limit).- See Also:
-
LAT_MAX
public static final double LAT_MAXMaximum valid latitude (Web Mercator limit).- See Also:
-
-
Method Details
-
encode
public static long encode(double longitude, double latitude) Encode longitude and latitude to a 52-bit geohash.- Parameters:
longitude- longitude in degrees (-180 to 180)latitude- latitude in degrees (-85.05112878 to 85.05112878)- Returns:
- 52-bit geohash value
-
decode
public static double[] decode(long geohash) Decode a 52-bit geohash to longitude and latitude.- Parameters:
geohash- 52-bit geohash value- Returns:
- array of [longitude, latitude]
-
scoreToGeohash
public static long scoreToGeohash(double score) Convert a sorted set score (double) to a geohash (long).- Parameters:
score- the sorted set score- Returns:
- the geohash value
-
geohashToScore
public static double geohashToScore(long geohash) Convert a geohash (long) to a sorted set score (double).- Parameters:
geohash- the geohash value- Returns:
- the sorted set score
-
toBase32
Convert a 52-bit geohash to an 11-character base32 string. This is used by the GEOHASH command.- Parameters:
geohash- 52-bit geohash value- Returns:
- 11-character base32 string
-
isValidLongitude
public static boolean isValidLongitude(double longitude) Check if the given longitude is valid.- Parameters:
longitude- longitude to check- Returns:
- true if valid
-
isValidLatitude
public static boolean isValidLatitude(double latitude) Check if the given latitude is valid.- Parameters:
latitude- latitude to check- Returns:
- true if valid
-