AnsweredAssumed Answered

UdateCursor with Select By Location

Question asked by 2CQuiker on Dec 11, 2019
Latest reply on Dec 12, 2019 by mboyceesriaustralia-com-au-esridist

I am trying to do a select by location and then update the selected features, seems easy enough but i am see to get it figured out. Basically i want to update only the parcels that are within the City limits layer and update the 4 fields. I have tried different variations but i can't seem to get to work. I don't get any errors and also doesn't stop. I would appreciate any help.


Here is what i have.


import arcpy
from datetime import datetime as d
startTime =
start_time = time.time()

arcpy.env.overwriteOutput = True
arcpy.env.workspace = "C:/Temp/blah.gdb"

fc1 = "C:/Temp/blah.gdb/Parcels"

CITY = "C:/Temp/blah.gdb/City_Limits"

with arcpy.da.UpdateCursor(fc1, ['field1','field2','field3', 'field4']) as cursor:
    for row in cursor:
        #Select all parcels within the city limits layer
        arcpy.SelectLayerByLocation_management(fc1,"HAVE_THEIR_CENTER_IN", CITY)
        result = arcpy.GetCount_management(fc1)
        row [0] =  "IN CITY"
        row [1] =  "IN CITY"
        row [2] =  "IN CITY"
        row [3] =  "IN CITY"
    del row, cursor
    print ('(Elapsed time: ' + str( - startTime)[:-3] + ')')

except Exception as e:
    # If an error occurred, print line number and error message
    import traceback, sys
    tb = sys.exc_info()[2]
    print ("Line %i" % tb.tb_lineno)
    print (e.message)