Skip to main content

Module geohash

Module geohash 

Source
Expand description

Geohash encoding/decoding for spatial indexing.

Geohash is an interleaved Z-order curve over (longitude, latitude) that maps 2D coordinates to a 1D string using base-32 encoding. Nearby points share common prefixes, enabling fast proximity queries via string prefix matching on standard B-tree indexes.

Properties:

  • Precision 1: ~5,000 km cells
  • Precision 6: ~1.2 km × 0.6 km cells (default)
  • Precision 8: ~19 m × 19 m cells
  • Precision 12: ~3.7 cm × 1.9 cm cells (maximum practical)

References:

  • Gustavo Niemeyer, geohash.org (2008)
  • Wikipedia: Geohash

Enums§

Direction
Direction for neighbor computation.

Functions§

geohash_cover
Compute the set of geohash cells that cover a bounding box at the given precision. Useful for range queries: “find all geohash prefixes that overlap this region.”
geohash_decode
Decode a geohash string to its bounding box.
geohash_decode_center
Decode a geohash to its center point (longitude, latitude).
geohash_encode
Encode a (longitude, latitude) coordinate to a geohash string.
geohash_neighbor
Compute the geohash of a neighbor cell in the given direction.
geohash_neighbors
Compute all 8 neighbor geohashes.