1. 按位置选择要素
SelectLayerByLocation_management语法
SelectLayerByLocation_management (in_layer, {overlap_type}, {select_features}, {search_distance}, {selection_type})
测试主要代码如下:
Exp1:
import arcpy
arcpy.env.workspace = "D:/ArcpyBook/data/CityOfSanAntonio.gdb"
try:
#flayer = arcpy.MakeFeatureLayer_management("Burglary","Burglary_Layer")
flayer = arcpy.MakeFeatureLayer_management("Burglary", "Burglary_Layer1")
arcpy.SelectLayerByLocation_management(flayer, "COMPLETELY_WITHIN", "d:/ArcpyBook/Ch7/EdgewoodSD.shp")
cnt = arcpy.GetCount_management(flayer)
print("The number of selected records is: " + str(cnt))
except Exception as e:
print(e.message)
Exp2:
import arcpy
arcpy.env.workspace = &#