arcpy SelectByLocation_management 按位置选择
import arcpy from arcpy import env sourceGDB=r"d:\polygon.gdb" env.workspace=sourceGDB target="merge" out_feature_class="p2" arcpy.MakeFeatureLayer_management(out_feature_class, 'newlinks_lyr') arcpy.SelectLayerByLocation_management('newlinks_lyr', "INTERSECT",target) cnt = arcpy.GetCount_management('newlinks_lyr') print "The number of selected records is:" + str(cnt)
其中第一个参数必须为内存图层,不能用硬盘上得shp,否则会报错
ExecuteError: Failed to execute. Parameters are not valid.
ERROR 000368: Invalid input data.
Failed to execute (SelectLayerByLocation).
很神奇得是,再arcmap中执行没有问题,但是再toolbox和单独得python脚本中执行都会报错
转载自:https://blog.csdn.net/A873054267/article/details/84953539