【问题标题】:How Can I get the start and end node of the nearest edge to large points faster?如何更快地获得离大点最近的边的开始和结束节点?
【发布时间】:2019-08-26 14:31:17
【问题描述】:

我有 DataFrame 包含两列(纬度,经度)30000 点如下:

我需要获取到每个点最近的边的开始节​​点和结束节点。

我使用 osmnx 库 (https://osmnx.readthedocs.io/en/stable/search.html?q=get_nearest_edge&check_keywords=yes&area=default#) 中的方法将以下代码用于示例(仅包含 5 个点):

def find_nearest_edges(row):
    near_edge=ox.get_nearest_edge(G,(row['LATITUDE'],row['LONGITUDE']))
    start=intr_stp_nodes[1]
    end=intr_stp_nodes[2]
    return pd.Series([start,  end])
sample_df[['start','end']]=sample_df.apply(find_nearest_edges,axis=1)

虽然我得到了Resulting数据框,但是计算5个点还是花了很多时间:

生成的数据框:

我尝试使用@gboeing 推荐并创建下一个函数:

def find_nearest_edges(row): 
    shp,start,end=ox.get_nearest_edges(G,row['LONGITUDE'],row['LATITUDE'],method='kdtree',dist=0.0001) 
    return pd.Series([start, end]) 

sample_df[['start','end']]=sample_df.apply(find_nearest_edges,axis=1)

我应用了之前的功能,但它需要很长时间而没有任何结果。

【问题讨论】:

    标签: pandas performance osmnx


    【解决方案1】:

    您可以将 ox.get_nearest_edges 与 kdtree 结合使用,以快速查找到一组 xy 点的最近边:https://osmnx.readthedocs.io/en/stable/osmnx.html#osmnx.utils.get_nearest_edges

    【讨论】:

    猜你喜欢
    • 2012-12-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-10-16
    相关资源
    最近更新 更多