<?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: Ranking values by shape area using ArcPy in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/ranking-values-by-shape-area-using-arcpy/m-p/524907#M41141</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;So far, I've done some corrections to it but still not working, not even creation of a new field which I find it odd.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;import arcpy

arcpy.env.workspace = "D:/M1 Geomatique/Programmation II/Dossier"

try:
&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.AddField_management("zones-de-rattachement-des-bureaux-de-vote-en-2014", "RANG", "INT")
&amp;nbsp;&amp;nbsp;&amp;nbsp; size_rank = 1
&amp;nbsp;&amp;nbsp;&amp;nbsp; rows = arcpy.UpdateCursor(fc, sort_fields="shape_area D")
&amp;nbsp;&amp;nbsp;&amp;nbsp; for row in rows:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; row.setValue("RANG", size_rank)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; size_rank += 1
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; rows.updateRow(row)

except:
&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.GetMessages()&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Sat, 11 Dec 2021 22:53:12 GMT</pubDate>
    <dc:creator>deleted-user-3rTxRfVTcNm-</dc:creator>
    <dc:date>2021-12-11T22:53:12Z</dc:date>
    <item>
      <title>Ranking values by shape area using ArcPy</title>
      <link>https://community.esri.com/t5/python-questions/ranking-values-by-shape-area-using-arcpy/m-p/524906#M41140</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I'm trying to make a script that performs the following: it creates a new field that will hold values based on size of the shape area (from 1 to end of table), basically ranking them.&lt;/P&gt;&lt;P&gt;I have a few ideas to do it, and managed to write a script, however it is not working, no errors, nothing.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;import arcpy

fc = "D:/M1 Geomatique/Programmation II/Dossier/zones-de-rattachement-des-bureaux-de-vote-en-2014.shp"

try:
&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.AddField_management(fc, "RANG", "INT")
&amp;nbsp;&amp;nbsp;&amp;nbsp; size_rank = 1
&amp;nbsp;&amp;nbsp;&amp;nbsp; rows = arcpy.UpdateCursor(fc, ["shape_area"], "D")
&amp;nbsp;&amp;nbsp;&amp;nbsp; for row in rows:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; row.setValue("RANG", size_rank)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; pop_rank += 1
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; rows.updateRow(row)

except:
&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.GetMessages()&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Another idea would be to somehow adapt &lt;A href="https://arcpy.wordpress.com/2013/08/02/ranking-field-values/" rel="nofollow noopener noreferrer" target="_blank"&gt;this code&lt;/A&gt;, but in any case it is mentioned that shapefiles do not support ORDER BY as used above by arcpy.da.UpdateCursor’s sql_clause argument.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;One other idea, to use a list (ListFeatureClasses probably) to get all values, sort them by size, make a loop that takes each value and places a number based on their size. This one seems a bit complicated and I don't have a clear image on how to get through with it.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;What would you recommend me to do?&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 22:53:10 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/ranking-values-by-shape-area-using-arcpy/m-p/524906#M41140</guid>
      <dc:creator>deleted-user-3rTxRfVTcNm-</dc:creator>
      <dc:date>2021-12-11T22:53:10Z</dc:date>
    </item>
    <item>
      <title>Re: Ranking values by shape area using ArcPy</title>
      <link>https://community.esri.com/t5/python-questions/ranking-values-by-shape-area-using-arcpy/m-p/524907#M41141</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;So far, I've done some corrections to it but still not working, not even creation of a new field which I find it odd.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;import arcpy

arcpy.env.workspace = "D:/M1 Geomatique/Programmation II/Dossier"

try:
&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.AddField_management("zones-de-rattachement-des-bureaux-de-vote-en-2014", "RANG", "INT")
&amp;nbsp;&amp;nbsp;&amp;nbsp; size_rank = 1
&amp;nbsp;&amp;nbsp;&amp;nbsp; rows = arcpy.UpdateCursor(fc, sort_fields="shape_area D")
&amp;nbsp;&amp;nbsp;&amp;nbsp; for row in rows:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; row.setValue("RANG", size_rank)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; size_rank += 1
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; rows.updateRow(row)

except:
&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.GetMessages()&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 22:53:12 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/ranking-values-by-shape-area-using-arcpy/m-p/524907#M41141</guid>
      <dc:creator>deleted-user-3rTxRfVTcNm-</dc:creator>
      <dc:date>2021-12-11T22:53:12Z</dc:date>
    </item>
    <item>
      <title>Re: Ranking values by shape area using ArcPy</title>
      <link>https://community.esri.com/t5/python-questions/ranking-values-by-shape-area-using-arcpy/m-p/524908#M41142</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Problem solved.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;"INT" isn't a proper value for AddField, and then again fc shouldn't be there anymore after my last modification.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 29 Apr 2015 08:15:22 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/ranking-values-by-shape-area-using-arcpy/m-p/524908#M41142</guid>
      <dc:creator>deleted-user-3rTxRfVTcNm-</dc:creator>
      <dc:date>2015-04-29T08:15:22Z</dc:date>
    </item>
  </channel>
</rss>

