利用ArcPy按属性选择并导出shp

如果是操作一个文件按属性选择并导出,可以手动操作,如果是多个呢,必然还是通过代码省事省力。

鉴于网上使用arcpy按属性选择并导出shp的例子较少,本人研究了一下如何批量的按属性选择并导出,分享给大家。

步骤:

1、MakeFeatureLayer_management(),根据输入要素类或图层文件创建要素图层

2、SelectLayerByAttribute_management(),按属性选择

3、CopyFeatures_management(),保存

代码如下

#coding=utf-8
import arcpy
import os
# 获取当前路径
currentPath=os.getcwd()
print currentPath
# 遍历当前路径
files=os.listdir(currentPath)
for file in files:
    # 判断是否为文件夹
    if(len(file.split('.'))<2):
        # 设置工作空间
        arcpy.env.workspace=currentPath+"\\"+file
        print file
        # 判断select+文件夹否存在,不存在则新建
        if not os.path.exists(currentPath+'\\'+'select'+file):
            os.mkdir(currentPath+'\\'+'select'+file)
        # 遍历文件夹
        shpFiles=os.listdir(file)
        for shpFile in shpFiles:
            # 判断是否为shp文件
            if(shpFile.split('.')[-1]=="shp"):
                inPoint=shpFile
                outPoint=currentPath+'\\'+'select'+file+'\\'+shpFile[1:11]+".shp"
                print inPoint
                lyr=shpFile[1:11]
                arcpy.MakeFeatureLayer_management(inPoint, lyr)
                arcpy.SelectLayerByAttribute_management(lyr, "NEW_SELECTION", '"date" LIKE \'%00:00\'')
                arcpy.CopyFeatures_management(lyr, outPoint)

 

  • 6
    点赞
  • 30
    收藏
    觉得还不错? 一键收藏
  • 4
    评论
评论 4
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值