萊蕪網(wǎng)站seo重慶seo網(wǎng)站收錄優(yōu)化
參考文章
arcpy實(shí)現(xiàn) kml批量轉(zhuǎn)出為shp_kml批量合并轉(zhuǎn)shp_A873054267的博客-CSDN博客
參考幫助是arcgis里邊自帶的KMLToLayer_conversion函數(shù)
應(yīng)用場(chǎng)景:
兩步路產(chǎn)生的多個(gè)軌跡文件KML,批量轉(zhuǎn)換成arcgis 的gdb數(shù)據(jù)庫(kù)
最后合并成一個(gè)shp
第一步:把kml轉(zhuǎn)換成gdb
import arcpy, os# Set workspace (where all the KMLs are) 放kml文件的文件夾,如果kml文件過(guò)多,建議50個(gè)kml一個(gè)文件夾,多執(zhí)行幾個(gè)py就行,否則500個(gè)kml可能要一個(gè)小時(shí)
arcpy.env.workspace="D:/KML"# Set local variables and location for the consolidated file geodatabase 導(dǎo)出的geodata文件夾
outLocation = "D:/KMLOUT"# Create the master FileGeodatabase# Convert all KMZ and KML files found in the current workspace 找出kml文件,速度不快的
for kmz in arcpy.ListFiles('*.kml'):print "CONVERTING: " + os.path.join(arcpy.env.workspace,kmz)arcpy.KMLToLayer_conversion(kmz, outLocation)
第二步:
把數(shù)據(jù)合并到一個(gè)shp
import arcpy,os
# 下面是輸出shp的文件夾
out_path = "D:/KML2SHP"
fcz=[]
# 下面是gdb存放的的文件夾
arcpy.env.workspace = "D:/KMLOUT"# Loop through all the FileGeodatabases within the workspace
wks = arcpy.ListWorkspaces('*', 'FileGDB')
# Skip the Master GDB
for fgdb in wks: # Change the workspace to the current FileGeodatabasearcpy.env.workspace = fgdb # For every Featureclass inside, copy it to the Master and use the name from the original fGDB featureClasses = arcpy.ListFeatureClasses('*', '', 'Placemarks')for fc in featureClasses:if fc=='Polylines': # 只要線段,點(diǎn)不要,這個(gè)看自己的需求print "COPYING: " + fc + " FROM: " + fgdb fcCopy = fgdb + os.sep + 'Placemarks' + os.sep + fc print(fcCopy)fcz.append(fcCopy)arcpy.Merge_management(fcz,os.path.join(out_path,'M123.shp'))#M123是導(dǎo)出shp的文件名,可以自行修改,不能重復(fù)print("done")
比上面的參考文件的好的是,將所有l(wèi)ayer轉(zhuǎn)出到shp,這步?jīng)]做,速度會(huì)快一點(diǎn)。
后續(xù)可能會(huì)寫個(gè)自動(dòng)分割執(zhí)行的東西,因?yàn)閗ml文件較多,一個(gè)個(gè)生成比較慢;或者用異步生成工具
另外生成合并也有點(diǎn)慢,為了速度,用重名工具,先把文件重命名為a001,a002,最后就直接合并數(shù)組,可能會(huì)快一點(diǎn),或者python直接去文件名后拼接數(shù)組?fcz.append(fcCopy) 只是搞了一堆字符串,并不需要這么復(fù)雜,因?yàn)樯傻氖怯幸?guī)律的字符串