Skip to main content

Wrapper over Shapely that returns the set of geohashes that form a Polygon.

Project description

polygon-geohasher-2

[!NOTE] This is a minimally maintained fork of the original Bonsanto/polygon-geohasher repo, which does not appear to be actively maintained.

The original project is published to PyPi under the package name polygon-geohasher; this project is published under the package name polygon-geohasher-2. My goal is to provide a stable package that works with all actively maintained Python versions (those with a status of bugfix or security here). I will likely not implement any feature enhancements, but contributions are welcome!

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.10, < 3.15.
  • GEOS >= 3.3 (due to shapely).

Supported Python & Shapely Versions

Python Version Shapely 1 Shapely 2
3.10 :heavy_check_mark: :heavy_check_mark:
3.11 :heavy_check_mark: :heavy_check_mark:
3.12 :x: :heavy_check_mark:
3.13 :x: :heavy_check_mark:
3.14 :x: :heavy_check_mark:

Installing

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

$ pip install polygon-geohasher-2

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))

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

Development

To install the development environment:

$ pip install -r requirements-dev.txt

To run the tests:

$ pytest

To run the linter:

flake8 .

Type Checking

This project uses mypy to check type annotations. Please run the following command prior to submitting a PR:

$ mypy .

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

polygon_geohasher_2-0.2.0.tar.gz (5.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

polygon_geohasher_2-0.2.0-py3-none-any.whl (6.4 kB view details)

Uploaded Python 3

File details

Details for the file polygon_geohasher_2-0.2.0.tar.gz.

File metadata

  • Download URL: polygon_geohasher_2-0.2.0.tar.gz
  • Upload date:
  • Size: 5.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for polygon_geohasher_2-0.2.0.tar.gz
Algorithm Hash digest
SHA256 fbf088ebaf0e57e445cb706c449817da7765a2d9602b6fe39835a44db1820c65
MD5 5906b9b67014628324927ab4a074e9ca
BLAKE2b-256 ab9363252b05d079757dab14cb0037e6255dd4dad0b80315f2602ee346759600

See more details on using hashes here.

Provenance

The following attestation bundles were made for polygon_geohasher_2-0.2.0.tar.gz:

Publisher: python_publish.yml on duckontheweb/polygon-geohasher

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file polygon_geohasher_2-0.2.0-py3-none-any.whl.

File metadata

File hashes

Hashes for polygon_geohasher_2-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 78bc2ce629e5ca415239eccd6bc1384c90a8cb2fcce043cc26c898c0afdf7d28
MD5 df8321eb80d01afd069630cb8913dec7
BLAKE2b-256 e5b2bff55b80a634d147ae041b7d5ffdad84d918a21a79188edf05a71ec03020

See more details on using hashes here.

Provenance

The following attestation bundles were made for polygon_geohasher_2-0.2.0-py3-none-any.whl:

Publisher: python_publish.yml on duckontheweb/polygon-geohasher

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page