I have a dictionary of coordinates I am using for the placement of nodes. I am using the networkx module for making graphs.
For my project, i need to know the real distance in m or km of al the edges in the graph. I am now using the eucledian distance, but ofcourse that is not the real distance. I am using lon lat coordinates.
This is how, a part of, my dictionary looks like:
coord = {0:[ 4.98666883, 52.29477044],
1: [ 4.96969627 ,52.31851732],
2: [ 4.95026886 ,52.31294893],
3: [ 4.97016485 ,52.30191036],
4: [ 4.98254078 ,52.32017747],
5: [ 4.99130712 ,52.29755548],
6: [ 4.97406065 ,52.28985602]}
And this is the definition i am using for adding weight to the edges:
def Length(G,coord):
for i,j in G.edges():
G[i][j]['weight'] = euclidean(coord[i],coord[j])
return G
And this is the code i am using for the rest of the graph.
G = nx.Graph()
G.add_nodes_from(coord.keys())
G = nx.complete_graph(coord.keys())
G = Length(G,coord) #Dit gaat goed nu
print(TotalLength(G))
out: 500 meters
For printing the total length i am using:
Def TotalLength(G):
return G.size('weight')
This defition works everytime.
What can i do to add the actual distance to the edges?
Thanks in advance