<?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: Is there a way to perform a field calculate function based on attributes in another feature? in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/is-there-a-way-to-perform-a-field-calculate/m-p/148418#M11532</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Ah, in that case, I would read all your features into a dictionary, using Downstream ID as the key, then loop through all the features with an Update Cursor and look up the values in the dictionary to populate the current feature in the cursor, matching the current Upstream ID to the key in the dictionary.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Tue, 17 Jul 2018 22:06:29 GMT</pubDate>
    <dc:creator>DarrenWiens2</dc:creator>
    <dc:date>2018-07-17T22:06:29Z</dc:date>
    <item>
      <title>Is there a way to perform a field calculate function based on attributes in another feature?</title>
      <link>https://community.esri.com/t5/python-questions/is-there-a-way-to-perform-a-field-calculate/m-p/148415#M11529</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P style="color: #242729; background-color: rgba(248, 248, 248, 0.6); border: 0px; margin: 0px 0px 1em;"&gt;I have two fields that describe a points placement on a line. Each point has a unique ID, and a field describing the next ID "downstream". My goal is to compare a third field (field3) where the unique ID = the downstream ID.&lt;/P&gt;&lt;P style="color: #242729; background-color: rgba(248, 248, 248, 0.6); border: 0px; margin: 0px 0px 1em;"&gt;The downstream (DownstreamID) value of the third field (Field3_2) should be less than the third field (Field3_1) of the upstream (UniqueID) feature.&lt;/P&gt;&lt;P style="color: #242729; background-color: rgba(248, 248, 248, 0.6); border: 0px; margin: 0px 0px 1em;"&gt;I also included a section of visual basic code for performing a similar function in excel.&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;For (Each Feature) 
&amp;nbsp;&amp;nbsp;&amp;nbsp;if UniqeID /*(from feature1)*/ = DownstreamID /*(from feature2)*/ &amp;amp; Field3_1 /*(from feature1)*/ &amp;gt; Field3_2 /*(from feature2)*/: 
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;return(1) 
&amp;nbsp;&amp;nbsp;&amp;nbsp;else: 
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;return(0)

__________________________________________________________________________________________________

 If NextDownID &amp;lt;&amp;gt; -1 Then
 
 &amp;nbsp;&amp;nbsp;&amp;nbsp;NextDownRow = Application.Match(Cells(rw, 2), Columns(1), 0)
 
 &amp;nbsp;&amp;nbsp;&amp;nbsp;For i = 0 To 7 'create array with US Flows
 &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;If Cells(rw, USColumn + i).Value &amp;lt;&amp;gt; "" Then 'check if flow value exists
 &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;tmpUS(i) = Cells(rw, USColumn + i).Value 'if yes, add to array
 &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;tmpUS(i) = 0 'else, put in 0 (null causes issues)
 &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;End If
 &amp;nbsp;&amp;nbsp;&amp;nbsp;Next i
 
 &amp;nbsp;&amp;nbsp;&amp;nbsp;For j = 0 To 7 'create array with DS Flows
 &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;tmpq = Application.Index(Columns(3 + j), NextDownRow)
 &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;If tmpq &amp;lt;&amp;gt; "" Then
 &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;tmpDS(j) = tmpq
 &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;tmpDS(j) = 0
 &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;End If
 &amp;nbsp;&amp;nbsp;&amp;nbsp;Next j
 
 &amp;nbsp;&amp;nbsp;&amp;nbsp;For k = 0 To 7
 &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;tmpcmp(k) = tmpDS(k) - tmpUS(k) 'tmpCmp will be negative if US flows are &amp;gt; DS flows (i.e. flows are not increasing in the DS direction)
 &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;If tmpcmp(k) &amp;lt; 0 Then
 &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;Worksheets(outputsheet).Cells(outrw, 1).Value = NextDownID 'creates a row in the output sheet for the NextDownID. Only occurs if a DS flow need sto be replaced
 &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;NextDownNEW = Application.VLookup(NextDownID, Worksheets(inputsheet).Range("A:B"), 2, False) 'Determines the NextDownID associated with the Output Sheet HydroID i.e. InputSheet HydroID's NextDownID's NextDownID
 &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;Worksheets(outputsheet).Cells(outrw, 2).Value = NextDownNEW 'Prints NextDownNEW. Useful for iterating macro
 &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;Worksheets(outputsheet).Cells(outrw, k + 3).Value = tmpUS(k) 'Prints flows that need to be revised
 &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;FailCount = FailCount + 1
 &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;End If
 &amp;nbsp;&amp;nbsp;&amp;nbsp;Next k
 Else
 End If
 
 If Sheets(outputsheet).Cells(outrw, 1).Value &amp;lt;&amp;gt; 0 Then
 &amp;nbsp;&amp;nbsp;&amp;nbsp;outrw = outrw + 1 'If the Loop printed a HydroID, add 1 to outrow so on the next iteration the macro prints to the next row
 Else
 End If
 
 &amp;nbsp;&amp;nbsp;&amp;nbsp;rw = rw + 1
