<?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 How to pair SearchCursor with UpdateCursor in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/how-to-pair-searchcursor-with-updatecursor/m-p/34596#M2690</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I am having a little trouble figuring out where I am going wrong.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;If I have "NW" in my direction field I want to move the point a certain distance, but if it is "NE"&amp;nbsp; I want the move to be opposite.&amp;nbsp; I think I am almost there but it will only take my last Update for all the features.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;import arcpy


mxd = arcpy.mapping.MapDocument("CURRENT")


arcpy.env.overwriteOutput = True


fc = arcpy.GetParameterAsText(0)


NWxOffset = 200
NWyOffset = 200


NExOffset = -220
NEyOffset = -200


search = arcpy.SearchCursor(fc)
value = ""
for row in search:
&amp;nbsp;&amp;nbsp;&amp;nbsp; value = row.getValue("direction")
&amp;nbsp;&amp;nbsp;&amp;nbsp; with arcpy.da.UpdateCursor(fc, ["SHAPE@XY"]) as cursor:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if value == "NW":
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; for row in cursor:
&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; cursor.updateRow([[row[0][0] + NWxOffset, row[0][1] + NWyOffset]])
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; elif value == "NE":
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; for row in cursor:
&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; cursor.updateRow([[row[0][0] + NExOffset, row[0][1] + NEyOffset]])


arcpy.RefreshActiveView&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Fri, 10 Dec 2021 21:20:37 GMT</pubDate>
    <dc:creator>deleted-user-MS0lE1F_0-sy</dc:creator>
    <dc:date>2021-12-10T21:20:37Z</dc:date>
    <item>
      <title>How to pair SearchCursor with UpdateCursor</title>
      <link>https://community.esri.com/t5/python-questions/how-to-pair-searchcursor-with-updatecursor/m-p/34596#M2690</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I am having a little trouble figuring out where I am going wrong.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;If I have "NW" in my direction field I want to move the point a certain distance, but if it is "NE"&amp;nbsp; I want the move to be opposite.&amp;nbsp; I think I am almost there but it will only take my last Update for all the features.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;import arcpy


mxd = arcpy.mapping.MapDocument("CURRENT")


arcpy.env.overwriteOutput = True


fc = arcpy.GetParameterAsText(0)


NWxOffset = 200
NWyOffset = 200


NExOffset = -220
NEyOffset = -200


search = arcpy.SearchCursor(fc)
value = ""
for row in search:
&amp;nbsp;&amp;nbsp;&amp;nbsp; value = row.getValue("direction")
&amp;nbsp;&amp;nbsp;&amp;nbsp; with arcpy.da.UpdateCursor(fc, ["SHAPE@XY"]) as cursor:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if value == "NW":
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; for row in cursor:
&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; cursor.updateRow([[row[0][0] + NWxOffset, row[0][1] + NWyOffset]])
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; elif value == "NE":
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; for row in cursor:
&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; cursor.updateRow([[row[0][0] + NExOffset, row[0][1] + NEyOffset]])


arcpy.RefreshActiveView&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 10 Dec 2021 21:20:37 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/how-to-pair-searchcursor-with-updatecursor/m-p/34596#M2690</guid>
      <dc:creator>deleted-user-MS0lE1F_0-sy</dc:creator>
      <dc:date>2021-12-10T21:20:37Z</dc:date>
    </item>
    <item>
      <title>Re: How to pair SearchCursor with UpdateCursor</title>
      <link>https://community.esri.com/t5/python-questions/how-to-pair-searchcursor-with-updatecursor/m-p/34597#M2691</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;You shouldn't need to combine cursors.&amp;nbsp; You can use the update cursor to check the value of your direction field, then depending on the value of the direction field.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;import arcpy
