从 OSMNX Geoseries 获取坐标列表(纬度、经度)

Getting list of coordinates (lat,long) from OSMNX Geoseries

我想计算目的地列表和起点之间的最短路径。但首先我需要找到离我的目的地最近的节点。我正在从 OSMNX 函数获取一组兴趣点 (geometries_from_place) 的目的地列表。

import osmnx as ox
import geopandas as gpd
import networkx as nx
print(ox.__version__)
ox.config(use_cache=True, log_console=True)
Kinshasa = [ "Kisenso, Mont Amba, 31, Democratic Republic of the Congo",
"N'djili, Tshangu, Democratic Republic of the Congo",
"Kinshasa, Democratic Republic of the Congo"]
G_Kinshasa = ox.graph.graph_from_place(Kinshasa, simplify=True, network_type='drive')
tags2 = {'amenity' : ['hospital','university','social_facility'],
        'landuse' : ['retail', 'commercial'],
         'shop' : ['water','bakery']}
POIS = ox.geometries_from_place(Kinshasa, tags2, which_result=1)
Nearest_Nodes = ox.get_nearest_nodes(G_Kinshasa, POIS['geometry'][x],POIS[geometry][y])

如何从 POIS['geometry'] 对象(GeoSeries)中获取经纬度元组列表,并将其传递给上面最后一行代码中的 get_nearest_nodes? 这是 POIS['geometry']:

的输出示例
Out[10]: 
0                             POINT (15.34802 -4.39344)
1                             POINT (15.34074 -4.41001)
2                             POINT (15.34012 -4.40466)
3                             POINT (15.34169 -4.40443)
4                             POINT (15.35278 -4.40812)

您可以使用简单的 lambda 函数创建列表操作元组。 我没有针对其他可能解决方案的性能进行测试,而是针对 5000 行 x 9 列进行测试。 geodataframe 在中等台式机上大约需要 120 毫秒。

pointlist = list(POIS.geometry.apply(lambda x: ( x.x, x.y )))

这是一个最小的可重现解决方案(OSM 无法以当前形式对您的地点查询进行地理编码,因此我选择了一个仅用于演示目的的解决方案)。请注意,我指定了 balltree 方法来查找最近的节点,因为您正在使用未投影的图形和未投影的点。

import osmnx as ox
ox.config(use_cache=True, log_console=True)

place = 'Berkeley, CA, USA'
G = ox.graph_from_place(place, network_type='drive')

tags = {'amenity' : ['hospital','university','social_facility'],
        'landuse' : ['retail', 'commercial'],
        'shop' : ['water','bakery']}
gdf = ox.geometries_from_place(place, tags)

centroids = gdf.centroid
X = centroids.x
Y = centroids.y

nn = ox.get_nearest_nodes(G, X, Y, method='balltree')