python中pygeohash库用法详解
python中pygeohash库用法详解
·
1、库安装:
pip install pygeohash
2、简单操作
示例代码:
from pygeohash import encode, decode, geohash_approximate_distance
aa = encode(42.6, -5.6)
print(aa)
bb = encode(42.6, -5.6, precision=5)
print(bb)
cc = decode('ezs42e44yx96')
print(cc)
dd = decode('ezs42')
print(dd)
ee = geohash_approximate_distance(geohash_1='bcd3u', geohash_2='bc83n')
print(ee)
ff = geohash_approximate_distance('shi3u', 'sh83n')
print(ff)
运行结果:
3、使用pygeohash批量解码
要使用pygeohash批量解码,可以将要解码的地理哈希值存储在一个列表中,然后使用循环逐个解码。
示例代码:
import pygeohash
geohashes = ['wx4g09', 'wx4g0b', 'wx4g0c', 'ezs42', 'ezs42t37ccsp'] # 要解码的地理哈希列表
for geohash in geohashes:
latitude, longitude = pygeohash.decode(geohash)
print(f'Geohash: {geohash} Latitude: {latitude} Longitude: {longitude}') # 输出的精度是由要解码的地理哈希值决定的
运行结果:
在这个示例中,我们创建了一个包含五个地理哈希值的列表geohashes。然后,我们使用for循环遍历列表中的每个地理哈希值,并使用pygeohash.decode()函数解码每个地理哈希值。解码后,我们将得到的纬度和经度打印输出。
更多推荐
所有评论(0)