在OSMNX边缘上找到中心点的坐标

发布于 2025-02-12 00:31:29 字数 152 浏览 1 评论 0原文

我希望在OSMNX网络的任何边缘上找到中心点的坐标(LAT,LON)。

例如,我的网络是:

G=ox.graph_from_place('San Diego County, CA', network_type='drive')

I am looking to find the coordinates (Lat, Lon) of a center point on any edge of a network of OSMNX.

For instance my network is:

G=ox.graph_from_place('San Diego County, CA', network_type='drive')

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

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

发布评论

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

评论(1

盛装女皇 2025-02-19 00:31:29

使用Shapely使用插值函数。

import osmnx as ox
G=ox.graph_from_place('San Diego', network_type='drive')
nodes, edges = ox.graph_to_gdfs(G, nodes=True, edges=True)

得出图形每个边缘的中点。

edges['midpoint'] = ''
for i in range(0,len(edges)):
    midpoint = edges['geometry'].iloc[i].interpolate(0.5, normalized = True)
    edges['midpoint'].iloc[i] = midpoint

绘制图形。节点用红色表示。边缘的中点用绿色表示。

import matplotlib.pyplot as plt
fig, ax = ox.plot_graph(G, node_size=2, figsize=(48, 48),node_color='r', show=False, close=False)    
for i in range(0,len(edges)):
    ax.scatter(edges['midpoint'].iloc[i].x, edges['midpoint'].iloc[i].y, c='g', s = 2)    
plt.show() 

输出(显示的裁剪图像):

Use the interpolate function from shapely.

import osmnx as ox
G=ox.graph_from_place('San Diego', network_type='drive')
nodes, edges = ox.graph_to_gdfs(G, nodes=True, edges=True)

Derive midpoint for every edge of the graph.

edges['midpoint'] = ''
for i in range(0,len(edges)):
    midpoint = edges['geometry'].iloc[i].interpolate(0.5, normalized = True)
    edges['midpoint'].iloc[i] = midpoint

Plot the graph. Nodes are denoted by red. Midpoints of edges are denoted by green.

import matplotlib.pyplot as plt
fig, ax = ox.plot_graph(G, node_size=2, figsize=(48, 48),node_color='r', show=False, close=False)    
for i in range(0,len(edges)):
    ax.scatter(edges['midpoint'].iloc[i].x, edges['midpoint'].iloc[i].y, c='g', s = 2)    
plt.show() 

Output (cropped image shown):
enter image description here

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