Hi 2 Quicker (and not Dan ) <edited>
Nice script, a couple of things that should get it working:
- move the selection outside of the "with" statement
- you were not using the "result" of the count in this snippet, so i included some more print statements to give more feedback
- the update cursor now runs on the selection rather than the full data set
if this doesn't work then i would suggest
- adding in a unique identifier if one doesn't already exist
- building a list/set from the selection
- iterating over fc1 and updating the fields "if <uniqueID> in <list>"
If you like i can do up a skeleton of this option as well.
Hope this helps and good luck
Michael
import arcpy
from datetime import datetime as d
startTime = d.now()
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"
selection = arcpy.SelectLayerByLocation_management(fc1, "HAVE_THEIR_CENTER_IN", CITY)
numberoffeaturesfc1 = arcpy.GetCount_management(fc1)
result = arcpy.GetCount_management(selection)
count = 0
def findwhatsincity():
global count
with arcpy.da.UpdateCursor(selection, ['field1', 'field2', 'field3', 'field4']) as cursor:
for row in cursor:
row[0] = "IN CITY"
row[1] = "IN CITY"
row[2] = "IN CITY"
row[3] = "IN CITY"
count += 1
cursor.updateRow(row)
del row, cursor
print('Done')
try:
print ('Starting Script @ ' + startTime)
findwhatsincity()
print ('Number of features in ' + str(fc1) + ": " + str(numberoffeaturesfc1))
print ('Number of features in selection: ' + str(result))
print ('Number of features processed: ' + str(count))
print ('(Elapsed time: ' + str(d.now() - startTime)[:-3] + ')')
except Exception as e:
import traceback, sys
tb = sys.exc_info()[2]
print ("Line %i" % tb.tb_lineno)
print (e.message)