ST_ GeohashCover

The ST_GeohashCover function returns the geohash cover of the specified geometry at the specified depth. A geohash cover is the set of geohash cells that are needed to completely cover a given geometry. A larger depth corresponds to smaller cells, and therefore results in more exact coverage (that is, less area of the geohash cover that is outside of the geometry). However, when the cells are smaller, more cells are needed.

Syntax

Read syntax diagramSkip visual syntax diagramST_GeohashCover(geometry,depthST_GeohashCover_Small(geometryST_GeohashCover_Medium(geometryST_GeohashCover_Large(geometryST_GeohashCover_Huge(geometry )

Parameter

geometry
A value of type ST_Geometry or one of its subtypes that represents the geometry for which the geohash cover values are to be calculated. If the specified geometry is NULL or empty, one row with a geohash value of NULL is returned.
depth
A value of type INTEGER in the range 1 - 45 that determines the size of the geohash cells that comprise the geohash cover. The following table lists some of the most commonly used depths and their corresponding approximate cell sizes.
Geohash Depth Approximate Cell Size Description Examples
45 0.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 (huge) region state or country

Geohash values of two geometries that are to be compared must be computed using the same depth. An attempt to compare geohash values computed using different depths is invalid.

Shortcut functions

The following shortcut functions can be used instead of ST_GeohashCover:
Shortcut Function Description Equivalent ST_ GeohashCover Function
ST_ GeohashCover_Small(geometry) Returns the geohash cover of the specified geometry at depth 28. ST_ GeohashCover(geometry,28)
ST_ GeohashCover_Medium(geometry) Returns the geohash cover of the specified geometry at depth 23. ST_ GeohashCover(geometry,23)
ST_ GeohashCover_Large(geometry) Returns the geohash cover of the specified geometry at depth 18. ST_ GeohashCover(geometry,18)
ST_ GeohashCover_Huge(geometry) Returns the geohash cover of the specified geometry at depth 13. ST_ GeohashCover(geometry,13)

Restrictions

  • The number of rows returned by this function cannot exceed 10,000 (SQL0443N).
  • The specified geometry must use SRS 4326 (GSE3001N).

Output

A column of type BIGINT with the name GEOHASH containing the geohash values of the specified geometry at the specified depth.

Examples

Example 1
The following SQL statement returns the geohash cover of a point geometry (the geohash cover of a point is a single geohash) at depth 10:
select geohash from table(st_geohashcover(st_point(1,2),10))
Result:
GEOHASH
--------------------
-4611686018427387904
Example 2
The following SQL statement returns the geohash values of a polygon geometry at depth 15:
select * from table(st_geohashcover(ST_POLYGON('polygon((3 3, 4 6, 5 3, 3 3))'),15))
Result:
GEOHASH
--------------------
-4604930618986332160
-4604367669032910848
-4603804719079489536
-4603241769126068224
-4591419820104220672
-4590856870150799360