电子烟网站设计,专门做设计的一个网站,163邮箱注册,wordpress 百万数据库参考文章
arcpy实现 kml批量转出为shp_kml批量合并转shp_A873054267的博客-CSDN博客
参考帮助是arcgis里边自带的KMLToLayer_conversion函数
应用场景#xff1a;
两步路产生的多个轨迹文件KML#xff0c;批量转换成arcgis 的gdb数据库
最后合并成一个shp
第一步#…参考文章
arcpy实现 kml批量转出为shp_kml批量合并转shp_A873054267的博客-CSDN博客
参考帮助是arcgis里边自带的KMLToLayer_conversion函数
应用场景
两步路产生的多个轨迹文件KML批量转换成arcgis 的gdb数据库
最后合并成一个shp
第一步把kml转换成gdb
import arcpy, os# Set workspace (where all the KMLs are) 放kml文件的文件夹如果kml文件过多建议50个kml一个文件夹多执行几个py就行否则500个kml可能要一个小时
arcpy.env.workspaceD:/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)
第二步:
把数据合并到一个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 fcPolylines: # 只要线段点不要这个看自己的需求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)
比上面的参考文件的好的是将所有layer转出到shp这步没做速度会快一点。
后续可能会写个自动分割执行的东西因为kml文件较多一个个生成比较慢或者用异步生成工具
另外生成合并也有点慢为了速度用重名工具先把文件重命名为a001a002最后就直接合并数组可能会快一点或者python直接去文件名后拼接数组 fcz.append(fcCopy) 只是搞了一堆字符串并不需要这么复杂因为生成的是有规律的字符串