Geohashes and geohash covers

You can use geohashes and geohash covers to simplify certain operations.

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, which is specified by the user of the algorithm. The smaller the depth value, the larger the cell size.

A geohash cover is the set of geohash cells that are needed to completely cover a particular geometry. A larger depth corresponds to smaller cells, which usually results in more exact coverage (that is, a proportionally smaller area of the geohash cover that is outside of the geometry). However, when the cells are smaller, more cells are needed to compose the geohash cover.

A single-point geometry is always associated with a single cell; however, a non-single-point geometry such as a linestring, polygon, multi-polygon, or multi-point geometry might touch several cells.

Figure 1. Examples of geohash covers of a single geometry at 3 different depths
The number of geohash values in a geohash cover increases with increasing depth. In the following examples, increasing the depth from 13 to 17 increases the number of returned geohash values from 2 to 20:
select * from table(st_geohashcover(ST_POLYGON('polygon((3 3, 4 6, 5 3, 3 3))’),13))

GEOHASH 
-------
-4604930618986332160
-4591419820104220672
2 record(s) selected.
select * from table(st_geohashcover(ST_POLYGON('polygon((3 3, 4 6, 5 3, 3 3))’),17))

GEOHASH 
-------
-4604930618986332160
-4604789881497976832
-4604367669032910848
-4604226931544555520
-4604649144009621504
-4604508406521266176
-4604086194056200192
-4603945456567844864
-4603804719079489536
-4603663981591134208
-4603241769126068224
-4603101031637712896
-4603523244102778880
-4603382506614423552
-4602960294149357568
-4602819556661002240
-4591419820104220672
-4591279082615865344
-4590856870150799360
-4590716132662444032
20 record(s) selected.
The following table lists some of the most commonly used depths 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
When using geohash covers, the following restrictions apply:
  • Each row of the table that contains the base geometry must have a primary key or unique identification. This is required so that each geometry can be associated with the geohash values that comprise its geohash cover. These geohash values are stored in a geohash-filter table that is associated with the geometry column.
  • Geometries for which geohash covers are calculated must use SRS 4326.
  • 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.