【问题标题】:python osmnx - How to download a city district map from OpenStreetMap based on the boundary ID?python osmnx - 如何根据边界 ID 从 OpenStreetMap 下载市区地图?
【发布时间】:2021-03-11 19:56:38
【问题描述】:

osmnx 是一个 Python 工具,可让您从 OpenStreetMap 下载地图并将其作为 Networkx 图使用。例如,我可以使用以下命令获取洛杉矶的街道地图:

osmnx.graph_from_place('Los Angeles, CA, USA', network_type='drive')

现在我正在尝试下载伊朗德黑兰内的一个地区。使用“德黑兰,伊朗”这个名字并没有太大帮助,结果是错误的。但是,城市边界的 OSM ID 为 8775292,如下链接所示:

https://www.openstreetmap.org/relation/8775292

那么,有没有办法给 OSMNx 提供边界 ID 而不是给它命名以进行查询?

谢谢!

【问题讨论】:

    标签: python gis openstreetmap osmnx


    【解决方案1】:

    根据 OSMnx documentation,您可以将地点查询提供为字符串或字典。请参阅usage examples 以了解每个示例。使用 dict 似乎可以很好地返回您正在寻找的城市边界:

    import osmnx as ox
    ox.config(use_cache=True, log_console=True)
    
    # define the place query
    query = {'city': 'Tehran'}
    
    # get the boundaries of the place
    gdf = ox.geocode_to_gdf(query)
    gdf.plot()
    
    # or just get the street network within the place
    G = ox.graph_from_place(query, network_type='drive')
    fig, ax = ox.plot_graph(G, edge_linewidth=0)
    

    如果您用波斯语或英语查询更具体的字符串,它也可以正常工作:

    # query in persian
    gdf = ox.geocode_to_gdf('شهر تهران')
    gdf.plot()
    
    # or in english
    gdf = ox.geocode_to_gdf('Tehran City')
    gdf.plot()
    

    有没有办法给 OSMNx 提供边界 ID 而不是给它命名以供查询

    不,OSMnx 通过查询 Nominatim 地理编码器来检索边界多边形。

    【讨论】:

    • 感谢您亲爱的波音教授回答我的问题,并创建了 OSMnx 包。非常感谢,您在论坛中的出现对社区也有很大帮助。我尝试了你的解决方案,它奏效了。我发现将查询设置为“德黑兰市区 1”也可以。我正在尝试将街道布局用作城市的水管网进行一些水力计算。稍后我必须从 SRTM tiff 文件中提取点高程并将其分配给节点。
    • 太棒了!感谢您通过 by_osmid=True 合并 OSM ID 搜索。非常感谢波音教授。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2020-03-13
    • 2015-10-20
    • 2021-10-12
    • 1970-01-01
    • 1970-01-01
    • 2020-12-20
    • 1970-01-01
    相关资源
    最近更新 更多