Module org.elasticsearch.server
Class GeoTileUtils
java.lang.Object
org.elasticsearch.search.aggregations.bucket.geogrid.GeoTileUtils
Implements geotile key hashing, same as used by many map tile implementations.
The string key is formatted as "zoom/x/y"
The hash value (long) contains all three of those values compacted into a single 64bit value:
bits 58..63 -- zoom (0..29)
bits 29..57 -- X tile index (0..2^zoom)
bits 0..28 -- Y tile index (0..2^zoom)
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final intstatic final intstatic final doubleThe geo-tile map is clipped at 85.05112878 to 90 and -85.05112878 to -90static final intLargest number of tiles (precision) to use.static final doubleSince shapes are encoded, their boundaries are to be compared to against the encoded/decoded values ofLATITUDE_MASKstatic final double -
Method Summary
Modifier and TypeMethodDescriptionstatic intcheckPrecisionRange(int precision) Assert the precision value is within the allowed range, and return it if ok, or throw.static intgetXTile(double longitude, int tiles) Calculates the x-coordinate in the tile grid for the specified longitude given the number of tile columns for a pre-determined zoom-level.static intgetYTile(double latitude, int tiles) Calculates the y-coordinate in the tile grid for the specified longitude given the number of tile rows for pre-determined zoom-level.static longlongEncode(double longitude, double latitude, int precision) Encode lon/lat to the geotile based long format.static longlongEncode(String hashAsString) Encode a geotile hash style string to a long.static longlongEncodeTiles(int precision, int xTile, int yTile) static int[]Parse geotile String hash format in "zoom/x/y" into an array of integersstatic StringstringEncode(long hash) Encode to a geotile string from the geotile based long formatstatic doubletileToLat(int yTile, int tiles) Decode a yTile into its latitude valuestatic doubletileToLon(int xTile, int tiles) Decode a xTile into its longitude valuestatic RectangletoBoundingBox(int xTile, int yTile, int precision) Decode a bucket key to a bounding box of the tile corners.static RectangletoBoundingBox(long hash) static RectangletoBoundingBox(String hash) Decode a string bucket key in "zoom/x/y" format to a bounding box of the tile corners
-
Field Details
-
MAX_ZOOM
public static final int MAX_ZOOMLargest number of tiles (precision) to use. This value cannot be more than (64-5)/2 = 29, because 5 bits are used for zoom level itself (0-31) If zoom is not stored inside hash, it would be possible to use up to 32. Note that changing this value will make serialization binary-incompatible between versions. Another consideration is that index optimizes lat/lng storage, loosing some precision. E.g. hash lng=140.74779717298918D lat=45.61884022447444D == "18/233561/93659", but shown as "18/233561/93658"- See Also:
-
LATITUDE_MASK
public static final double LATITUDE_MASKThe geo-tile map is clipped at 85.05112878 to 90 and -85.05112878 to -90- See Also:
-
ENCODED_LATITUDE_MASK
public static final int ENCODED_LATITUDE_MASK -
ENCODED_NEGATIVE_LATITUDE_MASK
public static final int ENCODED_NEGATIVE_LATITUDE_MASK -
NORMALIZED_LATITUDE_MASK
public static final double NORMALIZED_LATITUDE_MASKSince shapes are encoded, their boundaries are to be compared to against the encoded/decoded values ofLATITUDE_MASK -
NORMALIZED_NEGATIVE_LATITUDE_MASK
public static final double NORMALIZED_NEGATIVE_LATITUDE_MASK
-
-
Method Details
-
checkPrecisionRange
public static int checkPrecisionRange(int precision) Assert the precision value is within the allowed range, and return it if ok, or throw. -
getXTile
public static int getXTile(double longitude, int tiles) Calculates the x-coordinate in the tile grid for the specified longitude given the number of tile columns for a pre-determined zoom-level.- Parameters:
longitude- the longitude to use when determining the tile x-coordinate. Longitude is in degrees and must be between -180 and 180 degrees.tiles- the number of tiles per row for a pre-determined zoom-level
-
getYTile
public static int getYTile(double latitude, int tiles) Calculates the y-coordinate in the tile grid for the specified longitude given the number of tile rows for pre-determined zoom-level.- Parameters:
latitude- the latitude to use when determining the tile y-coordinate. Latitude is in degrees and must be between -90 and 90 degrees.tiles- the number of tiles per column for a pre-determined zoom-level
-
longEncode
public static long longEncode(double longitude, double latitude, int precision) Encode lon/lat to the geotile based long format. The resulting hash contains interleaved tile X and Y coordinates. The precision itself is also encoded as a few high bits. -
longEncode
Encode a geotile hash style string to a long.- Parameters:
hashAsString- String in format "zoom/x/y"- Returns:
- long encoded value of the given string hash
-
longEncodeTiles
public static long longEncodeTiles(int precision, int xTile, int yTile) -
parseHash
Parse geotile String hash format in "zoom/x/y" into an array of integers -
stringEncode
Encode to a geotile string from the geotile based long format -
toBoundingBox
-
toBoundingBox
Decode a string bucket key in "zoom/x/y" format to a bounding box of the tile corners -
toBoundingBox
Decode a bucket key to a bounding box of the tile corners. The points belonging to the max latitude and min longitude belong to the tile while the points belonging to the min latitude and max longitude belong to the next tile. -
tileToLon
public static double tileToLon(int xTile, int tiles) Decode a xTile into its longitude value -
tileToLat
public static double tileToLat(int yTile, int tiles) Decode a yTile into its latitude value
-