Hi Randy,
I've adapted the script you suggested and I'm getting the following error
Traceback (most recent call last):
File "S:/Scripts/ShortRecyclingAuditUpdate.py", line 41, in <module>
updateRows.updateRow(updateRow)
TypeError: sequence size must match size of the row
Here is the script
import arcpy
arcpy.env.workspace = "\\\\Projects\\RecyclingAudit\\RecyclingAuditUpdate"
PW = "\\\\Projects\\RecyclingAudit\\RecyclingAuditUpdate\\UpdateAudits.gdb"
RecyDistrict = "\\\\connections\\SDELOAD@Pub.sde\\RecyclingDistrict"
RecyAudit = PW +"\\RecyclingAudit"
RecyAuditFieldList = ["Week","RecycleRt","RecyCollDay"]
SpatialJoin = PW + "\\SpatialJoin_RA"
SpatialJoinFields = ["Week", "RecycleRt", "RecyCollDay"]
arcpy.env.overwriteOutput = True
if arcpy.Exists(SpatialJoin):
arcpy.Delete_management(SpatialJoin)
# Scratch spatial join feature
arcpy.SpatialJoin_analysis(RecyAudit, RecyDistrict, SpatialJoin, "JOIN_ONE_TO_ONE", "KEEP_ALL",
'Crdt "Crdt" false true false 8 Date 0 0,First,#,RecyclingAudit,Crdt,-1,-1;'
'Address1 "address" true true false 255 Text 0 0,First,#,RecyclingAudit,Address1,0,255;'
'Classification "Classification" true true false 255 Text 0 0,First,#,RecyclingAudit,Classification,0,255;'
'Status "Status" true true false 10 Text 0 0,First,#,RecyclingAudit,Status,0,10;'
'Compliance "Compliance" true true false 5 Text 0 0,First,#,RecyclingAudit,Compliance,0,5;'
'Week "Week" true true false 50 Text 0 0,First,#,SolidWasteRecyclingDistrict,Week,0,50;'
'RecycleRt "RecycleRt" true true false 50 Text 0 0,First,#,SolidWasteRecyclingDistrict,RecycleRt,0,50;'
'RecyCollDay "RecyCollDay" true true false 50 Text 0 0,First,#,SolidWasteRecyclingDistrict,RecyCollDay,0,50',
"INTERSECT", None, '')
# Start edit session
edit = arcpy.da.Editor(PW)
edit.startEditing(True, False)
edit.startOperation()
# Populate the dictionary from recycling district
valueDict = {r[0]:(r[1:]) for r in arcpy.da.SearchCursor(SpatialJoin, SpatialJoinFields)}
with arcpy.da.UpdateCursor(RecyAudit, RecyAuditFieldList) as updateRows:
for updateRow in updateRows:
keyValue = updateRow[0]
if keyValue in valueDict:
for n in range (1,len(SpatialJoinFields)):
updateRow = valueDict[keyValue][n-1]
updateRows.updateRow(updateRow)
del valueDict
# Stop edit operation, stop edit session and save changes
edit.stopOperation()
edit.stopEditing(True)
This is what the tables look like
Could you please help me understand what the error means?
I don't understand how the update cursor knows which records to update. As you can see from the table I only need to update the records that are NULL.
Thanks.