<?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: problem with arcpy.da.updateCursor in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/problem-with-arcpy-da-updatecursor/m-p/570703#M44734</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;At a quick glance, you're looping through your SearchCursor, and within that SearchCursor you're looping through the UpdateCursor. So each time through the Search loop, you're updating all your data with the same set of data, the one row, of search results. If three loops through your SearchCursor returned a, b, c, respectively, your UpdateCursor then populates your field with all a's, then all b's, then all c's, respectively.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Fri, 20 Jun 2014 12:30:40 GMT</pubDate>
    <dc:creator>Zeke</dc:creator>
    <dc:date>2014-06-20T12:30:40Z</dc:date>
    <item>
      <title>problem with arcpy.da.updateCursor</title>
      <link>https://community.esri.com/t5/python-questions/problem-with-arcpy-da-updatecursor/m-p/570702#M44733</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;I'm a programming-beginner and I am currently writing my first Python-Script. That's why the question is more a general (or perhaps a semantic) one. I want to write a specific ID to the attribute table of an existing shapefile. This ID is amongst others composed of the coordinates (centroid) of the shape. So I tried the following:&lt;/SPAN&gt;&lt;BR /&gt;&lt;PRE class="plain" name="code"&gt;import arcpy&amp;nbsp;&amp;nbsp; arcpy.env.workspace = "**************" outline = "***********testoutline7.shp" fields = ['SHAPE@XY']&amp;nbsp; with arcpy.da.SearchCursor(outline, fields) as cursor: &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; coordX = row[0][0] &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if coordX &amp;lt; 0: &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; coordX = coordX + 360 &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; coordY = row[0][1]&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; print "X: {}, Y: {}".format(coordX,coordY)&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; #----transformation of the centroid-coordinates---# &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Xrnd = round(coordX, 3) &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; longitude = str(Xrnd) &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; glimsLongitude = longitude.split('.') &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Yrnd = round(coordY, 3) &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; latitude = str(Yrnd) &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; glimsLatitude = latitude.split('.') &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;&amp;nbsp; with arcpy.da.UpdateCursor(outline, "GLIMS_ID") as crsr: &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; for glims in crsr: &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; glims[0] = "G" + glimsLongitude[0] + glimsLongitude[1] + "E" + glimsLatitude[0] + glimsLatitude[1] + "N" &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; crsr.updateRow(glims)&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;The problem is, that after processing there is the same ID in every polygon of the shapefile. I'm using only a test-shapefile to try it and it consists of 3 polygons. They all get the same ID in their attribut-field "GLIMS_ID". But the print-statement above on the other hand returns all the different coordinates of the different polygons. What's the mistake?&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;I know, the code requires a lot of revision and it is not yet beautiful. I would therefore be open-minded for every other suggestion for improvement. I also tried to vary the "position" of the last 4 lines, without success.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Thank you for your help!&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 20 Jun 2014 11:32:23 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/problem-with-arcpy-da-updatecursor/m-p/570702#M44733</guid>
      <dc:creator>MarcListemann</dc:creator>
      <dc:date>2014-06-20T11:32:23Z</dc:date>
    </item>
    <item>
      <title>Re: problem with arcpy.da.updateCursor</title>
      <link>https://community.esri.com/t5/python-questions/problem-with-arcpy-da-updatecursor/m-p/570703#M44734</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;At a quick glance, you're looping through your SearchCursor, and within that SearchCursor you're looping through the UpdateCursor. So each time through the Search loop, you're updating all your data with the same set of data, the one row, of search results. If three loops through your SearchCursor returned a, b, c, respectively, your UpdateCursor then populates your field with all a's, then all b's, then all c's, respectively.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 20 Jun 2014 12:30:40 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/problem-with-arcpy-da-updatecursor/m-p/570703#M44734</guid>
      <dc:creator>Zeke</dc:creator>
      <dc:date>2014-06-20T12:30:40Z</dc:date>
    </item>
    <item>
      <title>Re: problem with arcpy.da.updateCursor</title>
      <link>https://community.esri.com/t5/python-questions/problem-with-arcpy-da-updatecursor/m-p/570704#M44735</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;BLOCKQUOTE class="jive-quote"&gt;At a quick glance, you're looping through your SearchCursor, and within that SearchCursor you're looping through the UpdateCursor. So each time through the Search loop, you're updating all your data with the same set of data, the one row, of search results. If three loops through your SearchCursor returned a, b, c, respectively, your UpdateCursor then populates your field with all a's, then all b's, then all c's, respectively.&lt;/BLOCKQUOTE&gt;&lt;BR /&gt;&lt;SPAN&gt; &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Ok, thank you, I guess i see what you mean. But do you therefore also have a solution? I tried to set the UpdateCursor-Method out of the SearchCursor-loop, but with the same effect. Is UpdateCursor probably the wrong approach for this purpose?&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 20 Jun 2014 17:50:46 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/problem-with-arcpy-da-updatecursor/m-p/570704#M44735</guid>
      <dc:creator>MarcListemann</dc:creator>
      <dc:date>2014-06-20T17:50:46Z</dc:date>
    </item>
    <item>
      <title>Re: problem with arcpy.da.updateCursor</title>
      <link>https://community.esri.com/t5/python-questions/problem-with-arcpy-da-updatecursor/m-p/570705#M44736</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Try not putting your Update code in its own loop. If necessary, retrieve the OID or other unique field in your SearchCursor as well as the current field. Use the OID in a Where clause in your UpdateCursor. This way you'll loop through the records in your SearchCursor, and target the record the SearchCursor is on in your UpdateCursor.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Or, you could try ditching the SearchCursor and just use an UpdateCursor, doing your calculation there before you call updateRow. I've never done this, but Help says UpdateCursor is read/write, so presumably it can function as a SearchCursor as well. The next() method returns a tuple of the values, so you should be able to read the necessary values out of that.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 20 Jun 2014 19:02:03 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/problem-with-arcpy-da-updatecursor/m-p/570705#M44736</guid>
      <dc:creator>Zeke</dc:creator>
      <dc:date>2014-06-20T19:02:03Z</dc:date>
    </item>
    <item>
      <title>Re: problem with arcpy.da.updateCursor</title>
      <link>https://community.esri.com/t5/python-questions/problem-with-arcpy-da-updatecursor/m-p/570706#M44737</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Great! I used your latter suggestion (but without the next()-method) and it worked! Just using the UpdateCursor without SearchCursor. It's actually that simple.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Many thanks!&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 20 Jun 2014 22:01:59 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/problem-with-arcpy-da-updatecursor/m-p/570706#M44737</guid>
      <dc:creator>MarcListemann</dc:creator>
      <dc:date>2014-06-20T22:01:59Z</dc:date>
    </item>
  </channel>
</rss>

