【发布时间】:2021-12-14 09:55:10
【问题描述】:
我有一个包含数千个坐标(纬度、经度)的列表。我想为每个点找到最近的道路和距离。我尝试使用 OSMNX:从 osmnx 加载所有道路并计算每个点到每条道路的距离(代码如下)。但是计算需要很长时间。
roads = gdf[["geometry", "u", "v","ref","name","highway","lanes"]].values.tolist()
# calculate and attach distance
roads_with_distances = [(road, Point(tuple(reversed((59.961517, 30.340880)))).distance(road[0])) for road in roads] #ox
# sort by distance
roads_with_distances = sorted(roads_with_distances, key=lambda x: x[1])
# Select closest road
closest_road = roads_with_distances[0]
# Check whether you are actually "on" the road
if round(closest_road[1],4) < 0.0001: print('Hit the road, Jack!')
我的数据示例(坐标列):
OSMNX 道路数据示例(road==Linestring):
有没有找到最近的道路和距离(以米为单位)的有效方法? 我正在寻找一种 Python 方法。
【问题讨论】:
-
请添加一些随机/样本数据和一个最小工作示例。可能一棵树可以很好地完成这项工作scikit-learn.org/stable/modules/generated/… 它支持你想要的haversine
-
@WillemHendriks 我在帖子中添加了更多信息。上面的代码给了我最近的道路信息,例如名称和距离。但我什至不需要路名,只需要一段距离。
-
您能否将测试数据添加为代码生成和/或样本?
标签: gis geospatial geo osmnx kdtree