求轨迹间距离代码怎么写
lat_list,long_list39.9408499,116.38358
39.94080063,116.3836432
39.94077965,116.3836613
39.94076545,116.3836884
39.94075841,116.3836974
39.94075125,116.3837155
39.94073693,116.3837516
39.94072964,116.3837786
39.9407226,116.3837877
39.9406868,116.3838779
坐标点如上,求连续多点间的距离代码该怎么写啊(点1-点2,点2-点3,.....)
{:5_100:}
平面直角坐标系?? 不明白
{:5_99:} wp231957 发表于 2021-9-9 19:49
平面直角坐标系??
GCJ02坐标 傻眼貓咪 发表于 2021-9-9 19:55
不明白
这是一条轨迹数据,求轨迹中两点间的距离 import math
def length(A: tuple, B: tuple):
a = abs(A-B)
b = abs(A-B)
return math.sqrt(a**2+b**2)
x = (3, 7)
y = (7, 4)
print(length(x, y))5.0 from math import radians, cos, sin, asin, sqrt
from geopy.distance import geodesic
def geodistance(lng1,lat1,lng2,lat2):
lng1, lat1, lng2, lat2 = map(radians, ) # 经纬度转换成弧度
dlon=lng2-lng1
dlat=lat2-lat1
a=sin(dlat/2)**2 + cos(lat1) * cos(lat2) * sin(dlon/2)**2
distance=2*asin(sqrt(a))*6371*1000 # 地球平均半径,6371km
distance=round(distance/1000,3)
return distance
print(geodesic((32.088423,118.647258), (32.09006,118.639575)).m)
这个是求起点和终点间距离的代码,我想把它改成连续求多点距离,就是起点-中间点1-中间点2-。。。-终点,连续求两点间的距离{:10_254:} 本帖最后由 blahblahfc 于 2021-9-10 06:09 编辑
试试
def geodesic_m(*args):
r = [geodesic(lat_long1, lat_long2).m
for lat_long1, lat_long2 in zip(args, args)]
if len(args)==2:
return r
else:
return r
lat_long_list = [(39.9408499,116.38358),
(39.94080063,116.3836432),
(39.94077965,116.3836613),
(39.94076545,116.3836884),
(39.94075841,116.3836974),
(39.94075125,116.3837155),
(39.94073693,116.3837516),
(39.94072964,116.3837786),
(39.9407226,116.3837877),
(39.9406868,116.3838779)]
geodesic_m((39.9408499,116.38358),
(39.94080063,116.3836432))
geodesic_m((39.9408499,116.38358),
(39.94080063,116.3836432),
(39.94077965,116.3836613))
geodesic_m(*lat_long_list)
如果要用 geodistance 函数,把第2行中的 geodesic(lat_long1, lat_long2).m 改为 geodistance(*reversed(lat_long1), *reversed(lat_long2)) 就行。
页:
[1]