import codecs
import os
import csv
import copy def Read_Gps_Data(Gps_Data_Path): gps_data_dic={ 'id':'None', 'gps_1_e':'None', 'gps_1_n':'None', 'gps_2_e':'None', 'gps_2_n':'None', 'length_of_e':'None', 'length_of_n':'None', 'length_of_two_point':'None', } gps_data_list=[] list_data = os.listdir(Gps_Data_Path) Gps_Data_Path = Gps_Data_Path+'\\'+list_data[0] gps_file = codecs.open(Gps_Data_Path,'rb+','gbk') csv_reader = csv.reader(gps_file) #將csv第一行讀出 csv_header= next(csv_reader,0) print(csv_header) csv_list=[row for row in csv_reader] for raw in csv_list: gps_data_dic['id'] = raw[0] gps_data_dic['gps_1_e'] = raw[1] gps_data_dic['gps_1_n'] = raw[2] gps_data_dic['gps_2_e'] = raw[3] gps_data_dic['gps_2_n'] = raw[4] gps_data_list.append(copy.deepcopy(gps_data_dic)) gps_data_list_length = len(gps_data_list) gps_file.close() return gps_data_list_length,gps_data_list def Calculate_Two_Point_Length(): Gps_Data_Path = input('Please enter the GPS data path:') gps_data_list_length,gps_data_list = Read_Gps_Data(Gps_Data_Path) for index in gps_data_list: length_of_two_point = geodesic((index['gps_1_n'],index['gps_1_e']), (index['gps_2_n'],index['gps_2_e'])).m length_of_e = geodesic((0,index['gps_1_e']), (0,index['gps_2_e'])).m length_of_n = geodesic((index['gps_1_n'],0), (index['gps_2_n'],0)).m index['length_of_e'] = length_of_e index['length_of_n'] = length_of_n index['length_of_two_point'] = length_of_two_point print(index['id']) print(index['length_of_two_point']) result_path = os.path.abspath('.')+'\\'+'result_file.csv' csv_file = codecs.open(result_path,'ab','gbk') csv_writer=csv.writer(csv_file) csv_writer.writerow(['序號','實際GPS東經','實際GPS北緯','設備GPS東經','設備GPS北緯','經度誤差距離','緯度誤差距離','誤差距離']) for index in gps_data_list: temp_list = [index['id'],index['gps_1_e'],index['gps_1_n'],index['gps_2_e'],index['gps_2_n'],index['length_of_e'],index['length_of_n'],index['length_of_two_point']] csv_writer.writerow(temp_list) csv_file.close() # print(geodesic((30.212882,120.221473), (30.212931,120.221474)).m) #計算兩個坐標直線距離
# print(geodesic((30.28708,120.12802999999997), (28.7427,115.86572000000001)).km) #計算兩個坐標直線距離
if __name__ == '__main__': Calculate_Two_Point_Length()
轉載請註明出處,本文鏈接:https://www.uj5u.com/qita/124952.html
下一篇:請問怎么才能去觸發這個web事件
