You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何通过OSMnx从OpenStreetMap获取荷兰Nootdorp 284公交线路的节点列表?

解决OSMnx获取Nootdorp 284路公交线路的问题

方法一:直接通过OSM关系ID获取(最精准)

既然你已经掌握目标线路的OSM关系ID(2024408),直接用osmnx.features.features_from_id方法获取,避开place边界匹配和标签过滤的潜在问题:

import osmnx as ox

# 直接通过关系ID定位公交线路
gdf_busline = ox.features.features_from_id("R2024408")

# 查看线路核心信息
print(gdf_busline[['name', 'route', 'members']])

方法二:优化区域查询的标签与范围

如果坚持用区域查询,需要更精准的标签过滤,同时确保查询范围覆盖线路全程:

import osmnx as ox

# 加入线路名称标签缩小范围,同时扩大查询区域至南荷兰省
gdf_busline = ox.features.features_from_place(
    "South Holland, Netherlands",
    tags={'type': 'route', 'route': 'bus', 'name': '284'}
)

print(gdf_busline)

提取线路的节点列表

获取到公交线路的relation数据后,解析members字段提取所有节点:

# 取出目标线路的成员列表
members = gdf_busline.iloc[0]['members']

# 过滤出节点类型的成员,提取节点ID
node_ids = [member['ref'] for member in members if member['type'] == 'node']

# 批量获取节点的地理信息
nodes_gdf = ox.features.features_from_ids(node_ids, tags={'type': 'node'})

# 输出节点经纬度列表
node_coords = list(zip(nodes_gdf['y'], nodes_gdf['x']))
print("线路节点经纬度列表:", node_coords)

原方法返回空的原因

  • features_from_place的"place"边界可能未完整覆盖284路的所有路段,导致查询时遗漏目标线路
  • 初始标签过滤不够精准,仅靠type和route标签可能无法定位到特定线路,加入name标签能大幅缩小匹配范围

内容的提问来源于stack exchange,提问作者laurens k

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.30 09:08:18