In [34]:
import networkx as nx
import osmnx as ox
place = 'Hong Kong Island,Hong Kong'
G = ox.graph_from_place(place, network_type='drive')
In [35]:
ox.plot_graph(G)
Out[35]:
(<Figure size 800x800 with 1 Axes>, <Axes: >)
In [36]:
orig = list(G)[0]
print(orig)
24533064
In [37]:
dest = list(G)[-1]
print(dest)
11696541109
In [38]:
route = nx.shortest_path(G, orig, dest, weight='length')
print(route)
[24533064, 1618530627, 6180007018, 5464743242, 5464771735, 8353799771, 9938957350, 1618530604, 288361310, 232216520, 5090469984, 5090469981, 5090446026, 232221477, 2285675771, 232221479, 2688575200, 2688586799, 2688581881, 232221524, 8394547231, 4858149666, 635737209, 232221586, 232221594, 239989632, 239989634, 1072934548, 239989636, 10166403999, 10166403998, 10166424918, 5157524450, 1072934398, 1071364113, 1683192344, 1683192349, 1683192361, 1683192313, 5035465466, 5035465469, 1683192299, 1683192292, 11696541109]
In [39]:
fig, ax = ox.plot_graph_route(G, route, route_linewidth=6, node_size=0, bgcolor='k')
In [ ]:
Resources:
1. https://geoffboeing.com/2016/11/osmnx-python-street-networks/
2. https://osmnx.readthedocs.io/