Hmmmm, actually I was alredy thinking about this, before I decided to try with cursors but somehow I could not make such logical conclusion... Will definitley try this.However in the meanwhile I came up with something. It works quite fine except for a few polygons. I do not know why but while checking the result I found some polygons that should have been selected (exported) but were not.I tested it also on second area and it returned strange error message:Traceback (most recent call last): File "LINK TO THE SCRIPT", line 235, in <module> cursor.next()StopIterationAny idea what it means?Here is the last code:spatialReference = arcpy.Describe(depressionsLocation + depressionsName).spatialReference
arcpy.CreateFeatureclass_management(depressionsLocation, unroofedCaves, "POLYGON", depressionsLocation + depressionsName, "SAME_AS_TEMPLATE", "DISABLED", spatialReference)
depressions = depressionsLocation + "depressions.shp"
selectingBuffer = depressionsLocation + "dissolvedBuffers.shp"
wasSelectedField = ('ID')
isSelectorField = ('ASPECT_R', 'ID')
try:
arcpy.MakeFeatureLayer_management(depressions, "depressionsLayer")
arcpy.MakeFeatureLayer_management(selectingBuffer, "selectingBufferLayer")
except:
print "Could not create feature layers"
try:
with arcpy.da.SearchCursor("selectingBufferLayer", isSelectorField) as cursor:
for row in cursor:
oid = int(row[1])
if (row[0] >= 2):
arcpy.SelectLayerByAttribute_management("selectingBufferLayer", "NEW_SELECTION", '"ID" = {}'.format(oid))
arcpy.SelectLayerByLocation_management("depressionsLayer", "INTERSECT", "selectingBufferLayer")
with arcpy.da.SearchCursor("depressionsLayer", wasSelectedField) as selcursor:
for selrow in selcursor:
arcpy.SelectLayerByAttribute_management("depressionsLayer", "ADD_TO_SELECTION", '"ID" = {}'.format(oid))
arcpy.Append_management("depressionsLayer", depressionsLocation + unroofedCaves, "NO_TEST", "", "")
print "Exporting "
break
#del selcursor, selrow
else:
cursor.next()
del cursor, row
finally:
if arcpy.Exists("depressionsLayer"): arcpy.Delete_management("depressionsLayer")
if arcpy.Exists("selectingBufferLayer"): arcpy.Delete_management("selectingBufferLayer")