【问题标题】:Shortest distance of a location from a route (Python)位置与路线的最短距离(Python)
【发布时间】:2017-08-10 07:08:19
【问题描述】:

我有一个位置及其经纬度信息

loc = (28.469723, 77.065292)

以及由五对经纬度对给出的路线(折线)

route = [(28.478324, 77.093916), (28.471647, 77.092457), (28.465498, 77.086105), (28.461273, 77.077651)]

有没有一种简单的方法可以计算从locroute 的最短距离(公里)?

【问题讨论】:

    标签: python-3.x geospatial latitude-longitude shapely shortest


    【解决方案1】:

    那你就可以这样解决了。

    from geopy.distance import vincenty
    from shapely.geometry import LineString, Point, LinearRing
    
    loc = (28.469723, 77.065292)
    routePoints = [(28.478324, 77.093916), (28.471647, 77.092457), (28.465498, 77.086105), (28.461273, 77.077651)]
    
    point = Point(loc)
    route = LineString(routePoints)
    
    pol_ext = LinearRing(route.coords)
    d = pol_ext.project(point)
    p = pol_ext.interpolate(d)
    closest_point_coords = list(p.coords)[0]
    
    distance = vincenty(closest_point_coords, loc).km
    
    print(distance)
    

    1.5303772782641438

    输出仍然是一样的,因为该点意外地是最近的,但是通过更改点,您会看到它在最近的线上找到了一个点。

    【讨论】:

    • 谢谢,但我想这会给我从这五个坐标中最近的距离...我需要的是到这些点给出的路径的最短距离。
    猜你喜欢
    • 1970-01-01
    • 2011-10-23
    • 2020-11-27
    • 1970-01-01
    • 1970-01-01
    • 2010-10-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多