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.
Wikipedia: https://en.wikipedia.org/wiki/Geohash
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/
Install directly from PyPI repository:
pip install geohash-tools
Import geohash tools
to your python module using following command:
import geohash_tools as gh
Module provides tools that allows user to perform basic geohash-related operations:
encode(lat,lon,precision)
β encode geographical coordinates as geohash with demanded precision (number of characters),decode(geohash)
β decode geographical coordinates as (latitude,longitude) tuple.
adjacent(geohash, direction)
β find geohash adjacent to geohash specified in input in chosen direction. Returns adjacent geohash with same precision. Allowed directions aretop
,right
,bottom
,left
,neighbours(geohash, include_self=True, show=False)
β find adjacent geohashes in all 8 directions. Ifshow
argument is set toTrue
, simple ascii map will be printed.
distance(geohash_1, geohash_2)
β calculate exact distance between pair of geohashes using haversine formula.
There are presented some simple examples which purpose is to make user more familiar with functions presented in Features section.
>>> 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'
>>> gh.decode('u3k40t')
(52.41302490234375, 16.9024658203125)
>>> gh.decode('u3k40t9wv')
(52.4142050743103, 16.899268627166748)
>>> gh.adjacent('u3k40t', 'top')
'u3k40w'
>>> gh.adjacent('u3k40t9wv', 'left')
'u3k40t9wu'
>>> 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']
>>> gh.distance('u3k40t9wv', 'u3k40')
26666.04332847212
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.
Jakub Markowiak: jamarkowiak@gmail.com