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

基于Overpass API获取道路内部车道几何信息的技术咨询

问题:如何从OpenStreetMap获取道路内部车道的几何坐标?

我编写了一段Python脚本,输入经纬度后可生成包含道路边缘、人行横道及车道信息的GeoJSON。脚本如下:

def fetch_intersection_data(lat, lon, radius: int = 20):
    """
    Fetch intersection data from OpenStreetMap using Overpass API and convert to GeoJSON.
    
    :param lat: Latitude of the center of the intersection
    :param lon: Longitude of the center of the intersection
    :param radius: Radius around the point to search (in meters)
    :return: GeoJSON data as a dictionary
    """
    overpass_url = "http://overpass-api.de/api/interpreter"
    overpass_query = f"""
                [out:json];
                (
                way["highway"](around:{radius},{lat},{lon});
                node["highway"="crossing"](around:{radius},{lat},{lon});
                way["lanes"](around:{radius},{lat},{lon});
                way["lanes:forward"](around:{radius},{lat},{lon});
                way["lanes:backward"](around:{radius},{lat},{lon});
                );
                out geom;
    """
    print(overpass_query)
    response = requests.get(overpass_url, params={'data': overpass_query})
    osm_data = response.json()

    with open('raw_data.json', 'w') as f:
        json.dump(osm_data, f)

    try:
        features = []

        for element in osm_data['elements']:
                feature = {
                    "type": "Feature",
                    "properties": element.get('tags', {}),
                    "geometry": None
                }
                
                if element['type'] == 'way':
                    if 'geometry' in element:
                        feature['geometry'] = {
                            "type": "LineString",
                            "coordinates": [[point['lon'], point['lat']] for point in element['geometry']]
                        }
                    feature['properties']['id'] = element['id']

                elif element['type'] == 'node':
                    feature['geometry'] = {
                        "type": "Point",
                        "coordinates": [element['lon'], element['lat']]
                    }
                    feature['properties']['id'] = element['id']
                
                if feature['geometry']:
                    features.append(feature)
            
        geojson = {"type": "FeatureCollection","features": features}
    
    except Exception as e:
        print(e)

    return geojson

目前脚本已实现大部分需求,在geojson.io上可视化效果符合预期,但缺少道路内部车道的几何坐标。我希望获取该信息以绘制类似示例图中红色车道的效果,然而API返回的JSON中并无此数据,请问是查询语句存在遗漏还是该信息在OpenStreetMap中不存在?


解答

  • OpenStreetMap的车道数据特性:OSM中极少直接存储车道的独立几何坐标。多数道路仅通过lanes、lanes:forward这类标签记录车道数量,而非单独的线条几何。只有极少数经过精细测绘的区域,会用way+highway=lane标签标记独立车道的几何,但这类数据覆盖率极低,不具备普遍性。

  • 当前查询语句的局限:现有查询仅筛选了带lanes系列标签的道路,这类道路返回的是道路整体的几何,而非车道的单独几何。若要尝试查找独立车道的几何,可在查询中添加way["highway"="lane"](around:{radius},{lat},{lon});,但实际能获取到数据的概率非常低。

  • 替代实现方案:若要绘制车道线,更可行的方式是基于道路整体几何,结合lanes等标签信息,通过算法偏移道路中心线生成车道几何:

    1. 通过道路的width标签获取宽度(若无则使用默认值),结合车道数计算单条车道的宽度
    2. 对道路的LineString进行左右方向的偏移,生成每条车道的线条
    3. 结合oneway、lanes:forward等标签区分单向/双向车道的方向,调整偏移逻辑

内容的提问来源于stack exchange,提问作者Paulo Henrique PH

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.20 10:54:50