<?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: Trouble with UpdateCursor.updateRow() in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/trouble-with-updatecursor-updaterow/m-p/59773#M4750</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;If you're using arcgis 10.1 I would suggest using arcpy.da.UpdateCursor instead of arcpy.UpdateCursor.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;It much faster and offers easy access to geometry (simply add 'SHAPE@' to field list), disadvantage is its less intuitive at the beginning.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Regards,&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Arek&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Tue, 09 Apr 2013 09:51:16 GMT</pubDate>
    <dc:creator>ArkadiuszMatoszka</dc:creator>
    <dc:date>2013-04-09T09:51:16Z</dc:date>
    <item>
      <title>Trouble with UpdateCursor.updateRow()</title>
      <link>https://community.esri.com/t5/python-questions/trouble-with-updatecursor-updaterow/m-p/59769#M4746</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;I am trying to update an SDE feature class based on another SDE feature class using an Update Cursor.&amp;nbsp; Th feature classes have identical fields and the same number of records.&amp;nbsp; There is a "LASTMODIFIED" date field that is changed anytime a record is updated in the source feature class.&amp;nbsp; &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;What I'm doing is matching up the rows in each table using their "ID" field, then checking to see if the "LASTMODIFIED" date is different.&amp;nbsp; If it &lt;/SPAN&gt;&lt;SPAN style="font-style:italic;"&gt;is&lt;/SPAN&gt;&lt;SPAN&gt; different, then I want to update the &lt;/SPAN&gt;&lt;SPAN style="text-decoration:underline;"&gt;entire&lt;/SPAN&gt;&lt;SPAN&gt; row of the target feature class with the row from the source feature class.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;For some reason, this is not working.&amp;nbsp; The script runs without error, and I've inserted counters to make sure it is finding cases where the last modified dates are different (it is).&amp;nbsp; However, when I check the records of the target dataset after the script has run, no data has been changed at all.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Does anyone know why this is happening?&amp;nbsp; I want the entire record to be replaced with the source FCC record, and I thought updateRow() would do that.&amp;nbsp; The only other thing I can think of is to delete the existing record and insert the record I want in its place, but that seems kind of stupid to me.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="plain" name="code"&gt;sourceFCCur = arcpy.UpdateCursor(SourceFCPath) for sourceFCRow in sourceFCCur: &amp;nbsp;&amp;nbsp;&amp;nbsp; targetFCCur = arcpy.UpdateCursor(TargetFCPath) &amp;nbsp;&amp;nbsp;&amp;nbsp; for targetFCRow in targetFCCur: &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if targetFCRow.ID == sourceFCRow.ID: &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; sourceFCDate = sourceFCRow.getValue('LASTMODIFIED') &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; targetFCDate = targetFCRow.getValue('LASTMODIFIED') &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if sourceFCDate != targetFCDate: &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; targetFCCur.updateRow(targetFCRow) &amp;nbsp;&amp;nbsp;&amp;nbsp; del targetFCCur&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 07 Apr 2013 18:04:54 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/trouble-with-updatecursor-updaterow/m-p/59769#M4746</guid>
      <dc:creator>JeremyRead</dc:creator>
      <dc:date>2013-04-07T18:04:54Z</dc:date>
    </item>
    <item>
      <title>Re: Trouble with UpdateCursor.updateRow()</title>
      <link>https://community.esri.com/t5/python-questions/trouble-with-updatecursor-updaterow/m-p/59770#M4747</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Hi,&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;If you'll look at lines below (from your code) you will notice that you're overwriting row with itself, so i wouldn't expect any change in data:&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt; &lt;/SPAN&gt;&lt;BR /&gt;&lt;PRE class="plain" name="code"&gt;targetFCCur = arcpy.UpdateCursor(TargetFCPath) &amp;nbsp;&amp;nbsp;&amp;nbsp; for targetFCRow in targetFCCur: &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ... nothing with targetFCRow done here ... &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; targetFCCur.updateRow(targetFCRow)&lt;/PRE&gt;&lt;DIV style="display:none;"&gt; &lt;/DIV&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;You should copy each field value from source row to target row, it won't happen by itself.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Regards&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Arek&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 08 Apr 2013 07:07:58 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/trouble-with-updatecursor-updaterow/m-p/59770#M4747</guid>
      <dc:creator>ArkadiuszMatoszka</dc:creator>
      <dc:date>2013-04-08T07:07:58Z</dc:date>
    </item>
    <item>
      <title>Re: Trouble with UpdateCursor.updateRow()</title>
      <link>https://community.esri.com/t5/python-questions/trouble-with-updatecursor-updaterow/m-p/59771#M4748</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;like arek said, you have to get the values of your source FC and update the corresponding fields in the target FC.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;something like this should work (only tested with a small sample of data), or at least help get you started:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;import arcpy

