# -*- coding: utf-8 -*-
import sys
sys.path.append("D:\\Python27\\ArcGIS10.4\\python")
sys.path.append("D:\\Program Files (x86)\\ArcGIS\\Desktop10.4\\arcpy\\arcpy")
import arcpy, os# Set workspace (where all the KMLs are) 放kml文件的文件夹,如果kml文件过多,建议50个kml一个文件夹,多执行几个py就行,否则500个kml可能要一个小时
arcpy.env.workspace = "E:\\python\\JINAN\\JINAN\\CQQ\\KMLMS"# Set local variables and location for the consolidated file geodatabase 导出的geodata文件夹
outLocation = "E:\\python\\JINAN\\JINAN\\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)
# -*- coding: utf-8 -*-
import sys
sys.path.append("D:\\Python27\\ArcGIS10.4\\python")
sys.path.append("D:\\Program Files (x86)\\ArcGIS\\Desktop10.4\\arcpy\\arcpy")
import arcpy, os# 下面是输出shp的文件夹
out_path = "E:\\python\\JINAN\\JINAN\\KML2SHP"
fcz = []
# 下面是gdb存放的的文件夹
arcpy.env.workspace = "E:\\python\\JINAN\\JINAN\\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 fGDBfeatureClasses = arcpy.ListFeatureClasses('*', '', 'Placemarks')for fc in featureClasses:if fc == 'Polylines': # 只要线段,点不要,这个看自己的需求print("COPYING: " + fc + " FROM: " + fgdb)fcCopy = fgdb + os.sep + 'Placemarks' + os.sep + fcprint(fcCopy)fcz.append(fcCopy)arcpy.Merge_management(fcz, os.path.join(out_path, 'M123.shp'))# M123是导出shp的文件名,可以自行修改,不能重复print("done")
python E:\python\JINAN\JINAN\kml2gdb.pypython E:\python\JINAN\JINAN\hebing.py
参考链接
https://blog.csdn.net/countsun/article/details/132254557