<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Update point fields with fields in intersecting polygon in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/update-point-fields-with-fields-in-intersecting/m-p/1082356#M61849</link>
    <description>&lt;P&gt;&lt;SPAN&gt;OK, I figured out the error. I had to add a common field to both field lists (RecyAuditFieldList and SpatialJoinFields) which are OBJECTID and TARGET_FID. &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;The edited list looks like this:&lt;/SPAN&gt;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;RecyAuditFieldList = ["OID@","Week","RecycleRt","RecyCollDay"]
SpatialJoinFields = ["TARGET_FID","Week", "RecycleRt", "RecyCollDay"]&lt;/LI-CODE&gt;&lt;P&gt;I will most likely have to update this script in the future since it updates all the records, not just the ones with missing fields.&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Fri, 23 Jul 2021 20:54:51 GMT</pubDate>
    <dc:creator>AliciaShyu</dc:creator>
    <dc:date>2021-07-23T20:54:51Z</dc:date>
    <item>
      <title>Update point fields with fields in intersecting polygon</title>
      <link>https://community.esri.com/t5/python-questions/update-point-fields-with-fields-in-intersecting/m-p/1080958#M61823</link>
      <description>&lt;P&gt;I have 2 feature classes events (points)&amp;nbsp; and districts (polygons).&amp;nbsp;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Polygons" style="width: 480px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/18969i9EA095B7B20CC13D/image-size/large?v=v2&amp;amp;px=999" role="button" title="Polygons.png" alt="Polygons" /&gt;&lt;span class="lia-inline-image-caption" onclick="event.preventDefault();"&gt;Polygons&lt;/span&gt;&lt;/span&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Points" style="width: 850px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/18968iF78085D4D4AF3767/image-size/large?v=v2&amp;amp;px=999" role="button" title="Points.png" alt="Points" /&gt;&lt;span class="lia-inline-image-caption" onclick="event.preventDefault();"&gt;Points&lt;/span&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;I get new points every day and they need polygon (district) information.&amp;nbsp;&lt;/P&gt;&lt;P&gt;I would like to copy over the fields Week, RecycleRt and RecyCollDay from the polygon feature class to the points.&lt;/P&gt;&lt;P&gt;This is the script that I have so far. I know the arcpy.da.UpdateCursor section is wrong, because I don't understand UpdateCursor and I'm getting a runtime error: Cannot find field 'Week'&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;import arcpy

arcpy.env.workspace = "\\\\gis\\RecyclingAuditUpdate"
PW = "\\\\Projects\\RecyclingAuditUpdate\\UpdateAudits.gdb"
VPub = "\\\\connections\\AuthUser@VPub_Prd.sde"
RecyAudit = PW +"\\RecyclingAudit"
RecyDistrict = VPub + "\\RecyclingDistrict"

# Select new records 
NewSelection = arcpy.SelectLayerByAttribute_management (RecyAudit,"NEW_SELECTION",["Week IS NULL AND RecycleRt IS NULL AND RecyCollDay IS NULL"],"NON_INVERT")

# Select intersecting districts
UpDistricts = arcpy.SelectLayerByLocation_management (RecyDistrict,"INTERSECT",NewSelection, "","NEW_SELECTION")

 Start edit session
edit = arcpy.da.Editor(PW)
edit.startEditing(True, False)