source = "E:/test.mdb/src"
target = "E:/test.mdb/trg"

# cursor for sourceFC
s_rows = arcpy.SearchCursor(source)
# Dictionary for sourceFC´s fields
sDict = {}
# field names of sourceFC/targetFC, excluding Shape and OID
fList = [a.name for a in arcpy.ListFields(source) if a.name not in ("OBJECTID","Shape")]

# fill the sourceFC Dict(OIDs as keys) with dictionaries of its fieldnames/values
for s_row in s_rows:
&amp;nbsp;&amp;nbsp;&amp;nbsp; sDict[s_row.OBJECTID] = dict((k,s_row.getValue(k)) for k in fList)
del s_row,s_rows

# update cursor for targetFC
t_rows = arcpy.UpdateCursor(target)
for t_row in t_rows: 
&amp;nbsp;&amp;nbsp;&amp;nbsp; # compare the current row's field with the corresponding one from the sourceFC-dict
&amp;nbsp;&amp;nbsp;&amp;nbsp; # if values differ, update all target fields with sourceFC-dict´s values
&amp;nbsp;&amp;nbsp;&amp;nbsp; if t_row.LASTMODIFIED != sDict[t_row.OBJECTID]["LASTMODIFIED"]:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; for fName in fList:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; t_row.setValue(fName, sDict[t_row.OBJECTID][fName])
&amp;nbsp;&amp;nbsp;&amp;nbsp; t_rows.updateRow(t_row)
&amp;nbsp;&amp;nbsp;&amp;nbsp; 
del t_row,t_rows&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 10 Dec 2021 22:15:31 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/trouble-with-updatecursor-updaterow/m-p/59771#M4748</guid>
      <dc:creator>RaphaelR</dc:creator>
      <dc:date>2021-12-10T22:15:31Z</dc:date>
    </item>
    <item>
      <title>Re: Trouble with UpdateCursor.updateRow()</title>
      <link>https://community.esri.com/t5/python-questions/trouble-with-updatecursor-updaterow/m-p/59772#M4749</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Many thanks to both of you for your help.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I see what you mean about overwriting a row with itself.&amp;nbsp; That was a typo on my part as I was trying to change the names of the variables to be more generic/readable in the post, so my apologies on that.&amp;nbsp; The actual script was trying to read the row from the other cursor:&amp;nbsp; targetFCCur.updateRow(sourceFCRow)&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Raphael, thank you for the example you posted.&amp;nbsp; One question: what can I do to retain the shape information since it cannot be included in the dictionary?&amp;nbsp; All the other fields will need to be copied, but the shape will also need to be transferred.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;At the moment, I've decided to just delete the existing record and insert the updated record instead.&amp;nbsp; It's not ideal, but it is working ok if nothing else works.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 08 Apr 2013 20:35:17 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/trouble-with-updatecursor-updaterow/m-p/59772#M4749</guid>
      <dc:creator>JeremyRead</dc:creator>
      <dc:date>2013-04-08T20:35:17Z</dc:date>
    </item>
    <item>
      <title>Re: Trouble with UpdateCursor.updateRow()</title>
      <link>https://community.esri.com/t5/python-questions/trouble-with-updatecursor-updaterow/m-p/59773#M4750</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;If you're using arcgis 10.1 I would suggest using arcpy.da.UpdateCursor instead of arcpy.UpdateCursor.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;It much faster and offers easy access to geometry (simply add 'SHAPE@' to field list), disadvantage is its less intuitive at the beginning.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Regards,&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Arek&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 09 Apr 2013 09:51:16 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/trouble-with-updatecursor-updaterow/m-p/59773#M4750</guid>
      <dc:creator>ArkadiuszMatoszka</dc:creator>
      <dc:date>2013-04-09T09:51:16Z</dc:date>
    </item>
    <item>
      <title>Re: Trouble with UpdateCursor.updateRow()</title>
      <link>https://community.esri.com/t5/python-questions/trouble-with-updatecursor-updaterow/m-p/59774#M4751</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;changed the code a bit to update the shape field of the targetFC as well. works for me if the FCs are point-type.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;
