3

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

loc = (28.469723, 77.065292)

和由五个纬度对给出的路线(折线)

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

loc有没有一种简单的方法来计算以公里为单位的最短距离route

4

1 回答 1

0

那你就可以这样解决了。

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

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

于 2017-03-18T20:23:52.700 回答