import math
def euclidean_distance(x1, y1, x2, y2):
return math.sqrt((x2 - x1) ** 2 + (y2 - y1) ** 2)
if __name__ == '__main__':
'''
16move.pos文件内容如下:
% (x/y/z-ecef=WGS84,Q=1:fix,2:float,3:sbas,4:dgps,5:single,6:ppp,ns=# of satellites
% GPST x-ecef(m) y-ecef(m) z-ecef(m) Q ns sdx(m) sdy(m) sdz(m) vx(m/s) vy(m/s) vz(m/s) age(s) ratio
2284 109908.000 -2654301.9349 3767744.5271 4394555.9078 5 14 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.00 0.0
2284 109909.000 -2654301.9454 3767744.5016 4394555.9292 5 14 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.00 0.0
2284 109910.000 -2654301.3708 3767745.1125 4394556.4741 5 16 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.00 0.0
2284 109911.000 -2654301.3240 3767745.0599 4394556.4335 5 16 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.00 0.0
'''
with open('16move.pos', 'r') as yt:
# 临时存放
tmp = []
for line in yt.readlines():
tmpSort = line.strip().split(" ")
tmp.append(tmpSort)
# print(tmp[0][3],tmp[0][6])
sum = 0
l = 0
# 剔除前面两行(列头部分)
for i in range(2, len(tmp) - 1):
# 计算相邻两行的第4个值(x)和第7个(y),并累加
sum += euclidean_distance(float(tmp[i][3]), float(tmp[i][6]), float(tmp[i + 1][3]), float(tmp[i + 1][6]))
l += 1
print("第%s次:" % (l) + "统计路程:" + str(sum) + "米")
print("总路程:%s" % str(sum) + "米")
python_从文件读取xy坐标并统计之间的距离
于 2023-10-18 20:43:57 首次发布