尝试从多边形 OSMNX 中提取信息时出错

Error when trying to extract the information from Polygon OSMNX

当我尝试从曼哈顿多边形中提取信息时:

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)

我收到以下错误:

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

这是因为 cityMultiPolygon 吗?

您的 city 变量是一个 geopandas GeoDataFrame。 graph_from_polygon 函数期望 polygon 参数的类型为 shapely Polygon 或 MultiPolygon。参见 the docs。您传递给它的参数类型错误。

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)