如何使最近的边的起点和终点更快地到达大点?

时间:2019-04-04 18:21:41

标签: pandas performance osmnx

我让DataFrame包含两列(纬度,经度),用于30000点,如下所示:

enter image description here

我需要获取距每个点最近的边缘的起点和终点。

我使用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)

尽管我得到了“结果”数据帧,但它花了很多时间来计算5分:

结果数据框:

enter image description here

1 个答案:

答案 0 :(得分:0)

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