【ArcPy】要素类按字段拆分
Python工具代码,非Python窗口脚本,可以自行编辑处理一下。
# coding=gbk import arcpy from arcpy import da as da def main(): lyr=arcpy.GetParameter(0) fld=arcpy.GetParameterAsText(1) out_folder=arcpy.GetParameterAsText(2) unique_lst=[] with da.SearchCursor(lyr,fld) as cursor: for row in cursor: if row[0] not in unique_lst: unique_lst.append(row[0]) arcpy.AddMessage(">>>分类列表已获取。") arcpy.AddMessage('>>>开始执行拆分输出……') cnt=len(unique_lst) arcpy.SetProgressor("step","{} 个待输出要素类。".format(cnt),1,cnt,1) for out_val in unique_lst: out_val=out_val.encode('gb2312') arcpy.SetProgressorPosition() arcpy.Select_analysis(lyr,r"{}\\{}.shp".format(out_folder.encode('gb2312'),out_val),"{}='{}'".format(fld.encode('gb2312'),out_val)) arcpy.AddMessage(">>>要素类拆分完成。") if __name__=="__main__": main()