首页 > 其他 > 详细

arcpy 按属性分割要素类

时间:2021-02-15 23:40:07      阅读:28      评论:0      收藏:0      [点我收藏+]

 

# coding=gbk
import arcpy
from arcpy import da
import os
import re

# 过滤路径非法字符串
def filename_filter(filename):
    filename = re.sub(r[\/:*?"<>|], ‘‘, filename)
    return filename


def main():
    in_fc=arcpy.GetParameter(0)
    in_field=arcpy.GetParameterAsText(1)
    out_workspace=arcpy.GetParameterAsText(2)
    # 字段唯一值列表
    lst=[]
    with da.SearchCursor(in_fc,[in_field]) as cursor:
        for row in cursor:
            lst.append(row[0])
    lst = set(lst)
    # 类型个数
    record_count = len(lst)
    arcpy.SetProgressor("step","{} feature classes will be exporting...".format(record_count).encode(gbk),0,record_count,1)
    # 数据库描述
    des_workspace=arcpy.Describe(out_workspace)
    # 如果工作空间是文件夹,那么输出应该是shapefile,应该有扩展名.shp
    if des_workspace.workspaceType==FileSystem:
        for item in lst:
            arcpy.Select_analysis(in_fc,os.path.join(out_workspace,filename_filter(item) +.shp),in_field+=+""+item+"")
            arcpy.SetProgressorPosition()
    else:
        for item in lst:
            arcpy.Select_analysis(in_fc,os.path.join(out_workspace,filename_filter(item)),in_field+=+""+item+"")
            arcpy.SetProgressorPosition()
    arcpy.AddMessage(... work done.)


if __name__ == __main__:
    main()

 

arcpy 按属性分割要素类

原文:https://www.cnblogs.com/yzhyingcool/p/14404294.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!