<?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 field with change in Z value from one point to the next in Python Snippets Questions</title>
    <link>https://community.esri.com/t5/python-snippets-questions/update-field-with-change-in-z-value-from-one-point/m-p/837979#M458</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Jake, Thanks for your help.&amp;nbsp; I may be mistaken but I think your code gets me the backward calc.&amp;nbsp; I need the forward calc. I put your code in and ran it and it gave me the below output.&amp;nbsp; I need the -1.442169 in the first row, not the second row.&amp;nbsp; This is because it is associated with other attributes in that row.&amp;nbsp; &lt;/P&gt;&lt;P&gt;&lt;IMG alt="" class="image-1 jive-image" src="https://community.esri.com/legacyfs/online/126313_pastedImage_0.png" style="max-width: 1200px; max-height: 900px;" /&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks again for your help,&lt;/P&gt;&lt;P&gt;Ian&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Thu, 10 Sep 2015 16:49:29 GMT</pubDate>
    <dc:creator>IanIrmischer</dc:creator>
    <dc:date>2015-09-10T16:49:29Z</dc:date>
    <item>
      <title>update field with change in Z value from one point to the next</title>
      <link>https://community.esri.com/t5/python-snippets-questions/update-field-with-change-in-z-value-from-one-point/m-p/837977#M456</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt; I am trying to write some python code to calculate a change in Z value from one point to the next. I have a number of point files with Z values in a field called &lt;EM style="font-size: 10.0pt; font-family: 'Calibri',sans-serif;"&gt;"RASTERVALU"&lt;/EM&gt;.&amp;nbsp; I have a field called zdiff that I would like to update with " Zdiff(row1)=Z(row2)-Z(row1)". I can use the update cursor it to look at the backwards change (Zdiff(row1)=z(row1)-Z(row0)) but not the forward change (Zdiff(row1)=z(row1)-Z(row0)). &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #1f497d;"&gt;I used the following code below but it seems like the updaterow.next() is messing up my sequential flow through the rows.&amp;nbsp; &lt;/SPAN&gt;Let me know if anyone has any ideas:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10.0pt;"&gt;updateRows=arcpy.da.&lt;SPAN style="text-decoration: underline;"&gt;UpdateCursor&lt;/SPAN&gt;(OutputFileName,[&lt;EM&gt;"RASTERVALU"&lt;/EM&gt;,&lt;EM&gt;"zDiff"&lt;/EM&gt;]) &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10.0pt;"&gt;for row in updateRows:&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10.0pt;"&gt; nextRow=updateRows.next()&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10.0pt;"&gt; zdiff=nextRow[0]-row[0]&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10.0pt;"&gt; row[1]=zdiff&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10.0pt;"&gt; updateRows.updateRow(row)&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #1f497d;"&gt;The first run through the loop works ok but then it iterates to the third row instead of the second row. I assume it is because of my use of updateRows.next() but I am not sure. I can’t find very good documentation of the updateRow.next or any of the cursor information.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Any thoughts?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Ian&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 10 Sep 2015 15:57:11 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-snippets-questions/update-field-with-change-in-z-value-from-one-point/m-p/837977#M456</guid>
      <dc:creator>IanIrmischer</dc:creator>
      <dc:date>2015-09-10T15:57:11Z</dc:date>
    </item>
    <item>
      <title>Re: update field with change in Z value from one point to the next</title>
      <link>https://community.esri.com/t5/python-snippets-questions/update-field-with-change-in-z-value-from-one-point/m-p/837978#M457</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Ian,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Here is one way you can do this:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;with arcpy.da.UpdateCursor(&lt;SPAN style="font-size: 10.0pt;"&gt;OutputFileName&lt;/SPAN&gt;, ["RASTERVALU", "zDiff"]) as cursor:
&amp;nbsp;&amp;nbsp;&amp;nbsp; firstTime = True
&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 firstTime:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; diff = row[0]
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; row[1] = 0
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; firstTime = False
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; else:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; row[1] = row[0] - diff
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; diff = row[0]
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; cursor.updateRow(row)

del cursor&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 12 Dec 2021 10:11:18 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-snippets-questions/update-field-with-change-in-z-value-from-one-point/m-p/837978#M457</guid>
      <dc:creator>JakeSkinner</dc:creator>
      <dc:date>2021-12-12T10:11:18Z</dc:date>
    </item>
    <item>
      <title>Re: update field with change in Z value from one point to the next</title>
      <link>https://community.esri.com/t5/python-snippets-questions/update-field-with-change-in-z-value-from-one-point/m-p/837979#M458</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Jake, Thanks for your help.&amp;nbsp; I may be mistaken but I think your code gets me the backward calc.&amp;nbsp; I need the forward calc. I put your code in and ran it and it gave me the below output.&amp;nbsp; I need the -1.442169 in the first row, not the second row.&amp;nbsp; This is because it is associated with other attributes in that row.&amp;nbsp; &lt;/P&gt;&lt;P&gt;&lt;IMG alt="" class="image-1 jive-image" src="https://community.esri.com/legacyfs/online/126313_pastedImage_0.png" style="max-width: 1200px; max-height: 900px;" /&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks again for your help,&lt;/P&gt;&lt;P&gt;Ian&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 10 Sep 2015 16:49:29 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-snippets-questions/update-field-with-change-in-z-value-from-one-point/m-p/837979#M458</guid>
      <dc:creator>IanIrmischer</dc:creator>
      <dc:date>2015-09-10T16:49:29Z</dc:date>
    </item>
    <item>
      <title>Re: update field with change in Z value from one point to the next</title>
      <link>https://community.esri.com/t5/python-snippets-questions/update-field-with-change-in-z-value-from-one-point/m-p/837980#M459</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Try the following:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;valueList = []

with arcpy.da.SearchCursor(OutputFileName, ["RASTERVALU"]) 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; valueList.append(row[0])
del cursor

x = 1

with arcpy.da.UpdateCursor(OutputFileName, ["RASTERVALU", "zDiff"]) 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; try:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; value = valueList&lt;X&gt;&lt;/X&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; except:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; value = valueList[-1]

&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; row[1] = row[0] - value
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; x += 1
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; cursor.updateRow(row)

del cursor&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 12 Dec 2021 10:11:21 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-snippets-questions/update-field-with-change-in-z-value-from-one-point/m-p/837980#M459</guid>
      <dc:creator>JakeSkinner</dc:creator>
      <dc:date>2021-12-12T10:11:21Z</dc:date>
    </item>
    <item>
      <title>Re: update field with change in Z value from one point to the next</title>
      <link>https://community.esri.com/t5/python-snippets-questions/update-field-with-change-in-z-value-from-one-point/m-p/837981#M460</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Jake, Thanks so much.&amp;nbsp; That worked and it was really helpful.&amp;nbsp; The code with the searchCursor will also help me many other places in my work.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks again,&lt;/P&gt;&lt;P&gt;Ian&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 10 Sep 2015 17:40:12 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-snippets-questions/update-field-with-change-in-z-value-from-one-point/m-p/837981#M460</guid>
      <dc:creator>IanIrmischer</dc:creator>
      <dc:date>2015-09-10T17:40:12Z</dc:date>
    </item>
  </channel>
</rss>

