DPM
DPM

Reputation: 935

Error when trying to extract the information from Polygon OSMNX

When I try to extract information from the Manhattan polygon:

import osmnx as ox

city = ox.geocode_to_gdf(['Manhattan, New York, USA'])

G = ox.graph_from_polygon(city, network_type='drive', simplify=True)
G_nx = nx.relabel.convert_node_labels_to_integers(G)
nodes, edges = ox.graph_to_gdfs(G_nx, nodes=True, edges=True)

I get the following error:

ValueError: The truth value of a Series is ambiguous. Use a.empty, a.bool(), a.item(), a.any() or a.all().

Is this due to the fact that city is a MultiPolygon?

Upvotes: 0

Views: 660

Answers (1)

gboeing
gboeing

Reputation: 6422

Your city variable is a geopandas GeoDataFrame. The graph_from_polygon function expects the polygon argument to be of type shapely Polygon or MultiPolygon. See the docs. You're passing it an argument of the wrong type.

import networkx as nx
import osmnx as ox
city = ox.geocode_to_gdf(['Manhattan, New York, USA'])
polygon = city.iloc[0]['geometry']
G = ox.graph_from_polygon(polygon, network_type='drive', simplify=True)
G_nx = nx.relabel.convert_node_labels_to_integers(G)
nodes, edges = ox.graph_to_gdfs(G_nx, nodes=True, edges=True)

Upvotes: 2

Related Questions