You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何计算追踪点在规划路线内的覆盖距离及完成占比?

规划路线覆盖距离与完成占比计算

我有一条由多个坐标点(A→B→C…)组成的规划路线,通过追踪设备获取行驶中的坐标数据,需要计算这些数据在规划路线内的覆盖距离,以及完成规划路线的百分比。我尝试将规划路线构建为LineString,结合Haversine公式计算追踪点与路线的关联,但未找到类似案例。

示例数据

规划路线坐标

[31.133174280616576, -83.42203815784336], [31.13192707647258, -83.42157019003105],[31.130689655790633, -83.4211512998921]

追踪获取的坐标

[31.133185576131343, -83.42202228254087], [31.132377192472315, -83.42175524389052]

需求场景

比如卡车从一个街区到另一个街区,规划路线长2公里,实际行驶2公里但仅500米在规划路线内,需得出25%的完成占比。我正尝试用Python的Geopy、Haversine公式结合Postgres实现,以下是部分尝试代码:

from shapely.geometry import LineString, Point
from geopy.distance import geodesic
planned_route = LineString([
    (43.91195105177844, -100.33847318111548),
    (43.912010542805625, -100.33705097257662),
    (43.91203698324306, -100.33570216834944),
    (43.91205020345737, -100.33417902888205),
])
coordinates = [
    (43.91195105177844, -100.33847318111548),
    (43.912010542805625, -100.33705097257662),
]
tracker_points = [Point(coord) for coord in coordinates]

covered_distance = 0
last_projected_point = None

for point in tracker_points:
    print(planned_route.interpolate(planned_route.project(point)))
    projected_point = planned_route.interpolate(planned_route.project(point))
    if last_projected_point is not None:
        covered_distance += geodesic((last_projected_point.x, last_projected_point.y), (projected_point.x, projected_point.y)).meters
    last_projected_point = projected_point

total_planned_distance = sum(geodesic(planned_route.coords[i], planned_route.coords[i+1]).meters for i in range(len(planned_route.coords) - 1))

percentage_covered = (covered_distance / total_planned_distance) * 100 if total_planned_distance > 0 else 0

内容的提问来源于stack exchange,提问作者opa

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.21 19:52:40