(地理国情监测)arcpy使用SelectLayerByLocation进行空间位置选择、SelectLayerByAttribute进行属性选择,使用CopyFeatures_management进行选择要素导出。
coding = 'utf-8'
import os #加载os库
import arcpy #加载arcpy库
file_dir_Source ="E:\\001.yangdebin\\001.集水区\\国情监测水网数据\\test.gdb\\CHydDataset\\UV_HYDL"
file_dir_BenDi1 ="E:\\001.yangdebin\\001.集水区\\JC19_340000备份.gdb\\CHydDataset\\CV_HYDL"
# Make a layer and select cities which overlap the chihuahua polygon
arcpy.MakeFeatureLayer_management(file_dir_Source, 'UVHYDL_lyr')
print("--------开始按位置查询WITHIN_CLEMENTINI!--------")
arcpy.SelectLayerByLocation_management('UVHYDL_lyr', 'WITHIN_CLEMENTINI', file_dir_BenDi1)
print("--------按位置查询选择Success!--------")
arcpy.SelectLayerByAttribute_management("UVHYDL_lyr", "SWITCH_SELECTION")
print("--------反向选择Success!--------")
# If features matched criteria write them to a new feature class
matchcount = int(arcpy.GetCount_management('UVHYDL_lyr').getOutput(0))
if matchcount == 0:
print('no features matched spatial and attribute criteria')
else:
arcpy.CopyFeatures_management('UVHYDL_lyr', "E:\\001.yangdebin\\001.集水区\\国情监测水网数据\\test.gdb\\CHydDataset\\SByLocation3")
print("--------选择结果拷贝Success!--------")