I am trying to figure out how to find all the shortest paths from each point and each node of a line to the other points and nodes of lines of this map.
I have tried to do it in Python using NetworkX. For testing, I clipped the map and tried to only look for the shortest paths from each node of a line to every other nodes of other lines of this map:
With that road network, I have 214 nodes (which should result in 214x214 shortest paths, I think). I have tried to make the graph of the road network with this code:
#Create the network graph
G = nx.DiGraph()
for k,v in idict.items():
G.add_edge(v[0],v[1], weight = v[2]) # v[0] = first (x,y) of a linestring, v[1] = last (x,y) of a linestring, v[2] = distance
G.add_edge(v[1],v[0], weight = v[2]) # return path
len(G.edges())
pos = nx.spring_layout(G)
nx.draw_networkx_nodes(G, pos = pos, node_size=20,arrows = True)
nx.draw_networkx_edges(G, pos = pos)
plt.show()
And the result shows:
I've also tried to apply the networkx floyd warshall function to calculate all shortest paths from each point to another point but some of the results return to infinity (as I think it says that no path is found between the points, while actually all paths are connected). All in all, it only returns to about 1720 shortest paths
How should I proceed to have the shortest path of each node to every other nodes in the map?