0

I'm generating a list on nodes ids according to get_nearest_node with OSMnx and generate a route between origin and destination that pass all the nodes in my list.

Python code:

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')

I tried to print ids list and it looks fine, so what could be the reason for this error?

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

Roy Ancri
  • 119
  • 2
  • 14
  • 1
    show the complete error message. – eyllanesc Dec 29 '19 at 23:16
  • That first loop looks unidiomatic, can you share more of your code? – AMC Dec 29 '19 at 23:52
  • @AMC, So I played with it and when I remove the plot route function, I could print the nodes ids for each route. So my problem is how to concatenate the route I generated between each two nodes to a larger one and then to plot it with folium – Roy Ancri Dec 30 '19 at 11:09

0 Answers0