我如何从NetworkX/OSMNX多边形获取节点对象

发布于 2025-02-02 04:02:09 字数 528 浏览 3 评论 0原文

我想通过Node的归因从OSMNX的Multidigraph获取一个节点对象。例如,通过指定纬度和经度坐标或渗透。但是现在,我只能通过列表索引获取它。

import osmnx as ox

# G: MultiDiGraph
G = ox.graph_from_bbox(n, s, e, w, network_type='all')

# get node by node's index
orig = list(G)[5]
dest = list(G)[24]


# Is there a way similar to the following?
# orig = G.nodes(osmid="123456")


route = ox.shortest_path(G, orig, dest, weight="length")
fig, ax = ox.plot_graph_route(G, route, route_color="r", route_linewidth=6, node_size=2)

I want to get a node object from OSMnx's MultiDiGraph by node's attribution. For example, by specifying latitude and longitude coordinates or osmid. But now I can only get it through the list index.

import osmnx as ox

# G: MultiDiGraph
G = ox.graph_from_bbox(n, s, e, w, network_type='all')

# get node by node's index
orig = list(G)[5]
dest = list(G)[24]


# Is there a way similar to the following?
# orig = G.nodes(osmid="123456")


route = ox.shortest_path(G, orig, dest, weight="length")
fig, ax = ox.plot_graph_route(G, route, route_color="r", route_linewidth=6, node_size=2)

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

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

发布评论

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

评论(1

不醒的梦 2025-02-09 04:02:09

您阅读OSMNX 用法示例 networkx 文档?他们演示了如何通过其ID访问节点,并且OSMNX DOCS解释了如何找到最接近某些LAT/长坐标的节点。

import osmnx as ox
G = ox.graph_from_place("Piedmont, CA, USA", network_type="drive")

# identify OSM ID of node(s) nearest to some point(s)
lat = 37.8262501
lng = -122.2476037
node_id = ox.nearest_nodes(G, lng, lat)

# access some node by its OSM ID
my_node = G.nodes[node_id]

# solve a shortest path between two nodes
path = ox.shortest_path(G, node_id, some_other_node_id)

Have you read the OSMnx documentation and usage examples, and the NetworkX documentation? They demonstrate how to access a node by its ID, and the OSMnx docs explain how to find the node nearest to some lat/long coordinates.

import osmnx as ox
G = ox.graph_from_place("Piedmont, CA, USA", network_type="drive")

# identify OSM ID of node(s) nearest to some point(s)
lat = 37.8262501
lng = -122.2476037
node_id = ox.nearest_nodes(G, lng, lat)

# access some node by its OSM ID
my_node = G.nodes[node_id]

# solve a shortest path between two nodes
path = ox.shortest_path(G, node_id, some_other_node_id)
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文