arcpy实现 kml批量转出为shp

分两步走:首先转出到layer

import arcpy, os
arcpy.env.workspace = r"D:\sq\ddx"
outLocation = "D:\sq\ddx"
MasterGDB = 'sq.gdb'
MasterGDBLocation = os.path.join(outLocation, MasterGDB)
arcpy.CreateFileGDB_management(outLocation, MasterGDB)
for kmz in arcpy.ListFiles('*.KM*'):
    arcpy.KMLToLayer_conversion(kmz, MasterGDBLocation)

其次将所有layer转出到shp

import arcpy, os
arcpy.env.workspace = r"D:\sq\dbx"
outGDB=r"D:\kml2.gdb"
wks = arcpy.ListWorkspaces('*', 'FileGDB')
count=0
for fgdb in wks:
    arcpy.env.workspace = fgdb
    featureClasses = arcpy.ListFeatureClasses('*', '', 'Placemarks')
    count+=1
    for fc in featureClasses:
        print fc
        arcpy.CopyFeatures_management(fc, outGDB+"\\s"+str(count)+fc)

最后又需要将所有shp合并

import arcpy
from arcpy import env
sourceGDB=r"d:\kml2.gdb"
env.workspace=sourceGDB
fcs=arcpy.ListFeatureClasses()
lspoly=[]
for fc in fcs:
                lspoly.append(fc)
arcpy.Merge_management(lspoly, "bjm")

转载自:https://blog.csdn.net/A873054267/article/details/87891063

You may also like...