OSMNX图形到距离矩阵和DBSCAN

问题描述

我在编程时很难从坐标图(LAT,LON)中获取距离矩阵。

我想连接任意一组点(比如说200.000个公司),并在图中用ox.graph_from_place()创建它们的最近值。

我正在使用dask数组和数据帧(da.arraydf.DataFrame

if __name__ == "__main__":

    # OPTION B: Use a strongly (instead of weakly) connected graph 
    Gs = ox.utils_graph.get_largest_component(G,strongly=True) 
    Gs.__name__ = "Gs"

    # attach nearest network node to each firm
    df["nn"] =  da.array(ox.get_nearest_nodes(Gs,X=df['longitude'],Y=df['latitude'],method='balltree') ) 

    # we'll get distances for each pair of nodes that have firms attached to them
    nodes_unique = pd.Series(df['nn'].unique()) 
    nodes_unique.index = nodes_unique.values 

    # convert MultiDiGraph to DiGraph for simpler faster distance matrix computation 
    G_dm = nx.DiGraph(Gs)
    G_dm.__name__ = "G_dm"

    save_pickle(Gs)
    save_pickle(G_dm)

    print("len df['nn']:",len(df['nn'])) 
    print("len nodes_unique:",len(nodes_unique)) 

避免了某些代码成为问题的核心,然后,我尝试使用强连接图network_distance_matrix()遵循https://networkx.org/documentation/stable/reference/algorithms/shortest_paths.htmlGs函数,但是在计算时间上如此低效。我在docs中看到了一堆函数,但是我还没有看到一个函数能够有效地计算属于Graph的一对独特节点之间的距离矩阵,以及通过它的路径。

我想知道是否有任何方法可以并行化此过程,和/或使其以一种生成方式进行,而不是存储所有的RAM。

我的目标是在DBSCAN(sklearn.clustering)模型中提供一个预先计算的矩阵,而且它必须快速运行,这样我就可以通过“ grid-search” 参数。我是这些图书馆的初学者。

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)