Geohash
Planted 02023-05-04
Geohash: What and Why
Geohash is a public domain geocode system based on the Morton Z-order curve.
Critical Feature: Proximity search with prefix property; Geohashing guarantees the longer a shared prefix between two hashes the closer they are.
Feature: Arbitrarily precise cells; longer strings are more precise; shorter strings are less precise.
Caveat: However, two areas can be close together but have entirely different Geohashes; this is due to how the geohash algorithm segments latitude/longitude coordinates into buckets. To solve this you can query neighboring buckets as well.
Encoding a latitude, longitude pair to a string geohash is a three step process:
- Quantize latitude and longitude to 32-bit integers
- Bit-interleave integers to produce 64-bit value (the integer geohash)
- Base32 encode (with custom alphabet) to produce string geohash
Example common flow of getting Geohash from Address:
- Address → Google Geocoding Service → [Latitude, Longitude]
- [Latitude, Longitude] → Geohash function → encoded base32 string
Filter data by proximity
- Given [Latitude, Longitude, Proximity]
- Approximate a cell containing the search area (approximate bounding)
- Lat/lon: the given lat/lon is bounding circle center and proximity is approximated by bounding circle radius
- Geohash: the given lat/lon is located inside calculated geohash (but not centered) and proximity is approximated by either
- reducing precision (widens bounding area)
- generating neighbor bounding areas
- Search
- Lat/lon: calculate and search within bounding circle [latitudeMin, latitudeMax, longitudeMin, longitudeMax]
- Geohash: search where geohash starts with bounding precision and (optionally) neighboring bounding precisions
References on Geohash
- 1966-05 G.M. Morton: A Computer Oriented Geodetic Data Base, and a New Technique in File Sequencing
- Wikipedia: Z-order curve
- 2007-05 Dave Troy: Google is employing the GeoHash algorithm
- 2008-02 Wikipedia: Geohash
- 2008-02 Gustavo Niemeyer: geohash.org is public!
- 2011-12 GIS StackExchange: Using geohash for proximity searches
- 2014-08 Chris Veness: Geohashes
- 2014-09 GIS StackExchange: What is the precision of Geohash?
- 2015-06 Transitland: Geohashes and You
- 2015-04 StackOverflow: Finding geohashes of certain length within radius from a point
- 2016-05 Geohash Spatial Index Search
- 2016-10 Google open-location-code wiki: Evaluation of Location Encoding Systems
- 2018-04 Uber Hexagonal hierarchical geospatial indexing system (h3): Comparison to Geohash
- 2018-08 Eeo Jun: Notes on Geohashing
- 2018-09 Dcode: Geohash
- 2018-09 Michael McLoughlin: Geohash in Golang Assembly
- 2019-10 Jose Paolo Talusan: Geohashing using Hilbert Space filling curves
- 2020-01 Peter Miller: The Problem of Nearness: Part 1 - Geohash
- 2021-01 Duncan Campbell: The secret to killer location queries? Meet the Geohash
- 2021-02 Google Firestore: Geo queries solution: Geohashes
-
2022-04 (YouTube video): [Geohashing Algorithm Proximity Search Based Applications](https://youtu.be/6uhSpLjGLgo)
Geohash in Code
- JavaScript
- 2008-05 Dave Troy: geohash-js
- 2011-06 Ning Sun: node-geohash
- 2014-08 Chriss Veness: latlon-geohash
- 2018-06 geofire.geohashForLocation
- C
- 2015-06 Redis: geohash.c
Other geocode systems
- 2003-07 United States Patent 20050023524: Compact text encoding of latitude/longitude coordinates
- 2008 Mapcode
- Wikipedia: Mapcode
- 2012-10 Patent US9377311B2 Method and apparatus for identifying geographic locations
- 2013-12 Patent US8612147B2 System and method for simplified representation of geographic addresses
- 2013-07 What3Words
- 2014-10 Open Location Code (Plus Code)
- Wikipedia: Open Location Code
- Github: open-location-code
- dcode
- 2016-06 Tibor Vukovic: Hilbert-Geohash
- 2017-12 Google S2
- 2018-04 Uber H3: A Hexagonal Hierarchical Geospatial Indexing System
- 2021-02 Evan Fields: HexGeoGrids
- Natural Area Code
- Xaddress
- Placekey
Uber H3: Hexagonal hierarchical geospatial indexing system
Example flow of search by radius:
- Given [Latitude, Longitude, SearchRadius]
- Calculate grid disk (array of h3Indexes)
- Calculate grid disk of radius based on average cell edge length
- Calculate grid disk based on the search area
- Search for indexes between the minimum and maximum grid disk h3Indexes
Docs
References on H3
- 2018-11 Nick Rabinowitz: H3 Observable Collection
- 2019-08 João Paulo Figueira: Geospatial Indexing with Uber’s H3
- 2020-11 How to efficiently query using H3
- 2020-07 João Paulo Figueira: Fast Geospatial Indexing with H3
- 2021-10 Nick Rabinowitz: Using H3 for Geospatial Analytics
- 2022-10 Jake Adams: Aggregating and Analyzing Point Data with H3 Hexes and Pandas Foursquare:
https://gis.utah.gov/using-h3-hexes/
Minimum bounding rectangle
In computational geometry, the minimum bounding rectangle (MBR), also known as bounding box (BBOX) or envelope, is given a set of 2-dimensional objects: min(x), max(x), min(y), max(y).
- 2010-05 Jan Philip Matuschek: Finding Points Within a Distance of a Latitude/Longitude Using Bounding Coordinates
- 2014-05 Chris Veness: Calculate distance, bearing and more between Latitude/Longitude points