arcgis使用arcpy中拆分获取FeatureClass中各类型地物要素到单独的shpfile文件
很好用,简单易懂。
arcgis使用arcpy中按字段拆分要素到单独的shpfile文件:
coding = 'utf-8'
# -*- coding:UTF-8 -*-
import os
import arcpy
gdbPath=r"C:\Users\HP\Desktop\LUCC\test.gdb" #输入GDB数据库所在的文件夹的路径
FieldValue="DISTRICTID"
arcpy.env.workspace = gdbPath #将数据库作为工作空间
fcs=arcpy.ListFeatureClasses() #获取所有要素类
for fc in fcs: #循环所有要素类
nums = arcpy.GetCount_management(fc).getOutput(0) # 获取该要素类个数
print(str(fc) +"要素总个数为:" + str(nums))
shpfields = [FieldValue]
shp_JH = []
with arcpy.da.SearchCursor(fc, shpfields) as cursor:
for shpRow in cursor:
shp_JH.append(shpRow[0]) # 注意这个参数0
for selectVal in set(shp_JH):
where_clause = '"' + FieldValue + '"' + '= \'%s\''%(str(selectVal))
districtid_FC = str(fc)+ "_" + str(selectVal)
arcpy.Select_analysis(fc, districtid_FC, where_clause)
print("全部完成!")