Why aren't geohashes perfect squares?

569 Views Asked by At

Why are the geohashes that are rendered as demonstrably-rectangular on the map not optimized to render as squares? If the purpose of the geohash is to allow single-property spatial indexing and geoquerying, why isn't the geohash optimized into squares where it needs to be so that the circle rendered by the search radius clips the least amount of erroneous results?

enter image description here

1

There are 1 best solutions below

1
On

Fundamentally, the issue is with mapping coordinates on a sphere to a 2D space. As you move away from the equator, the coordinates become more "rectangular", because there is a greater difference between the physical differences represented by equal changes in degrees latitude and degrees longitude. This non-linear behavior is explained well in the Wikipedia article. I've included the relevant portion here:

Since a geohash (in this implementation) is based on coordinates of longitude and latitude the distance between two geohashes reflects the distance in latitude/longitude coordinates between two points, which does not translate to actual distance, see Haversine formula.

Example of non-linearity for latitude-longitude system:

At the Equator (0 Degrees) the length of a degree of longitude is 111.320 km, while a degree of latitude measures 110.574 km, an error of 0.67%.
At 30 Degrees (Mid Latitudes) the error is 110.852/96.486 = 14.89%
At 60 Degrees (High Arctic) the error is 111.412/55.800 = 99.67%, reaching infinity at the poles.