简体   繁体   English

如何获得边缘之间的两个节点(坐标)? 在 OSMNX 中,如果我有 (u,v,x) by ox.distance.nearest_edges

[英]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:我有边缘的 id,我想获取其中节点的坐标(x,y),我尝试这种方式:

#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'

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.通读 OSMnx文档和 NetworkX文档以熟悉此类基本功能。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM