用于h3的python绑定,一个由uber技术开发的分层六边形地理空间索引系统
h3的Python项目详细描述
安装
安装此程序时,需要在$PATH中包含cc、make和cmake。 套餐:
which cc /usr/bin/cc which make /usr/bin/make which cmake /usr/bin/cmake
pip install h3
开发
git clone https://github.com/uber/h3-py.git &&cd h3-py virtualenv env source env/bin/activate pip install -r requirements-dev.txt fab bootstrap
用法
下面的可视化是通过 folium。
fromh3importh3
将lat/lng转换为hexagon地址
h3_address=h3.geo_to_h3(37.3615593,-122.0553238,5)# lat, lng, hex resolutionhex_center_coordinates=h3.h3_to_geo(h3_address)# array of [lat, lng]hex_boundary=h3.h3_to_geo_boundary(h3_address)# array of arrays of [lat, lng]
得到六边形的krings
h3.k_ring_distances(h3_address,4)# array of 4 rings with size [1, 6, 12, 18]h3.k_ring(h3_address,4)# a collection of hexagons within kring sizes from 0 to 3
用六边形填充geo json
geoJson={'type':'Polygon','coordinates':[[[37.813318999983238,-122.4089866999972145],[37.7866302000007224,-122.3805436999997056],[37.7198061999978478,-122.3544736999993603],[37.7076131999975672,-122.5123436999983966],[37.7835871999971715,-122.5247187000021967],[37.8151571999998453,-122.4798767000009008]]]}hexagons=list(h3.polyfill(geoJson,8))# resolution 8
有关更多api引用,请参见H3 Documentation。