Geohash is a public domain latitude/longitude geocode system intended for fast approximations. The idea is that you can break the surface of the globe into a grid of squares of a certain size. The smaller the size, the more squares it takes to cover the surface. Each square, for each size, can be represented with a hash string. So for a very large square size, you can represent any given square with a singe character. As the squares get smaller (and therefore more precise), the hash string gets longer.

This is convenient for encoding, but also for extremely fast distance estimates. If two points are in the same square, you know they are no further than the length of the hypotenuse from each other. For very small square sizes, this can be a very reasonable approximation (as good as on the order of centimeters). So with an arbitrary set of square sizes, if you can find the smallest square that contains two points, it's hypotenuse is a decent estimate of their distance (particularly if you are expecting them to be relatively close).

Another benefit is that geohashes are a single simple variable (string), which can represent position in a single sql or pandas column, and be aggregated on simply.

Because of all of these things, I use the python library geohash pretty often in geospatial data analysis projects, unfortunately I didn't support python 3. After leaving a pull request open for a few months, I've decided to break out a separate maintained project for geohash. So now on pypi, you can pip install pygeohash and get my maintained version. A few changes over the original:

Python 3 support (this was my original change) 99% testing coverage (working on improving the actual quality of these still) Distance module for different distance measures between geohashes

Going forward, I aim to:

Improve the quality of testing, including some speed/performance benchmarking Expand the distance module for different approximations Maintain the library with no external dependencies Add fast clustering / binning of sets of geohashes with statistics Add stats functions for lists of geohashes (mean, stdev, etc.)

So let's try it out:

import pygeohash as pgh pgh.encode(42.6, -5.6) # >>> 'ezs42e44yx96' pgh.encode(42.6, -5.6, precision=5) # >>> 'ezs42' pgh.decode('ezs42') # >>> (42.6, -5.6) pgh.geohash_approximate_distance('shi3u', 'sh83n') # >>> 625441

As always, I welcome contributors and feedback, so let me know how it's working for you, and check out the source on github:

https://github.com/wdm0006/pygeohash