萊蕪網(wǎng)站seo重慶seo網(wǎng)站收錄優(yōu)化
參考文章
arcpy實現(xiàn) kml批量轉(zhuǎn)出為shp_kml批量合并轉(zhuǎn)shp_A873054267的博客-CSDN博客
參考幫助是arcgis里邊自帶的KMLToLayer_conversion函數(shù)
應(yīng)用場景:
兩步路產(chǎn)生的多個軌跡文件KML,批量轉(zhuǎn)換成arcgis 的gdb數(shù)據(jù)庫
最后合并成一個shp
第一步:把kml轉(zhuǎn)換成gdb
import arcpy, os# Set workspace (where all the KMLs are) 放kml文件的文件夾,如果kml文件過多,建議50個kml一個文件夾,多執(zhí)行幾個py就行,否則500個kml可能要一個小時
arcpy.env.workspace="D:/KML"# Set local variables and location for the consolidated file geodatabase 導出的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ù)合并到一個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': # 只要線段,點不要,這個看自己的需求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是導出shp的文件名,可以自行修改,不能重復print("done")
比上面的參考文件的好的是,將所有l(wèi)ayer轉(zhuǎn)出到shp,這步?jīng)]做,速度會快一點。
后續(xù)可能會寫個自動分割執(zhí)行的東西,因為kml文件較多,一個個生成比較慢;或者用異步生成工具
另外生成合并也有點慢,為了速度,用重名工具,先把文件重命名為a001,a002,最后就直接合并數(shù)組,可能會快一點,或者python直接去文件名后拼接數(shù)組?fcz.append(fcCopy) 只是搞了一堆字符串,并不需要這么復雜,因為生成的是有規(guī)律的字符串