Welcome to Geolib’s documentation!

https://img.shields.io/badge/python-2.7|3.4|3.5|3.6|3.7-blue.svg

geolib.geohash

Geohash encoding/decoding and associated functions (c) Chris Veness 2014-2016 / MIT Licence https://www.movable-type.co.uk/scripts/geohash.html

http://en.wikipedia.org/wiki/Geohash

geolib.geohash.adjacent(geohash, direction)[source]

Determines adjacent cell in given direction.

Parameters:
  • geohash – cell to which adjacent cell is required
  • direction – direction from geohash, string, one of n, s, e, w
Returns:

geohash of adjacent cell

>>> geohash.adjacent('gcpuyph', 'n')
>>> gcpuypk
geolib.geohash.bounds(geohash)[source]

Returns SW/NE latitude/longitude bounds of a specified geohash:

   |      .| NE
   |    .  |
   |  .    |
SW |.      |
Parameters:geohash – string, cell that bounds are required of
Returns:a named tuple of namedtuples Bounds(sw(lat, lon), ne(lat, lon)).
>>> bounds = geohash.bounds('ezs42')
>>> bounds
>>> ((42.583, -5.625), (42.627, -5.58)))
>>> bounds.sw.lat
>>> 42.583
geolib.geohash.decode(geohash)[source]

Decode geohash to latitude/longitude. Location is approximate centre of the cell to reasonable precision.

Parameters:geohash – string, cell that bounds are required of
Returns:Namedtuple with decimal lat and lon as properties.
>>> geohash.decode('gkkpfve')
>>> (70.2995, -27.9993)
geolib.geohash.encode(lat, lon, precision)[source]

Encode latitude, longitude to a geohash.

Parameters:
  • lat – latitude, a number or string that can be converted to decimal. Ideally pass a string to avoid floating point uncertainties. It will be converted to decimal.
  • lon – longitude, a number or string that can be converted to decimal. Ideally pass a string to avoid floating point uncertainties. It will be converted to decimal.
  • precision – integer, 1 to 12 represeting geohash levels upto 12.
Returns:

geohash as string.

>>> geohash.encode('70.2995', '-27.9993', 7)
>>> gkkpfve
geolib.geohash.neighbours(geohash)[source]

Returns all 8 adjacent cells to specified geohash:

| nw | n | ne |
|  w | * | e  |
| sw | s | se |
Parameters:geohash – string, geohash neighbours are required of
Returns:neighbours as namedtuple of geohashes with properties n,ne,e,se,s,sw,w,nw
>>> neighbours = geohash.neighbours('gcpuyph')
>>> neighbours
>>> ('gcpuypk', 'gcpuypm', 'gcpuypj', 'gcpuynv', 'gcpuynu', 'gcpuyng', 'gcpuyp5', 'gcpuyp7')
>>> neighbours.ne
>>> gcpuypm

Module contents

Indices and tables