我正在寻找一个中心点的坐标(Lat,Lon),它位于OSMNX网络的任何边缘。
例如,我的网络是:
G=ox.graph_from_place('San Diego County, CA', network_type='drive')发布于 2022-07-08 06:52:46
使用shapely中的interpolate函数。
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() 输出(裁剪后的图像显示):

https://stackoverflow.com/questions/72822746
复制相似问题