Python 列表';对象没有属性';xy';-NetworKX
我使用OSMnx根据get_nearest_node在节点ID上生成一个列表,并在源节点和目标节点之间生成一条通过列表中所有节点的路由 Python代码:Python 列表';对象没有属性';xy';-NetworKX,python,networkx,osmnx,Python,Networkx,Osmnx,我使用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 i
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'
AttributeError回溯(最近一次调用)
在里面
23用于范围内的id(长度(id)-1):
24 route=nx.最短路径(GG,ids[id],ids[id+1])
--->25米=ox.plot\u route\u folium(GG,route,route\u color='green')
26 st='date{da}.html'。格式(da=d)
27
~\Anaconda3\lib\site packages\osmnx\plot.py在plot\u route\u folium中(G、route、route\u map、popup\u属性、平铺、缩放、拟合边界、route\u颜色、route\u宽度、route\u不透明度)
919
920#获取路线质心
-->921 x,y=gdf_管线_边。一元_并集。质心。xy
922路线_质心=(y[0],x[0])
923
~\Anaconda3\lib\site packages\shapely\geometry\point.py in xy(self)
145 [0.0]
146 """
-->147返回self.coords.xy
148
149
AttributeError:“列表”对象没有属性“xy”
TIA显示完整的错误消息。第一个循环看起来不规则,你能分享更多的代码吗?@AMC,所以我玩了它,当我删除plot route函数时,我可以打印每个路由的节点ID。所以我的问题是如何将我在两个节点之间生成的路由连接到一个更大的路由,然后用fol来打印它嗯