Closed al-yakubovich closed 2 years ago
Hi. If I create shapely.geometry.MultiPolygon with Shapely and try to convert it into graph with ox.graph.graph_from_polygon module I will get only first polygon as graph and all others are missing.
shapely.geometry.MultiPolygon
ox.graph.graph_from_polygon
from shapely.geometry import Polygon, MultiPolygon import osmnx as ox import networkx as nx p1_long_lat = [(-86.840049, 33.538406), (-86.782240, 33.534072), (-86.773982, 33.465972), (-86.876753, 33.464951)] p1 = Polygon(p1_long_lat) p2_long_lat = [(-86.883929, 33.463853), (-86.866684, 33.458227), (-86.876318, 33.440622), (-86.908593, 33.438854)] p2 = Polygon(p2_long_lat) mp = MultiPolygon([p1, p2]) # type: shapely.geometry.multipolygon.MultiPolygon G = ox.graph.graph_from_polygon(mp) # type: networkx.classes.multidigraph.MultiDiGraph orig = list(G)[0] dest = list(G)[-1] route = nx.shortest_path(G, orig, dest, weight='length') ox.plot_graph_route(G, route, route_linewidth=6, show=False, close=False, edge_color='black', bgcolor='w', edge_alpha=0.5, node_color='black')
mp represents two polygons: but I can see only one graph when use ox.plot_graph_route (there should be two graphs on image):
mp
ox.plot_graph_route
Per the docs, use the retain_all parameter if you wish to retain more than just the largest weakly connected component.
retain_all
Hi. If I create
shapely.geometry.MultiPolygon
with Shapely and try to convert it into graph withox.graph.graph_from_polygon
module I will get only first polygon as graph and all others are missing.mp
represents two polygons: but I can see only one graph when useox.plot_graph_route
(there should be two graphs on image):