openstreetmap是免费地理数据下载的网站,而osmnx是一个用于从openstreetmap下载边界并分析和可视化街道网络python包是Geoff Boeing大神所编写,安装OSMnx时建议在anaconda下安装[人生苦短,快用anaconda],如果不想装anaconda也可以使用Miniconda轻量级;osmnx依赖geopandas库geopandas库又依赖gdal、fiona、pyproj、pandas等等

1.获取深圳行政区域和深圳道路网络集

import osmnx as ox

city=ox.gdf_from_place("南山区,深圳市,中国")

print city

ox.plot_shape(ox.project_gdf(city))

0818b9ca8b590ca3270a3433284dd417.png

treet=ox.graph_from_place("shenzhen,china",which_result=2)

ox.plot_graph(treet)

0818b9ca8b590ca3270a3433284dd417.png

通过某一位置查询,例如腾讯总部大厦周围的1公里驾驶道路网

location =ox.graph_from_point((22.5436253,113.9299285),distance=1000,network_type='drive')

ox.plot_graph(location)

0818b9ca8b590ca3270a3433284dd417.png

2.下载道路网络到本地磁盘并保存shp格式

treet=ox.graph_from_place("shenzhen,china",which_result=2)

ox.plot_graph(treet)

ox.save_graph_shapefile(treet,filename='sz')

0818b9ca8b590ca3270a3433284dd417.png

当然也可以做简单的拓扑和分析,大家可以根据自已需求尽情玩一玩。

参考文献

Logo

技术共进,成长同行——讯飞AI开发者社区

更多推荐