arcpy实现kml批量转出为shp 包括shp合并

# -*- 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 FileGeodatabase
    arcpy.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")

arcpy实现kml批量转出为shp 包括shp合并_第1张图片

arcpy实现kml批量转出为shp 包括shp合并_第2张图片

python E:\python\JINAN\JINAN\kml2gdb.py

python E:\python\JINAN\JINAN\hebing.py

参考链接
https://blog.csdn.net/countsun/article/details/132254557

你可能感兴趣的:(python,arcgis)