我在ArcGIS中编写了一个python脚本,用于选择相交的要素。它需要不断重复,直到选择所有相关功能。此时选择将停止变化。是否可以设置循环以保持重复,直到所选要素的数量与上次循环时相同?我可以使用arcpy.GetCount_management()
方法获取所选功能。
我已将所选要素的数量设为变量:
selectCount = arcpy.GetCount_management("StreamT_StreamO1")
然后这是
mylist = []
with arcpy.da.SearchCursor("antiRivStart","ORIG_FID") as mycursor:
for feat in mycursor:
mylist.append(feat[0])
liststring = str(mylist)
queryIn1 = liststring.replace('[','(')
queryIn2 = queryIn1.replace(']',')')
arcpy.SelectLayerByAttribute_management('StreamT_StreamO1',"ADD_TO_SELECTION",'OBJECTID IN '+ queryIn2 )
arcpy.SelectLayerByLocation_management("antiRivStart","INTERSECT","StreamT_StreamO1","","ADD_TO_SELECTION")
所以我想做的事情实际上是:
while selectcount == previousselectcount:
do stuff
但我不知道应该如何构造while循环
答案 0 :(得分:1)
您非常接近于如何监控功能数量的变化。考虑以下。
previousselectcount = -1
selectcount = arcpy.GetCount_management("StreamT_StreamO1")
while selectcount != previousselectcount:
do stuff
# update both counts at the end of what you want to do in the while loop
previousselectcount = selectcount
selectcount = arcpy.GetCount_management("StreamT_StreamO1")
注意while循环条件中的not equals运算符(!=
)。
答案 1 :(得分:0)
如果selectcount或previousselectcount的类型为float,则可能需要执行一个范围 又名
while selectcount >= previousselectcount+c:
....
c的正常数非常接近于零。