Skip to main content

Geohash tools for performing geohash related tasks.

Project description

Geohash tools

Python module which supports geohash geocode system based on space-filling curves, announced in 2008 by Gustavo Niemeyer. System allows to encode 2-dimensional data as sequence of characters, where number of characters determines accuracy of decoded information.

More detailed information about mathematics behind Geohash can be found here:

Wikipedia: https://en.wikipedia.org/wiki/Geohash

Important links:

Package is inspired by its Ruby equivalent: https://github.com/masuidrive/pr_geohash
Github: https://github.com/Jakub-Markowiak/geohash-tools
PyPI repository: https://pypi.org/project/geohash-tools/

Quick start

Install directly from PyPI repository:

    pip install geohash-tools

Import geohash tools to your python module using following command:

    import geohash_tools as gh

Features

Module provides tools that allows user to perform basic geohash-related operations:

Coding:

  • encode(lat,lon,precision) – encode geographical coordinates as geohash with demanded precision (number of characters),
  • decode(geohash) – decode geographical coordinates as (latitude,longitude) tuple.

Neighbours:

  • adjacent(geohash, direction) – find geohash adjacent to geohash specified in input in chosen direction. Returns adjacent geohash with same precision. Allowed directions are top, right, bottom, left,
  • neighbours(geohash, include_self=True, show=False) – find adjacent geohashes in all 8 directions. If show argument is set to True, simple ascii map will be printed.

Measurements:

  • distance(geohash_1, geohash_2) – calculate exact distance between pair of geohashes using haversine formula.

Examples

There are presented some simple examples which purpose is to make user more familiar with functions presented in Features section.

Encoding geohash

>>> import geohash_tools as gh
# Default precision is set to 6 characters
>>> gh.encode(52.41419458448101, 16.899256413657202)
'u3k40t'
>>> gh.encode(52.41419458448101, 16.899256413657202, precision=9)
'u3k40t9wv'

Decoding geohash

>>> gh.decode('u3k40t')
(52.41302490234375, 16.9024658203125)

>>> gh.decode('u3k40t9wv')
(52.4142050743103, 16.899268627166748)

Find adjacent geohash

>>> gh.adjacent('u3k40t', 'top')
'u3k40w'

>>> gh.adjacent('u3k40t9wv', 'left')
'u3k40t9wu'

Find geohash neighbours

>>> gh.neighbours('u3k40w')
['u3k40r', 'u3k40x', 'u3k40z', 'u3k40q', 'u3k40w', 'u3k40y', 'u3k40m', 'u3k40t', 'u3k40v']

>>> gh.neighbours('u3k40t9wv', show=True)

u3k40t9xh|u3k40t9xj|u3k40t9xn
---------|---------|---------
u3k40t9wu|u3k40t9wv|u3k40t9wy
---------|---------|---------
u3k40t9ws|u3k40t9wt|u3k40t9ww

['u3k40t9xh', 'u3k40t9xj', 'u3k40t9xn', 'u3k40t9wu', 'u3k40t9wv', 'u3k40t9wy', 'u3k40t9ws', 'u3k40t9wt', 'u3k40t9ww']        

>>> gh.neighbours('u3k40w', include_self=False)
['u3k40r', 'u3k40x', 'u3k40z', 'u3k40q', 'u3k40y', 'u3k40m', 'u3k40t', 'u3k40v']

Calculate distance between 2 geohashes

>>> gh.distance('u3k40t9wv', 'u3k40')
26666.04332847212

License

MIT License

Copyright (c) 2022 Jakub Markowiak

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Contact

Jakub Markowiak: jamarkowiak@gmail.com

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

geohash_tools-0.2.0.tar.gz (5.8 kB view details)

Uploaded Source

File details

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

File metadata

  • Download URL: geohash_tools-0.2.0.tar.gz
  • Upload date:
  • Size: 5.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.9.7

File hashes

Hashes for geohash_tools-0.2.0.tar.gz
Algorithm Hash digest
SHA256 ee39f0bd950a0cdae027f0c08c7e22ba6ecb088a4cab8f2c9c50e6edf8992542
MD5 3505b04403cb14cbc6368364bf1b4c9a
BLAKE2b-256 653e45c169ddc0a8848f086ebf454ca4c933501266a06b6716472fc310c598c9

See more details on using hashes here.

Supported by

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