python - 从 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)
解决方案
这是一个最小的可重现解决方案(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')
推荐阅读
- javascript - Elegant, concise way to reformat JSON data in Javascript?
- javascript - Issues with code for a simple on page search
- python-3.x - 使用不同 Pandas DataFrame 的散景道奇图
- php - 动态显示产品报告的php代码
- python - (初学者)NLP:我正在尝试了解如何对文本中的单词进行分类以识别与某个主题相关的所有单词
- node.js - 我的节点 socket.io 连接在短时间不活动后自动断开
- sql - 按特定顺序对包含字母和数字的值列表进行排序
- java - 使用 PrintWriter 时已为此响应调用 getOutputStream()
- python - 使用 pandas 中的数据框,我如何附加一个只有某些列相同的数据框?
- python - 如果 A 列中的单元格为空,则修改 B 列中的单元格