Loop&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 12 Dec 2021 16:06:20 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/is-there-a-way-to-perform-a-field-calculate/m-p/148415#M11529</guid>
      <dc:creator>IsaacRemboldt1</dc:creator>
      <dc:date>2021-12-12T16:06:20Z</dc:date>
    </item>
    <item>
      <title>Re: Is there a way to perform a field calculate function based on attributes in another feature?</title>
      <link>https://community.esri.com/t5/python-questions/is-there-a-way-to-perform-a-field-calculate/m-p/148416#M11530</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Make a &lt;A href="http://desktop.arcgis.com/en/arcmap/10.3/manage-data/tables/about-joining-and-relating-tables.htm"&gt;join&lt;/A&gt;, then calculate.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;edit: using Python, you may be able to read all features of one feature class into a dictionary (depending on feature class size), then go through the features of the other feature class using an Update Cursor to change values.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 17 Jul 2018 20:40:56 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/is-there-a-way-to-perform-a-field-calculate/m-p/148416#M11530</guid>
      <dc:creator>DarrenWiens2</dc:creator>
      <dc:date>2018-07-17T20:40:56Z</dc:date>
    </item>
    <item>
      <title>Re: Is there a way to perform a field calculate function based on attributes in another feature?</title>
      <link>https://community.esri.com/t5/python-questions/is-there-a-way-to-perform-a-field-calculate/m-p/148417#M11531</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I think I phrased my question a bit incorrectly, by feature I meant a single row in the same shapefile. So I would compare a&amp;nbsp;Unique ID in field one with all the&amp;nbsp;downstream IDs in field 2 for every feature to find a match within the same shapefile. I have a visual basic example of this code for excel, but I was trying to get a working python example for doing it directly in ArcMap.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 17 Jul 2018 21:17:31 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/is-there-a-way-to-perform-a-field-calculate/m-p/148417#M11531</guid>
      <dc:creator>IsaacRemboldt1</dc:creator>
      <dc:date>2018-07-17T21:17:31Z</dc:date>
    </item>
    <item>
      <title>Re: Is there a way to perform a field calculate function based on attributes in another feature?</title>
      <link>https://community.esri.com/t5/python-questions/is-there-a-way-to-perform-a-field-calculate/m-p/148418#M11532</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Ah, in that case, I would read all your features into a dictionary, using Downstream ID as the key, then loop through all the features with an Update Cursor and look up the values in the dictionary to populate the current feature in the cursor, matching the current Upstream ID to the key in the dictionary.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 17 Jul 2018 22:06:29 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/is-there-a-way-to-perform-a-field-calculate/m-p/148418#M11532</guid>
      <dc:creator>DarrenWiens2</dc:creator>
      <dc:date>2018-07-17T22:06:29Z</dc:date>
    </item>
    <item>
      <title>Re: Is there a way to perform a field calculate function based on attributes in another feature?</title>
      <link>https://community.esri.com/t5/python-questions/is-there-a-way-to-perform-a-field-calculate/m-p/148419#M11533</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thanks for this tip, I had started messing around with the "table to numpy array" tool but using a dictionary instead of an array might work better.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 18 Jul 2018 22:48:24 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/is-there-a-way-to-perform-a-field-calculate/m-p/148419#M11533</guid>
      <dc:creator>IsaacRemboldt1</dc:creator>
      <dc:date>2018-07-18T22:48:24Z</dc:date>
    </item>
    <item>
      <title>Re: Is there a way to perform a field calculate function based on attributes in another feature?</title>
      <link>https://community.esri.com/t5/python-questions/is-there-a-way-to-perform-a-field-calculate/m-p/148420#M11534</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;You could do that, too. In any case, the pattern is similar: make a copy, join/match, calculate.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 18 Jul 2018 23:23:50 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/is-there-a-way-to-perform-a-field-calculate/m-p/148420#M11534</guid>
      <dc:creator>DarrenWiens2</dc:creator>
      <dc:date>2018-07-18T23:23:50Z</dc:date>
    </item>
  </channel>
</rss>

