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

发布于 2025-01-26 04:15:50 字数 958 浏览 4 评论 0原文

我有一个边缘的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)

输出:

 {'osmid': 571036931, 'highway': 'residential', 'oneway': False, 'length': 55.707}

如果我尝试:

coordinates_edges = G.edges[nearestEdge[0][0], nearestEdge[0][1],0]['geometry']

我得到此错误:

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

糖果控 2025-02-02 04:15:50

我并不完全清楚您的意思:

如何在边缘之间获得两个节点(坐标)?

如果您问如何获得边缘连接的两个节点的坐标,则可以执行类似:

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)

通过OSMNX 文档和networkx documentation 以熟悉这样的基本功能。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文