0

I have been trying to overlay different osmnx plots onto folium but I have been unable to. I want to achieve the same thing as shown in the image below with a simple osmnx plot but instead on folium with the red edges being red and the other edges being a different colour.

fig, ax = ox.plot_graph_routes(G,max_response_edges, bgcolor='k', node_size=30, node_color='#999999', node_edgecolor='none', node_zorder=2,
                        edge_color='#555555', edge_linewidth=1.5, edge_alpha=1,figsize = (20,20))

enter image description here

I have tried to use the following code:

H = G.copy()
H1 = G.copy()
H.remove_edges_from(G.edges - set(map(lambda x: tuple(x)+(0,),max_response_edges)))
m = ox.folium.plot_graph_folium(H,tiles='openstreetmap',popup_attribute='name',opacity = 1,color = 'red',weight= 10)
H1.remove_edges_from(set(map(lambda x: tuple(x)+(0,),max_response_edges)))
n = ox.folium.plot_graph_folium(H1,tiles='openstreetmap',popup_attribute='name',opacity = 1,color = 'blue',weight= 10)
n.add_to(m)
m

enter image description here

I tried making use of m.add_child() or m.add_to() but none have proved useful. A similar stack overflow question was posted here however this did not work. Can folium overlays be done?

Rishan
  • 105
  • 1
  • 8
  • 1
    "however this did not work" -- it would help if you could unpack this aspect in detail, as that prior answer was the one that I would give. – gboeing May 04 '21 at 14:49
  • hello @gboeing. I only get the image shown above with red edges only – Rishan May 05 '21 at 15:15

1 Answers1

0

Got it working through the following code

H = G.copy()
H1 = G.copy()
H.remove_edges_from(G.edges - set(map(lambda x: tuple(x)+(0,),max_response_edges)))
m = ox.folium.plot_graph_folium(H,tiles='openstreetmap',popup_attribute='name',opacity = 1,color = 'red',weight= 10)
H1.remove_edges_from(set(map(lambda x: tuple(x)+(0,),max_response_edges)))
m = ox.folium.plot_graph_folium(H1, graph_map = m,tiles='openstreetmap',popup_attribute='name',opacity = 1,color = 'blue',weight= 10)
m

turns out I was missing the graph_map=m parameter

Rishan
  • 105
  • 1
  • 8