我正在使用OSMnx根据get_nearest_node生成有关节点ID的列表,并在通过该列表中所有节点的起点和终点之间生成一条路由。
Python代码:
ids = []
for r in range(len(df)):
location = df.iloc[r]['location'] #(lat,lon)
some_node_id = ox.get_nearest_node(GG,location)
ids.append(some_node_id)
for id in range(len(ids)-1):
route = nx.shortest_path(GG,ids[id],ids[id+1])
m = ox.plot_route_folium(GG, route, route_color='green') #ERROR at this line
m.save('route.html')
我尝试打印ID列表,看起来不错,那么可能是此错误的原因吗?
AttributeError Traceback (most recent call last)
<ipython-input-91-fc82d1877717> in <module>
23 for id in range(len(ids)-1):
24 route = nx.shortest_path(GG,ids[id],ids[id+1])
---> 25 m = ox.plot_route_folium(GG, route, route_color='green')
26 st = 'date {da}.html'.format(da=d)
27
~\Anaconda3\lib\site-packages\osmnx\plot.py in plot_route_folium(G, route, route_map, popup_attribute, tiles, zoom, fit_bounds, route_color, route_width, route_opacity)
919
920 # get route centroid
--> 921 x, y = gdf_route_edges.unary_union.centroid.xy
922 route_centroid = (y[0], x[0])
923
~\Anaconda3\lib\site-packages\shapely\geometry\point.py in xy(self)
145 [0.0]
146 """
--> 147 return self.coords.xy
148
149
AttributeError: 'list' object has no attribute 'xy'
TIA