坐标+半径 生成 geohash
- 使用numpy 和 shaply 根据坐标+半径300米生成20个点的polygon;
- 根据polygon 转成polygon 包含的geohash 列表;
import geog
import numpy as np
import shapely.geometry
from polygon_geohasher.polygon_geohasher import polygon_to_geohashes
p = shapely.geometry.Point([121.499639, 31.239444])
n_points = 20
d = 3 * 100 # meters
angles = np.linspace(0, 360, n_points)
polygon = geog.propagate(p, angles, d)
geohash_list = polygon_to_geohashes(shapely.geometry.Polygon(polygon), 7)
print(polygon)
print(geohash_list)
输出结果如下:
[[121.50279449 31.23944396]
[121.50262354 31.24031999]
[121.50212917 31.2411011 ]
[121.50136493 31.24170263]
[121.50041365 31.24205941]
[121.49937841 31.24213275]
[121.49837142 31.24191472]
[121.4975018 31.24142894]
[121.49686379 31.24072806]
[121.49652654 31.23988803]
[121.49652656 31.23899989]
[121.49686387 31.23815988]
[121.49750189 31.23745903]
[121.49837149 31.23697327]
[121.49937843 31.23675525]
[121.5004136 31.23682859]
[121.50136485 31.23718534]
[121.50212908 31.23778685]
[121.50262349 31.23856794]
[121.50279449 31.23944396]]
{'wtw3syc', 'wtw3sz1', 'wtw3syf', 'wtw3syb', 'wtw3sz4', 'wtw3sz0'}