'How can i get the the two nodes (coordinates) between a edge? In OSMNX if i had (u,v,x) by ox.distance.nearest_edges
I have the id's of an edge and I want to get the coordinates(x,y) of the nodes inside it, I try this way:
#this is my graph:
G = ox.graph_from_address('Arequipa, Arequipa', `network_type='drive',simplify=True,dist=7000)
#where nearestEdge[x][0] = u, nearesEdge[x][1] = v
coordinates_edges = G.edges[nearestEdge[0][0], nearestEdge[0][1],0]
print(coordinates_edges)
Output:
{'osmid': 571036931, 'highway': 'residential', 'oneway': False, 'length': 55.707}
if I try:
coordinates_edges = G.edges[nearestEdge[0][0], nearestEdge[0][1],0]['geometry']
I get this error:
KeyError Traceback (most recent call last)
<ipython-input-52-20f93c142504> in <module>()
8 #coordinates_nodes = G.nodes[5517424179]['y']
9
---> 10 coordinates_edges = G.edges[nearestEdge[0][0], nearestEdge[0][1],0]['geometry']
11 print(coordinates_edges)
12
KeyError: 'geometry'
Solution 1:[1]
I'm not totally clear what you mean by:
How can i get the the two nodes (coordinates) between a edge?
If you're asking how do you get the coordinates of the two nodes that an edge connects, you can do something like:
import osmnx as ox
G = ox.graph_from_address('Arequipa, Arequipa', network_type='drive', simplify=True,dist=7000)
edge = list(G.edges)[0]
node1 = edge[0]
node1_x = G.nodes[node1]['x']
node1_y = G.nodes[node1]['y']
node2 = edge[1]
node2_x = G.nodes[node2]['x']
node2_y = G.nodes[node2]['y']
print(node1_x, node1_y, node2_x, node2_y)
Read through the OSMnx documentation and the NetworkX documentation to familiarize yourself with basic functionality like this.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | gboeing |