import arcpy

source = "E:/test.mdb/src"
target = "E:/test.mdb/trg"

# cursor for sourceFC
s_rows = arcpy.SearchCursor(source)
# Dictionary for sourceFCs fields
sDict = {}
# field names of sourceFC/targetFC, excluding Shape and OID
fList = [a.name for a in arcpy.ListFields(source) if a.name not in ("OBJECTID","Shape")]

# fill the sourceFC Dict(OID as key) with dictionaries of its fieldnames/values
for s_row in s_rows:
&amp;nbsp;&amp;nbsp;&amp;nbsp; sDict[s_row.OBJECTID] = dict((k,s_row.getValue(k)) for k in fList)
&amp;nbsp;&amp;nbsp;&amp;nbsp; 
&amp;nbsp;&amp;nbsp;&amp;nbsp; # get point coordinates from the shape field and put them into the dict
&amp;nbsp;&amp;nbsp;&amp;nbsp; s_pnt = s_row.Shape.getPart()
&amp;nbsp;&amp;nbsp;&amp;nbsp; sDict[s_row.OBJECTID]["GEO"] = (s_pnt.X,s_pnt.Y)&amp;nbsp;&amp;nbsp;&amp;nbsp; 
del s_row,s_rows
print sDict

# update cursor for targetFC
t_rows = arcpy.UpdateCursor(target)

for t_row in t_rows: 
&amp;nbsp;&amp;nbsp;&amp;nbsp; # compare the current row's field with the corresponding one from the sourceFC-dict
&amp;nbsp;&amp;nbsp;&amp;nbsp; # if values differ, update all target fields with sourceFC-dicts values
&amp;nbsp;&amp;nbsp;&amp;nbsp; if t_row.LASTMODIFIED != sDict[t_row.OBJECTID]["LASTMODIFIED"]:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; for fName in fList:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; t_row.setValue(fName, sDict[t_row.OBJECTID][fName])
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; # replace point coordinates of shape field with values from the sourceFC-dict
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; t_pnt = arcpy.Point(sDict[t_row.OBJECTID]["GEO"][0],sDict[t_row.OBJECTID]["GEO"][1])
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; t_row.setValue("Shape", t_pnt)
&amp;nbsp;&amp;nbsp;&amp;nbsp; t_rows.updateRow(t_row)
&amp;nbsp;&amp;nbsp;&amp;nbsp; 
del t_row,t_rows&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 10 Dec 2021 22:15:33 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/trouble-with-updatecursor-updaterow/m-p/59774#M4751</guid>
      <dc:creator>RaphaelR</dc:creator>
      <dc:date>2021-12-10T22:15:33Z</dc:date>
    </item>
  </channel>
</rss>

