首页 > 解决方案 > 从 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])

如何从作为 GeoSeries 的 POIS['geometry'] 对象获取纬度和经度的 tules 列表,以便在上面的最后一行代码中将其传递给 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)

标签: pythongeopandasosmnx

解决方案


这是一个最小的可重现解决方案(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')

推荐阅读