DatageohashH3S2quadtreespatial index

Geospatial index

Definition

A geospatial index organises points or shapes by location, using grid cells (geohash, H3, S2) or trees (quadtrees, R-trees), to answer proximity and bounding-box queries efficiently.

In practice

A proximity query is a two-dimensional range query, and a composite B-tree on (lat, lng) only narrows the first column well. Cell systems turn a position into a key: geohash encodes nested rectangles as base-32 strings, H3 tiles the globe with hexagons at 16 resolutions, S2 maps the sphere onto a cube of quadtree cells. A nearby search reads a cell and its neighbours.

Cell boundaries mean nearby points can have very different keys, so searches must always include neighbouring cells. Choosing the resolution trades fan-out against cell size, and dense areas such as a city centre at rush hour create hot cells, so the index is often sharded by cell and hot cells split or cached. PostGIS uses R-trees via GiST for shapes.

Example

A rider at geohash u33dc0 (about 1.2 × 0.6 km) is matched by reading that cell plus its 8 neighbours from a cell → drivers map updated every 4 seconds.