<?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: What sorcery is this? in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/what-sorcery-is-this/m-p/372541#M29431</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I just re-checked it once again. They are correctly assigned.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Tue, 23 Jun 2015 17:48:13 GMT</pubDate>
    <dc:creator>SalmanAhmed</dc:creator>
    <dc:date>2015-06-23T17:48:13Z</dc:date>
    <item>
      <title>What sorcery is this?</title>
      <link>https://community.esri.com/t5/python-questions/what-sorcery-is-this/m-p/372538#M29428</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;import arcpy&lt;/P&gt;&lt;P&gt;arcpy.env.overwriteOutput = True&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;fc_in = 'E://SUT//Thesis//Geodata//Thesis.gdb//NRW_Gemeinde'&lt;/P&gt;&lt;P&gt;fc_in2 = 'E://SUT//Thesis//Geodata//Thesis.gdb//NRWCommuterData2'&lt;/P&gt;&lt;P&gt;fc_in3 = 'E://SUT//Thesis//Geodata//Thesis.gdb//NRWGemeindeDissolveFinal_SpatialJoin'&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;dct = {} #Dictionary for gemeinde-workers pair&lt;/P&gt;&lt;P&gt;dct2 = {} #Dictionary for gemeinde-value pair&lt;/P&gt;&lt;P&gt;dct3 = {} #Dictionary for gemeined-result pair&lt;/P&gt;&lt;P&gt;dct4 = {} #Dictionary for caseID-result pair&lt;/P&gt;&lt;P&gt;dct5 = {} #Dictionary for sub-region origin and destination pair&lt;/P&gt;&lt;P&gt;dct6 = {} #Dictionary for case_ID and result pair&lt;/P&gt;&lt;P&gt;lst = [] #List for case IDs&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;fld_gemeinde = 'GEN'&lt;/P&gt;&lt;P&gt;fld_workers = 'Workers'&lt;/P&gt;&lt;P&gt;fld_result = 'Result'&lt;/P&gt;&lt;P&gt;fld_o = 'GEN'&lt;/P&gt;&lt;P&gt;fld_d = 'GEN_1'&lt;/P&gt;&lt;P&gt;fld_caseID = 'Case_ID_Ne'&lt;/P&gt;&lt;P&gt;fld_caseID2 = 'Case_ID'&lt;/P&gt;&lt;P&gt;fld_value = 'Value'&lt;/P&gt;&lt;P&gt;fld_sub_region_o = 'Sub_Region'&lt;/P&gt;&lt;P&gt;fld_sub_region_d = 'Sub_Regi_1'&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;with arcpy.da.SearchCursor(fc_in, (fld_gemeinde, fld_workers), sql_clause=(None, 'ORDER BY "GEN" ASC')) as cursor:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; for row in cursor:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; dct[row[0]] = row[1]&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;arcpy.AddField_management(fc_in2, fld_result, 'DOUBLE')&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;with arcpy.da.UpdateCursor(fc_in2, (fld_o, fld_d, fld_caseID, fld_result, fld_value), sql_clause=(None, 'ORDER BY "GEN" ASC')) as cursor2:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; for row2 in cursor2:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if row2[2] in lst:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; row2[3] = (row2[4] + dct2[row2[2]])/dct[row2[0]]&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; dct2[row2[2]] = row2[4] + dct2[row2[2]]&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;STRONG&gt;dct4[row2[2]] = row2[3]&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; else:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; row2[3] = row2[4]/dct[row2[0]]&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; lst.extend([row2[2]])&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; dct2[row2[2]] = row2[4]&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; dct4[row2[2]] = row2[3]&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; cursor2.updateRow(row2)&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;arcpy.AddField_management(fc_in3, fld_result, 'DOUBLE')&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;with arcpy.da.UpdateCursor(fc_in3, (fld_caseID2, fld_result)) as cursor3:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; for row3 in cursor3:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;STRONG&gt;row3[1] = dct4[row3[0]]&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; cursor3.updateRow(row3)&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Clearly the two lines in the code in bold means that the two circled values in the image should be same. But they are not ! I feel like my head will burst open trying to figure why. Please can some help me?&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 23 Jun 2015 17:19:58 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/what-sorcery-is-this/m-p/372538#M29428</guid>
      <dc:creator>SalmanAhmed</dc:creator>
      <dc:date>2015-06-23T17:19:58Z</dc:date>
    </item>
    <item>
      <title>Re: What sorcery is this?</title>
      <link>https://community.esri.com/t5/python-questions/what-sorcery-is-this/m-p/372539#M29429</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Here is the code in PythonWin&lt;IMG alt="Untitledcode.png" class="image-1 jive-image" src="https://community.esri.com/legacyfs/online/112771_Untitledcode.png" style="width: 620px; height: 272px;" /&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 23 Jun 2015 17:26:55 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/what-sorcery-is-this/m-p/372539#M29429</guid>
      <dc:creator>SalmanAhmed</dc:creator>
      <dc:date>2015-06-23T17:26:55Z</dc:date>
    </item>
    <item>
      <title>Re: What sorcery is this?</title>
      <link>https://community.esri.com/t5/python-questions/what-sorcery-is-this/m-p/372540#M29430</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;From your code, there's no guarantee that you've correctly assigned &lt;STRONG style="font-family: arial, helvetica, 'helvetica neue', verdana, sans-serif;"&gt;fld_caseID &lt;/STRONG&gt;&lt;SPAN style="font-family: arial, helvetica, 'helvetica neue', verdana, sans-serif;"&gt;and&lt;/SPAN&gt;&lt;STRONG style="font-family: arial, helvetica, 'helvetica neue', verdana, sans-serif;"&gt;&lt;SPAN style="font-family: arial, helvetica, 'helvetica neue', verdana, sans-serif;"&gt; &lt;/SPAN&gt;&lt;STRONG style="font-family: arial, helvetica, 'helvetica neue', verdana, sans-serif;"&gt;fld_caseID2&lt;/STRONG&gt;&lt;/STRONG&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 23 Jun 2015 17:43:11 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/what-sorcery-is-this/m-p/372540#M29430</guid>
      <dc:creator>DarrenWiens2</dc:creator>
      <dc:date>2015-06-23T17:43:11Z</dc:date>
    </item>
    <item>
      <title>Re: What sorcery is this?</title>
      <link>https://community.esri.com/t5/python-questions/what-sorcery-is-this/m-p/372541#M29431</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I just re-checked it once again. They are correctly assigned.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 23 Jun 2015 17:48:13 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/what-sorcery-is-this/m-p/372541#M29431</guid>
      <dc:creator>SalmanAhmed</dc:creator>
      <dc:date>2015-06-23T17:48:13Z</dc:date>
    </item>
    <item>
      <title>Re: What sorcery is this?</title>
      <link>https://community.esri.com/t5/python-questions/what-sorcery-is-this/m-p/372542#M29432</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;The results written to &lt;SPAN style="font-family: arial, helvetica, 'helvetica neue', verdana, sans-serif;"&gt;fc_in2 are based on the records read until that moment. The result written to fc_in3 are based on dct4 after all the data in fc_in2 have been processed. Therefore, you wont have the same result for these two featureclasses.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;During cursor on fc_in2:&lt;/P&gt;&lt;P&gt;# caseID in list&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; # result = (value + dct2[caseID])&amp;nbsp; / workers&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; # dct2[caseID] = value + dct2[caseID]&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; # dct4[caseID] = result&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;# caseID not in list&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; # result = value / workers&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; # add caseID to list&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; # dct2[caseID] = result&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; # dct4[caseID] = result&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;For each row the result of that moment will be written to fc_in2. However the result corresponding to dct4 for key caseID keeps getting updated. In case you want to get the same result in both featureclasses AND&amp;nbsp; the result in fc_in3 is correct, the second cursor should be a search cursor to generate dct4 and afterwards you should do an update cursor to on fc_in2 to set the result values from dct4.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Maybe some more explanation on what you are trying to obtain could be helpful. And the workers are not shown in the image. If you could attach the data, people can have a better understanding of what is going on.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 24 Jun 2015 02:53:27 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/what-sorcery-is-this/m-p/372542#M29432</guid>
      <dc:creator>XanderBakker</dc:creator>
      <dc:date>2015-06-24T02:53:27Z</dc:date>
    </item>
    <item>
      <title>Re: What sorcery is this?</title>
      <link>https://community.esri.com/t5/python-questions/what-sorcery-is-this/m-p/372543#M29433</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Yes you are correct, dct4 for key caseID keeps getting updated as the update cursor moves on each row in fc_in2. But after that I need these updated values from dct4 to be written to fc_in3 in the result field. Thats why I first run update Cursor on fc_in2 - this updates dct4 and gives each caseID a result value (in dct4) and then Im trying to write this result to fc_in3 using caseID from dct4 in result field. So it should be same.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Concerning what Im doing, I have multiple rows with same caseIDs in fc_in2 as you can see. For example the first two rows have caseID 1 5. So I want to calculate the result for the first row using value and workers (from another table). Then when the cursor moves to the second row which has the same caseID, it should take its value, add to it the value from the previous row (since previous row had the same caseID) and divide this sum with the workers value. So this second row will have a new value in the result field. This is the updated final value for caseID 1 5 and it will be written in dct4 with that caseID as key. If there are more rows with same caseID then this process should continue. Now I just want to write this same value in fc_in3 for the row with caseID 1 5. In fc_in3 there is just one row for each caseID. Thats the difference. Im outside now I can attach the dataset in the evening probably.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 24 Jun 2015 08:18:50 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/what-sorcery-is-this/m-p/372543#M29433</guid>
      <dc:creator>SalmanAhmed</dc:creator>
      <dc:date>2015-06-24T08:18:50Z</dc:date>
    </item>
    <item>
      <title>Re: What sorcery is this?</title>
      <link>https://community.esri.com/t5/python-questions/what-sorcery-is-this/m-p/372544#M29434</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;So effectively if there are 10 rows with same caseID in fc_in2, then the updated result of the 10th row should be written to dct4 for that caseID as key. And I simply want this final result to be also written to fc_in3 for the row with that same caseID by running a last update cursor on fc_in3.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 24 Jun 2015 08:28:34 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/what-sorcery-is-this/m-p/372544#M29434</guid>
      <dc:creator>SalmanAhmed</dc:creator>
      <dc:date>2015-06-24T08:28:34Z</dc:date>
    </item>
    <item>
      <title>Re: What sorcery is this?</title>
      <link>https://community.esri.com/t5/python-questions/what-sorcery-is-this/m-p/372545#M29435</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;By the way fc_in2 is not really a feature class its just a geodatabase table. fc_in3 is a feature class.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 24 Jun 2015 19:46:44 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/what-sorcery-is-this/m-p/372545#M29435</guid>
      <dc:creator>SalmanAhmed</dc:creator>
      <dc:date>2015-06-24T19:46:44Z</dc:date>
    </item>
    <item>
      <title>Re: What sorcery is this?</title>
      <link>https://community.esri.com/t5/python-questions/what-sorcery-is-this/m-p/372546#M29436</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thanks for clarifying, but since the geometry is not used it does not influence the result. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Question: is the result what you expect it to be or does it require changes. If so, could you attach a sample of your data and specify with more detail what you are trying to achieve?&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 24 Jun 2015 19:54:51 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/what-sorcery-is-this/m-p/372546#M29436</guid>
      <dc:creator>XanderBakker</dc:creator>
      <dc:date>2015-06-24T19:54:51Z</dc:date>
    </item>
    <item>
      <title>Re: What sorcery is this?</title>
      <link>https://community.esri.com/t5/python-questions/what-sorcery-is-this/m-p/372547#M29437</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I just realized that in fc_in2 there are more rows with caseID 1 5 further down below. I thought there were just two rows on the very top as seen in the image. That's why I was saying the Result from this second row must be written to fc_in3. But now I see the final updated Result value for rows with caseID 1 5 is in the last row with that caseID (which is further down in the table) and not in the second row. This value is correctly written to fc_in3. I was sorting the table with the GEN field that's why I did not see the rows with caseID 1 5 other than the first two and didn't scroll down to check if there are more. Everything is fine now. The script was correct. And your explanation as well. Thanks alot for your time. I will be careful with the sorting order next time.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 24 Jun 2015 20:17:51 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/what-sorcery-is-this/m-p/372547#M29437</guid>
      <dc:creator>SalmanAhmed</dc:creator>
      <dc:date>2015-06-24T20:17:51Z</dc:date>
    </item>
  </channel>
</rss>

