首页 > 其他分享 >【ArcPy】要素类按字段拆分

【ArcPy】要素类按字段拆分

时间:2023-02-12 17:35:54浏览次数:37  
标签:__ 要素 val arcpy lst 拆分 unique ArcPy out

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()

 

标签:__,要素,val,arcpy,lst,拆分,unique,ArcPy,out
From: https://www.cnblogs.com/yzhyingcool/p/17114182.html

相关文章