Geohash is a convenient way to encode a location into a string representation with less precision. In BigObject, geohash() encodes a location into an integer, which can be converted into the string representation via st_geohash().

The GH_NEIGHBORS table operator generates neighboring Geohash codes around a Geohash or location. The GH_EXPAND includes the center code together with GH_NEIGHBORS.

The order of rows generated by GH_NEIGHBORS or GH_EXPAND are as follows:

GH_NEIGHBORS GH_EXPAND
northwest northwest
north north
northeast northeast
west west
east center
southwest east
south southwest
southeast south
- southeast

The syntax for generating neighbors from location data is:

SELECT * FROM table GH_NEIGHBORS
(
  longitude, latitude [, precision ,] [AS col_name]
)

Use the following statement to generate neighbors from Geohash numbers:

SELECT * FROM table GH_NEIGHBORS
(
  geohash_col [AS col_name]
)

The syntax for GH_EXPAND table function is similar to GH_NEIGHBORS.


Examples:

The Geohash string for Burj Khalifa tower is:

SELECT ST_GEOHASH(GEOHASH(lon, lat, 7)) AS gh FROM (SELECT 25.197222 AS lat, 55.274056 AS lon);

+---------+
| gh      |
+---------+
| thrr3g1 |
+---------+

To obtain the neighboring Geohash strings around Burj Khalifa tower:

SELECT st_geohash(nbr) AS neighbors FROM (SELECT 25.197222 AS lat, 55.274056 AS lon) GH_NEIGHBORS (lon, lat, 7 AS nbr);

+-----------+
| neighbors |
+-----------+
| thrr3g2   |
| thrr3g3   |
| thrr3g6   |
| thrr3g0   |
| thrr3g4   |
| thrr3fb   |
| thrr3fc   |
| thrr3ff   |
+-----------+