项目作者: joyanujoy

项目描述 :
Python geohash library
高级语言: Python
项目地址: git://github.com/joyanujoy/geolib.git
创建时间: 2018-07-10T17:44:23Z
项目社区:https://github.com/joyanujoy/geolib

开源协议:MIT License

下载


Build Status Documentation python 2.7|3.4|3.5|3.6|3.7 Downloads

Geolib

A python library for geohash encoding, decoding and finding neighbour cells. This is a python port of Chris Veness’ javascript implementation.

Wikipedia reference

Installation

pipenv install geolib
or
pip install geolib

Usage

  1. from geolib import geohash

Encode a latitude, longtiude to geohash

  1. >>> # geohash.encode(latitude, longitude, precision)
  2. >>> geohash.encode('70.2995', '-27.9993', 7)
  3. 'gkkpfve'

Decode a geohash to latitude, longitude

  1. >>> # geohash.decode(geohash), returns latitude, longitude as tuple of decimals
  2. >>> geohash.decode('gkkpfve')
  3. (70.2995, -27.9993)

Find neighbouring cells of a geohash

  1. >>> # geohash.neighbours(geohash)
  2. ... # returns a namedtuple (n, ne, e, se, s, sw, w, nw)
  3. >>> neighbours = geohash.neighbours('gcpuyph')
  4. >>> neighbours
  5. ('gcpuypk', 'gcpuypm', 'gcpuypj', 'gcpuynv', 'gcpuynu', 'gcpuyng', 'gcpuyp5', 'gcpuyp7')
  6. >>> neighbours.ne
  7. 'gcpuypm'

Find adjacent cell in a given direction

  1. >>> # geohash.adjacent(geohash, direction)
  2. >>> geohash.adjacent('gcpuyph', 'n')
  3. 'gcpuypk'

Find SW/NE latitude/longitude bounds of a geohash

  1. >>> # geohash.bounds(geohash)
  2. ... # returns a namedtuple ((sw_lat, sw_lon), ((ne_lat, ne_lon))
  3. >>> bounds = geohash.bounds('ezs42')
  4. >>> bounds
  5. ((42.583, -5.625), (42.627, -5.58)))
  6. >>> bounds.sw.lat
  7. 42.583