Skip to main content

polygon-geohasher

Polygon Geohasher is an open source Python package for converting Shapely's polygons into a set of geohashes. It obtains the set of geohashes inside a polygon or geohashes that touch (intersect) the polygon. This library uses python-geohash and shapely.

Requirements

Polygon Geohasher requires:

  • Python >= 3.x.
  • GEOS >= 3.3 (due to shapely).

Installing

Linux users can get Polygon Geohasher from the Python Package Index with pip (8+):

$ pip install polygon-geohasher

Usage

Here are some simple examples:

from polygon_geohasher import polygon_to_geohashes, geohashes_to_polygon
from shapely import geometry

polygon = geometry.Polygon([(-99.1795917, 19.432134), (-99.1656847, 19.429034),
                            (-99.1776492, 19.414236), (-99.1795917, 19.432134)])
inner_geohashes_polygon = geohashes_to_polygon(polygon_to_geohashes(polygon, 7))
outer_geohashes_polygon = geohashes_to_polygon(polygon_to_geohashes(polygon, 7, False))

Benchmarking

Compare the optimized implementation against the legacy algorithm:

$ .venv/bin/python benchmarks/polygon_to_geohashes.py --iterations 5 --precision 7

Use --inner or --outer to focus on a single mode, and --no-validate to skip output validation.

geohash_to_polygon(geohash):

This function receives a geohash and returns a Shapely's Polygon.

geohashes_to_polygon(geohashes):

This function receives a set of geohashes and returns a Shapely's Polygon or MultiPolygon.

polygon_to_geohashes(polygon, precision[, inner=True]):

This function receives a Shapely's Polygon and the precision of geohashes to be used to create a polygon and returns a set of geohashes (strings) that covers said polygon. It also receives an optional parameter inner that defines the way in which those polygons will be created. If an inner parameter is given, then only contained geohashes will be used; otherwise, intersected geohashes will be used.

See geohashed polygons resulting from both options (with and without inner) in the following example:

Example

Metadata

Release files for polygon-geohasher 0.0.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for polygon-geohasher 0.0.2
File Size Uploaded
polygon_geohasher-0.0.2.tar.gz 4.8 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for polygon-geohasher 0.0.2
File Interpreter ABI Platform
polygon_geohasher-0.0.2-py3-none-any.whl Python 3 none any Details

Total release size: 10.5 kB

Release files / polygon_geohasher-0.0.2.tar.gz

Download URL polygon_geohasher-0.0.2.tar.gz
Size 4.8 kB
Tags Source
SHA-256 checksum
How to use checksums
3c7eb95e3ee85028bf2337a17a3c61ca3088d588b57752bb2bf3b5c67690a14e
BLAKE2b-256 checksum
How to use checksums
b6ba33c6602bb15fe0526e7eee73dde44eae9d0a6e3bdf927e02f4172fca47a5
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.14.2

Release files / polygon_geohasher-0.0.2-py3-none-any.whl

Download URL polygon_geohasher-0.0.2-py3-none-any.whl
Size 5.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
b0b34e6b96a43f10e792926d93711a6a760ea112df88027b5dbd0051ca5d5f78
BLAKE2b-256 checksum
How to use checksums
f60b563d1c7930f78324f8cb5f932be0f32955aea08eb39041ba918092f11ca3
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.14.2

Release history Release notifications | RSS feed

This release

0.0.2 This release

2 release files

0.0.1

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page