mxd = arcpy.mapping.MapDocument("CURRENT")
arcpy.env.overwriteOutput = True
fc = arcpy.GetParameterAsText(0)
NWxOffset = 200&amp;nbsp; 
NWyOffset = 200&amp;nbsp; 
NExOffset = -220&amp;nbsp; 
NEyOffset = -200&amp;nbsp; 
fields = ["direction" , "SHAPE@X", "SHAPE@Y"]
with arcpy.da.UpdateCursor(fc, fields) as cursor:
&amp;nbsp;&amp;nbsp;&amp;nbsp; for row in cursor:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if row[0] == "NW":
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; row[1] += NWxOffset
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; row[2] += NWyOffset
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; elif row[0] == "NE":
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; row[1] += NExOffset
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; row[2] += NEyOffset
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; cursor.updateRow(row)
arcpy.RefreshActiveView&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 10 Dec 2021 21:20:40 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/how-to-pair-searchcursor-with-updatecursor/m-p/34597#M2691</guid>
      <dc:creator>IanMurray</dc:creator>
      <dc:date>2021-12-10T21:20:40Z</dc:date>
    </item>
    <item>
      <title>Re: How to pair SearchCursor with UpdateCursor</title>
      <link>https://community.esri.com/t5/python-questions/how-to-pair-searchcursor-with-updatecursor/m-p/34598#M2692</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Ian,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; That's it, learned something new.&amp;nbsp; Thank you so much.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;- Matt&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 13 Mar 2015 15:47:33 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/how-to-pair-searchcursor-with-updatecursor/m-p/34598#M2692</guid>
      <dc:creator>deleted-user-MS0lE1F_0-sy</dc:creator>
      <dc:date>2015-03-13T15:47:33Z</dc:date>
    </item>
    <item>
      <title>Re: How to pair SearchCursor with UpdateCursor</title>
      <link>https://community.esri.com/t5/python-questions/how-to-pair-searchcursor-with-updatecursor/m-p/34599#M2693</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;The other important thing to notice about UpdateCursors is that when you want to update the value of field, you actually need to set its value, using the rows index value from the cursor.&amp;nbsp; Once you set all the values, you then use cursor.updateRow(row) to update all the values in that row, not individually like I believe you were trying in your code.&amp;nbsp; You could have used two cursors, but that makes it fairly slower.&amp;nbsp; If this was a first attempt at using cursors, it was a good try.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;A href="https://community.esri.com/migrated-users/19932"&gt;Darren Wiens&lt;/A&gt;​, since it returns SHAPE@XY as a tuple in his original code, he shouldn't have been able to adjust the features centroid since tuples are immutable correct, or does an update cursor allow you to update SHAPE@XY?&amp;nbsp; Curious if you know, if not I might investigate some.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 13 Mar 2015 15:57:02 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/how-to-pair-searchcursor-with-updatecursor/m-p/34599#M2693</guid>
      <dc:creator>IanMurray</dc:creator>
      <dc:date>2015-03-13T15:57:02Z</dc:date>
    </item>
    <item>
      <title>Re: How to pair SearchCursor with UpdateCursor</title>
      <link>https://community.esri.com/t5/python-questions/how-to-pair-searchcursor-with-updatecursor/m-p/34600#M2694</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I won't pretend to understand the inner workings of it (I usually use 'SHAPE@', as a convenient but wasteful practice), but I think that because cursor.updateRow updates the table value rather than changing the tuple itself, it works, like below.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;&amp;gt;&amp;gt;&amp;gt; with arcpy.da.UpdateCursor("fc",'SHAPE@XY') as cursor:
...&amp;nbsp;&amp;nbsp;&amp;nbsp; for row in cursor:
...&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; cursor.updateRow([[row[0][0]+100, row[0][1]+1000]])&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The value of row never changes within the loop.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Conversely, the following does not work, for the reason you've identified:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;&amp;gt;&amp;gt;&amp;gt; with arcpy.da.UpdateCursor("fc",'SHAPE@XY') as cursor:
...&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; for row in cursor:
...&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; row[0][0] += 100
...&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; row[0][1] += 1000
...&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; cursor.updateRow([[row]])
...&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 
Runtime error 
Traceback (most recent call last):
&amp;nbsp; File "&amp;lt;string&amp;gt;", line 3, in &amp;lt;module&amp;gt;
TypeError: 'tuple' object does not support item assignment&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 10 Dec 2021 21:20:43 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/how-to-pair-searchcursor-with-updatecursor/m-p/34600#M2694</guid>
      <dc:creator>DarrenWiens2</dc:creator>
      <dc:date>2021-12-10T21:20:43Z</dc:date>
    </item>
  </channel>
</rss>

