Functions for Working with Geohash
If you need to manually convert geographic coordinates to geohash strings, you can use geohash.org.
Encodes latitude and longitude as a -string.
Input values
- longitude - longitude part of the coordinate you want to encode. Floating in range
- latitude - latitude part of the coordinate you want to encode. Floating in range
[-90°, 90°]
- precision - Optional, length of the resulting encoded string, defaults to
12
. Integer in range[1, 12]
. Any value less than1
or greater than12
is silently converted to12
.
Returned values
Example
SELECT geohashEncode(-5.60302734375, 42.593994140625, 0) AS res;
Decodes any geohash-encoded string into longitude and latitude.
- encoded string - geohash-encoded string.
Returned values
- (longitude, latitude) - 2-tuple of values of longitude and latitude.
Example
SELECT geohashDecode('ezs42') AS res;
Returns an array of -encoded strings of given precision that fall inside and intersect boundaries of given box, basically a 2D grid flattened into array.
Syntax
geohashesInBox(longitude_min, latitude_min, longitude_max, latitude_max, precision)
Arguments
longitude_min
— Minimum longitude. Range:[-180°, 180°]
. Type: Float.longitude_max
— Maximum longitude. Range:[-180°, 180°]
. Type: .- — Maximum latitude. Range:
[-90°, 90°]
. Type: Float. precision
— Geohash precision. Range:[1, 12]
. Type: .
Note
Returned values
- Array of precision-long strings of geohash-boxes covering provided area, you should not rely on order of items.
[]
- Empty array if minimum latitude and longitude values aren’t less than corresponding maximum values.
Type: Array().
Note
Function throws an exception if resulting array is over 10’000’000 items long.
Example
Query:
┌─thasos──────────────────────────────────────┐