Home > other >  The experimental example 1
The experimental example 1

Time:10-11

The import codecs
The import OS
The 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=https://bbs.csdn.net/topics/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)). The km) # computing two coordinates, linear distance
If __name__=="__main__ ': Calculate_Two_Point_Length ()
  • Related