清理图形上的已划分道路以精确计算x距离内的交叉点

时间:2019-05-02 23:07:12

标签: python networkx osmnx

我正在尝试计算图形的每个边缘的x距离内的交点数量,然后使用色带进行显示,但是分开的道路会显示为多个交点,而不仅仅是一个交点。

下面的脚本显示了我当前使用osmnx创建图,然后使用networkx最短路径来查找所有节点上的路径的工作。返回x距离内的计数,然后返回边缘节点的平均值。

我知道osmnx具有干净的交集功能,但是它不与现有图形集成。

import osmnx as ox
import networkx as nx

location = 'location'
distance = x
net_type = 'drive'

G = ox.graph_from_place(location, buffer_dist=distance, network_type=net_type)
G = ox.project_graph(G)

shortest = nx.shortest_path_length(G, weight='length')

count_list = []
for node in list(shortest):
    int_count = 0
    for key in node[1]:
        if node[1].get(key) <= 400:
            int_count += 1
        else:
            break
    count_list.append(int_count)

intersections = dict(zip(G.nodes, count_list))

nx.set_node_attributes(G, intersections, 'int400')

nodes = list(G.nodes)
data_nodes = list(G.nodes(data=True))
for edge in G.edges(data=True):
    node_from = data_nodes[nodes.index(edge[0])][1]['int']
    node_to = data_nodes[nodes.index(edge[1])][1]['int']
    average = round(((node_from + node_to) / 2))
    edge[2]['int'] = average

我希望它只计算道路与分开的道路相交的单个路口。

我对使用它们很陌生,因此上面的一些代码也可以用不同的方式来完成。但是我的主要重点是为图中的每个节点/边获得准确的交点计数。

是否可以使用osmnx干净交集函数并将其与现有图形集成,从而调整边缘到新节点的from / to属性?

我在想,您也许能够确定要删除的节点,然后用替换该ID的新节点ID替换该ID的任何实例,但是我不知道这是否可行。

感谢帮助。

1 个答案:

答案 0 :(得分:0)

  

是否可以使用osmnx干净交集函数并将其与现有图形集成,从而调整边缘到新节点的from / to属性?

当前有一个添加此功能的拉取请求:https://github.com/gboeing/osmnx/pull/249

通常,在这一点上,您需要创建图形的投影副本,将交点清理到一定的米公差范围内,然后计算该图形上的交点。