ST_GEOHASH table function

The ST_GEOHASH table function takes an ST_POINT object and a depth as input parameters and returns a table with one column containing the geohash of the specified point geometry at the specified depth.

A geohash is a number that uniquely identifies a specific region. The geohash algorithm divides the Earth into regions, called cells, and converts the latitude and longitude of the center of each cell into a number that uniquely identifies it. The size of each cell is determined by the depth value. The smaller the depth value, the larger the cell size.

Read syntax diagramSkip visual syntax diagramST_GEOHASH(point_geometry,depth)
point_geometry
A value of type ST_POINT that represents the point geometry for which the geohash is to be calculated. If the specified geometry is NULL or empty, one row with a geohash value of NULL is returned.
depth
An integer value in the range 1 - 45 that determines the size of the geohash cell. The following list contains some commonly used depths their corresponding approximate cell sizes.
Geohash Depth Approximate Cell Size Description Examples
45 .1 km2 Single point or address GPS-location or house
28 3 km2 Small region city block
23 100 km2 Medium-sized region forest or lake
18 3,000 km2 Large region county or postal code area
13 100,000 km2 Very large region state or country

Geohash values of two geometries that are to be compared should be computed using the same depth for a meaningful comparison.

The result of the function is a table containing one row with the format shown in the following table. The column is nullable.
Table 1. Format of the resulting table for ST_GEOHASH
Column name Data type Contains
GEOHASH BIGINT The geohash value of the specified point geometry at the specified depth.

Example

The following SQL statement returns the geohash value that covers the specified point geometry at depth 18:

SELECT geohash FROM TABLE(QSYS2.ST_GEOHASH(QSYS2.ST_POINT('point(10 20)'), 18));

Results:


GEOHASH
-------------------
6970727798239395840