# Update Week, RecycleRt and RecyCollDay fields in RecyclingAudit layer
updateFields = ["Week", "RecycleRt", "RecyCollDay"]
with arcpy.da.UpdateCursor(NewSelection, updateFields) as update_cursor:
    for row in update_cursor:
        row[1] = "Week"
        row[2] = "RecycleRt"
        row[3] = "RecyCollDay"
        update_cursor.updateRow(row)&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;Any guidance would be really appreciated. Thanks!&lt;/P&gt;</description>
      <pubDate>Tue, 20 Jul 2021 17:51:09 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/update-point-fields-with-fields-in-intersecting/m-p/1080958#M61823</guid>
      <dc:creator>AliciaShyu</dc:creator>
      <dc:date>2021-07-20T17:51:09Z</dc:date>
    </item>
    <item>
      <title>Re: Update point fields with fields in intersecting polygon</title>
      <link>https://community.esri.com/t5/python-questions/update-point-fields-with-fields-in-intersecting/m-p/1081021#M61824</link>
      <description>&lt;P&gt;rows are zero based, so I am guessing&amp;nbsp;&lt;/P&gt;&lt;P&gt;row[0] = "Week" on line 23&lt;/P&gt;</description>
      <pubDate>Tue, 20 Jul 2021 19:30:01 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/update-point-fields-with-fields-in-intersecting/m-p/1081021#M61824</guid>
      <dc:creator>DanPatterson</dc:creator>
      <dc:date>2021-07-20T19:30:01Z</dc:date>
    </item>
    <item>
      <title>Re: Update point fields with fields in intersecting polygon</title>
      <link>https://community.esri.com/t5/python-questions/update-point-fields-with-fields-in-intersecting/m-p/1081077#M61825</link>
      <description>&lt;P&gt;I believe it would be far more efficient to run the Spatial Join tool, add a join from the input to the result, and copy over the values from the result to the input feature class using Calculate Field, or an update cursor.&lt;/P&gt;</description>
      <pubDate>Tue, 20 Jul 2021 21:09:55 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/update-point-fields-with-fields-in-intersecting/m-p/1081077#M61825</guid>
      <dc:creator>curtvprice</dc:creator>
      <dc:date>2021-07-20T21:09:55Z</dc:date>
    </item>
    <item>
      <title>Re: Update point fields with fields in intersecting polygon</title>
      <link>https://community.esri.com/t5/python-questions/update-point-fields-with-fields-in-intersecting/m-p/1081323#M61836</link>
      <description>&lt;P&gt;That fixed the error and the script works but not the way I was thinking&amp;nbsp;&lt;span class="lia-unicode-emoji" title=":grinning_face_with_sweat:"&gt;😅&lt;/span&gt;&lt;/P&gt;&lt;P&gt;Instead of updating the fields with the corresponding selected polygon's fields. It's just updating them with the words Week, RecycleRt and RecyCollDay&amp;nbsp;&lt;span class="lia-unicode-emoji" title=":persevering_face:"&gt;😣&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="SelectDistricts.png" style="width: 999px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/19038i2CF35E6081CECE7F/image-size/large?v=v2&amp;amp;px=999" role="button" title="SelectDistricts.png" alt="SelectDistricts.png" /&gt;&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 21 Jul 2021 14:30:01 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/update-point-fields-with-fields-in-intersecting/m-p/1081323#M61836</guid>
      <dc:creator>AliciaShyu</dc:creator>
      <dc:date>2021-07-21T14:30:01Z</dc:date>
    </item>
    <item>
      <title>Re: Update point fields with fields in intersecting polygon</title>
      <link>https://community.esri.com/t5/python-questions/update-point-fields-with-fields-in-intersecting/m-p/1081487#M61840</link>
      <description>&lt;P&gt;I believe you're correct. I found this post&amp;nbsp;&lt;A title="Update points attributes based on there location" href="https://community.esri.com/t5/python-questions/update-points-attributes-based-on-there-location/m-p/691577/thread-id/53615" target="_blank" rel="noopener"&gt;Update points attributes based on there location&lt;/A&gt;&amp;nbsp;and updated my script to&lt;/P&gt;&lt;LI-CODE lang="python"&gt;import arcpy

arcpy.env.workspace = "\\\\gis\\RecyclingAuditUpdate"
PW = "\\\\Projects\\RecyclingAuditUpdate\\UpdateAudits.gdb"
VPub = "\\\\connections\\AuthUser@VPub_Prd.sde"
RecyAudit = PW +"\\RecyclingAudit"
RecyDistrict = VPub + "\\RecyclingDistrict"
RecyAudit = PW +"\\RecyclingAudit"
RecyAuditFieldList = ["Week","RecycleRt","RecyCollDay"]
SpatialJoin = PW + "\\SpatialJoin_RA"
SpatialJoinFields = ["Week", "RecycleRt", "RecyCollDay"]

arcpy.env.overwriteOutput = True
# 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)&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;This script has the following error:&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000FF"&gt;Traceback (most recent call last):&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT color="#0000FF"&gt;File "S:/Scripts/ShortRecyclingAuditUpdate.py", line 39, in &amp;lt;module&amp;gt;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT color="#0000FF"&gt;updateRows.updateRow(updateRow)&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT color="#0000FF"&gt;TypeError: sequence size must match size of the row&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;I don't understand how UpdateCursor works.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 21 Jul 2021 19:17:37 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/update-point-fields-with-fields-in-intersecting/m-p/1081487#M61840</guid>
      <dc:creator>AliciaShyu</dc:creator>
      <dc:date>2021-07-21T19:17:37Z</dc:date>
    </item>
    <item>
      <title>Re: Update point fields with fields in intersecting polygon</title>
      <link>https://community.esri.com/t5/python-questions/update-point-fields-with-fields-in-intersecting/m-p/1082356#M61849</link>
      <description>&lt;P&gt;&lt;SPAN&gt;OK, I figured out the error. I had to add a common field to both field lists (RecyAuditFieldList and SpatialJoinFields) which are OBJECTID and TARGET_FID. &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;The edited list looks like this:&lt;/SPAN&gt;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;RecyAuditFieldList = ["OID@","Week","RecycleRt","RecyCollDay"]
SpatialJoinFields = ["TARGET_FID","Week", "RecycleRt", "RecyCollDay"]&lt;/LI-CODE&gt;&lt;P&gt;I will most likely have to update this script in the future since it updates all the records, not just the ones with missing fields.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 23 Jul 2021 20:54:51 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/update-point-fields-with-fields-in-intersecting/m-p/1082356#M61849</guid>
      <dc:creator>AliciaShyu</dc:creator>
      <dc:date>2021-07-23T20:54:51Z</dc:date>
    </item>
  </channel>
</rss>

