What is PyGeoHash?
mastergeohash module, featuring core operations implemented in C for high performance.repository·master·Indexed 41 days ago
https://github.com/wdm0006/pygeohashA high-performance Python library implemented as a C extension for encoding and decoding geographic coordinates into geohashes. It provides utilities for calculating approximate and Haversine distances, retrieving adjacent geohashes, and performing bounding box operations. PyGeoHash also supports conversions between geohashes, Bing Quadkeys, and map-tiles, as well as visualization support via Matplotlib and Folium.
geohash module, featuring core operations implemented in C for high performance.libgeohash or geolib. In benchmark tests, it is approximately 1.10x faster than python-geohash and 13.4x faster than libgeohash for encoding operations. It is noted for high stability (low run-to-run spread) across most operations, including bounding box lookups and box enumeration.Every geohash represents a rectangular area on Earth, defined by a bounding box consisting of:
Bounding boxes are essential for:
By using bounding boxes, you can determine the exact area covered by a geohash, find intersecting geohashes, and check for overlapping geographic regions.
When deciding on a spatial indexing system, consider the following use cases:
pygeohash does not convert to H3 or S2 to avoid false promises of grid alignment.Use pygeohash.interop when you need to move data between geohash storage and the map-tile ecosystem without adding new dependencies.
When using PyGeoHash, keep the following performance and accuracy notes in mind:
While many libraries provide basic encoding and decoding, pygeohash provides several unique utility functions that are not available in common competitors like geohashr, python-geohash, or geolib. These include:
geohash_to_quadkey and quadkey_to_geohash).geohash_to_tile and tile_to_geohash).geohashes_in_box).is_valid_geohash).A geohash is a geocoding system that encodes latitude and longitude into a short string of base-32 characters. It is primarily used for indexing and searching geographic data due to several key properties:
When converting between Geohashes and Slippy Tiles, be aware of the following behaviors:
Longitude is exact between the two grids. An even-precision geohash at zoom 5 * precision / 2 maps cell-for-cell to a tile column and back losslessly. Generally, precision p maps to zoom floor(5 * p / 2).
Latitude is not perfectly aligned. Geohash latitude bands are equirectangular, while tile rows use Web Mercator projection. A round trip through non-aligned zoom or precision levels may land in a neighboring geohash cell. Boundary centers resolve deterministically to the lower-x, lower-y cell.
Geohashes cover up to +/-90 degrees, but tiles only exist within approximately +/-85.05112878 degrees.
ValueError.clip=True (where supported).To reproduce the benchmark results on your own machine, you must have the repository checked out locally and install the project with both the dev and benchmark extras. You can then run the comparison script provided in the repository.
Note that the benchmark script performs a warmup pass, runs the suite multiple times, and uses pytest-benchmark JSON reports to update the documentation with the observed environment and performance figures. It is recommended to run this on your own hardware before quoting any performance figures.
uv pip install -e ".[dev,benchmark]"
python scripts/run_comparison_benchmark.pyTo use the visualization capabilities (the viz module), you must install the package with the [viz] extra to include necessary dependencies like matplotlib and folium.
pip install pygeohash[viz]You can install pygeohash using pip. Depending on your needs, you can install the base library, include visualization support, or include benchmark dependencies.
pip install pygeohashpip install pygeohash[viz]pip install pygeohash[benchmark]# Basic installation
pip install pygeohash
# With visualization support
pip install pygeohash[viz]
# With the cross-library benchmark comparison dependencies
pip install pygeohash[benchmark]To use the pygeohash.viz module for plotting geohashes with Matplotlib or creating interactive maps with Folium, you must install the optional visualization dependencies.
You can install them via pip:
pip install pygeohash[viz]If you are working within the repository source, you can also use the provided Makefile commands:
# Install visualization dependencies
make install-viz
# Generate visualization examples
make viz-examples