All you need to do is use a Cursor spatial_filter:
The issue with your code is that the select by attributes does nothing to a Cursor. Selecting a layer modifies the OID set of the layer object and the cursor only looks at the raw SQL table.
If you want to filter a Cursor, you need to use spatial filters and where clauses:
Here's some updated code from my unedited answer that solves exactly the problem you had. The making a layer and copying features can be run in a separate operation to the flagging, so I made it into a function.
import arcpy
import os
def flag_parcel(parcel_path: os.PathLike, buffer: arcpy.Polyline):
desc = arcpy.Describe(parcel_path)
if 'BufferParcels' in [f.name for f in desc.fields]:
arcpy.management.AddFieldDeleteField(resParcels,"BufferParcels"parcel_path,"SHORT" 'BufferParcels')
# Create the field and set it to 0 (default)
arcpy.management.MakeFeatureLayerAddField(resParcelsparcel_path,"layerParcels" 'BufferParcels', 'SHORT')
# Set the BufferParcels field to 1 for all parcels that intersect the buffer
with arcpy.da.UpdateCursor(resParcelsparcel_path, ['BufferParcels'], spatial_filter=bigBufferspatial_filter=buffer) as cursor:
for row in cursor:
row = dict(zip(cursor.fields, row))
row['BufferParcels'] = 1
## This is really not needed because the default value of a newcursor.updateRow(list(row.values()))
SHORT field is 0
withdef main():
resParcels = r"<path>"
bigBuffer: arcpy.daPolygon = arcpy.UpdateCursorPolygon()
flag_parcel(resParcels, ['BufferParcels']bigBuffer)
# If you have multiple buffers, where_clause='BufferParcelsyou <>can 1')use asthe cursorfollowing code to flag parcels for each buffer
# bigBuffers: List[arcpy.Polygon] = [arcpy.Polygon(), arcpy.Polygon(), ...]
# for rowbuffer in cursorbigBuffers:
# row = dict(zipflag_parcel(cursor.fieldsresParcels, row)buffer)
#
row['BufferParcels'] # Or Merge the buffers into a single buffer
# bigBuffer: arcpy.Polygon = 0[bigBuffers[0].union(buf) for buf in bigBuffers[1:]][0]
# flag_parcel(resParcels, bigBuffer)
if __name__ == "__main__":
main(
All you need to do is use a Cursor spatial_filter