def FinalLines(txtpath,kmlsavepath,txtfile): """ 批量处理每辆车的完成路网匹配 :param txtpath: txt文件路径,txt文件是最终确定的轨迹点所属路段的存储文件 :param kmlsavepath: kml文件的保存路径 txtfile kml路线对应的txt文档 :return: """ if not os.path.isdir(kmlsavepath): os.mkdir(kmlsavepath) with open(txtpath,'r') as file: lines = file.readlines() linesnum = len(lines) finalconnways = [] #最终能走通的路线 count = 0 for i in range(linesnum): if lines[i].strip("\n")=="New_Road": continue waylists = GetAllLines(eval(lines[i].strip("\n"))) if len(waylists)>=3: if MapNavigation.JudgeLines(waylists): finalconnways.append(waylists) elif len(waylists)==2: if MapNavigation.JudgeTwoWay(waylists[0],waylists[1]): finalconnways.append(waylists) else:pass #print(finalconnways) finalconnways = Common_Functions.Double_layer_list(finalconnways) file = open(txtfile,'a') for sub in finalconnways: file.write(str(sub)+"\n") count += 1 nodes = Fill_coordinate_By_Routes(sub) Common_Functions.list2kml(nodes, str(count),kmlsavepath) file.close()
file.close() def BatchSelectLines(Candidatewaypath,savepath): """ 批量选出最终匹配的轨迹 :param Candidatewaypath: 所有候选路线的txt路径 :param savepath: kml保存路径 :return: """ txtlist = Common_Functions.findtxtpath(Candidatewaypath) for singletxt in txtlist: print(singletxt) (tempath, tempfilename) = os.path.split(singletxt) # tempfilename为txt文件名(包含后缀) (trunkname, extension) = os.path.splitext(tempfilename) # filename 为传入的txt文件名 extension为后缀 kmlsavepath = os.path.join(savepath,trunkname) txtkmllinename = trunkname +".txt" if not os.path.isdir(kmlsavepath): os.mkdir(kmlsavepath) FinalLines(singletxt,kmlsavepath,os.path.join(kmlsavepath,txtkmllinename)) #FinalLines("H:\GPS_Data\Road_Network\BYQBridge\FinalRoutes\\10706a7b-3d56-4551-9a09-debda7d2c032.txt","H:\GPS_Data\Road_Network\BYQBridge\KML\PartTrunksAreaKml") #BatchSelectLines("H:\GPS_Data\Road_Network\BYQBridge\FinalRoutes\Test","H:\GPS_Data\Road_Network\BYQBridge\KML\PartTrunksAreaKml\Batch") # FinalLines("H:\GPS_Data\Road_Network\BYQBridge\FinalRoutes\FullTrack\\10706a7b-3d56-4551-9a09-debda7d2c032.txt", # "H:\GPS_Data\Road_Network\BYQBridge\KML\PartTrunksAreaKml\FullTrack\\10706a7b-3d56-4551-9a09-debda7d2c032", # "H:\GPS_Data\Road_Network\BYQBridge\KML\PartTrunksAreaKml\FullTrack\\10706a7b-3d56-4551-9a09-debda7d2c032\\10706a7b.txt") Common_Functions.list2kml(Fill_coordinate_By_Routes([242945739, 242945750, 242945771, 47574802, 680002283, 47574807]), "se","H:\GPS_Data\Road_Network\BYQBridge\KML\PartTrunksAreaKml\Grid\BYC") #print(GetAllLines([318909305, 317886767, 407991264, 51997674, 317916355, 391813868, 29135445, 317916344, 29135795, 391813830, 210697668, 317916290, 29135960, 47574189, 242945770, 47574191, 229521327, 258296019, 317889645, 317913828, 29136270, 606768167, 606768159, 508147677, 508312926, 466839062, 466839044, 466839045, 332203310, 332203325, 398538985]))