<?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: Creating multiple fields with ranks using arcpy in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/creating-multiple-fields-with-ranks-using-arcpy/m-p/544538#M42465</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;What type of data are you working with? That is a very long feature class name, and I tend to avoid dashes in my feature class names because it has caused me problems in the past.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;If you are using a file geodatabase doesn't your workspace variable need to have the .gdb extension?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE __default_attr="python" __jive_macro_name="code" class="_jivemacro_uid_14303343925943173 jive_macro_code jive_text_macro" data-renderedposition="113_8_913_16" jivemacro_uid="_14303343925943173"&gt;&lt;P&gt;arcpy.env.workspace = &lt;SPAN class="string"&gt;"D:/M1 Geomatique/Programmation II/Dossier.gdb"&amp;nbsp; &lt;/SPAN&gt;&lt;/P&gt;&lt;/PRE&gt;&lt;P&gt;&lt;SPAN class="string"&gt; &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;Or if you are working with a shapefile you are missing the .shp extension in your fc variable and the field name is probably too long.&lt;SPAN class="string"&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Wed, 29 Apr 2015 19:08:43 GMT</pubDate>
    <dc:creator>JeffWard</dc:creator>
    <dc:date>2015-04-29T19:08:43Z</dc:date>
    <item>
      <title>Creating multiple fields with ranks using arcpy</title>
      <link>https://community.esri.com/t5/python-questions/creating-multiple-fields-with-ranks-using-arcpy/m-p/544533#M42460</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;&lt;SPAN style="text-decoration: line-through;"&gt;I have a field named "arrondissement" (district), which contains as attributes integers from 1 to 20. My task is to create a column for each arrondissement with the ranks (short integers) relative to the shape area for the connecting areas to voting stations of the same district.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I hope it makes sense, not really sure how to do it to be honest I'm lost at the moment. Besides adding a field, perhaps multiple ones with a loop by using ListFields and AddField, I don't really know what else to do.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;EDIT:&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;While figuring out what I have to do, practically creating a field for each arrondise, and in each, rank each FID (which are part of the respective arrondise) by the size of its shape area.&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"

fc = "zones_rattachement.shp"

try:
&amp;nbsp;&amp;nbsp;&amp;nbsp; fieldRoot = "RANG_R"
&amp;nbsp;&amp;nbsp;&amp;nbsp; for counter in range(1,21):
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.AddField_management(fc, fieldRoot + str(counter),'SHORT')

&amp;nbsp;&amp;nbsp;&amp;nbsp; 
&amp;nbsp;&amp;nbsp;&amp;nbsp; size_rank = 1
&amp;nbsp;&amp;nbsp;&amp;nbsp; numlist = list(range(1,21))
&amp;nbsp;&amp;nbsp;&amp;nbsp; for num in numlist:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.SelectLayerByAttribute_management(fc, "NEW_SELECTION", "arrondisse = '%c'")
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; rows = arcpy.UpdateCursor(fc, sort_fields="shape_area D")
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; for row in rows:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; row.setValue("RANG_R1", size_rank)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&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;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; rows.updateRow(row)

&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 
except:
&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.GetMessages()&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Message was edited by: Florin-Daniel Cioloboc&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Message was edited by: Florin-Daniel Cioloboc&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 23:33:34 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/creating-multiple-fields-with-ranks-using-arcpy/m-p/544533#M42460</guid>
      <dc:creator>deleted-user-3rTxRfVTcNm-</dc:creator>
      <dc:date>2021-12-11T23:33:34Z</dc:date>
    </item>
    <item>
      <title>Re: Creating multiple fields with ranks using arcpy</title>
      <link>https://community.esri.com/t5/python-questions/creating-multiple-fields-with-ranks-using-arcpy/m-p/544534#M42461</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;How about&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;import arcpy

fc = 'yourFeatureClass' #insert your feature class here
fieldRoot = 'RANK' #root name of the field
for counter in range(1,20):
&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.AddField_management(fc, fieldRoot + str(counter), 'LONG')&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 23:33:37 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/creating-multiple-fields-with-ranks-using-arcpy/m-p/544534#M42461</guid>
      <dc:creator>JeffWard</dc:creator>
      <dc:date>2021-12-11T23:33:37Z</dc:date>
    </item>
    <item>
      <title>Re: Creating multiple fields with ranks using arcpy</title>
      <link>https://community.esri.com/t5/python-questions/creating-multiple-fields-with-ranks-using-arcpy/m-p/544535#M42462</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;&lt;A href="https://arcpy.wordpress.com/2013/08/02/ranking-field-values/" title="https://arcpy.wordpress.com/2013/08/02/ranking-field-values/"&gt;Ranking field values | ArcPy Café&lt;/A&gt; &lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 29 Apr 2015 15:42:09 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/creating-multiple-fields-with-ranks-using-arcpy/m-p/544535#M42462</guid>
      <dc:creator>JamesCrandall</dc:creator>
      <dc:date>2015-04-29T15:42:09Z</dc:date>
    </item>
    <item>
      <title>Re: Creating multiple fields with ranks using arcpy</title>
      <link>https://community.esri.com/t5/python-questions/creating-multiple-fields-with-ranks-using-arcpy/m-p/544536#M42463</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;From what I can read, it should create 20 columns with a different name, not sure why in my case it's not working.&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"

fc = "zones-de-rattachement-des-bureaux-de-vote-en-2014"

try:
&amp;nbsp;&amp;nbsp;&amp;nbsp; fieldRoot = "RANG_RAPPORT"
&amp;nbsp;&amp;nbsp;&amp;nbsp; for counter in range(1,20):
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.AddField_management(fc, fieldRoot + str(counter),'LONG')

except:
&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.GetMessages()&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 23:33:40 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/creating-multiple-fields-with-ranks-using-arcpy/m-p/544536#M42463</guid>
      <dc:creator>deleted-user-3rTxRfVTcNm-</dc:creator>
      <dc:date>2021-12-11T23:33:40Z</dc:date>
    </item>
    <item>
      <title>Re: Creating multiple fields with ranks using arcpy</title>
      <link>https://community.esri.com/t5/python-questions/creating-multiple-fields-with-ranks-using-arcpy/m-p/544537#M42464</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Interesting solution, I think I ran into it yesterday but if:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;BLOCKQUOTE&gt;&lt;TABLE border="1"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;&lt;EM&gt;Note: dBase (and shapefiles) does not support ORDER BY as used above by &lt;A href="http://resources.arcgis.com/en/help/main/10.2/index.html#//018w00000014000000"&gt;arcpy.da.UpdateCursor’s&lt;/A&gt; sql_clause argument.&lt;/EM&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;is it possible, how to go around it, what can substitute the SQL clause? I guess, sorted() would work?&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 29 Apr 2015 18:34:34 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/creating-multiple-fields-with-ranks-using-arcpy/m-p/544537#M42464</guid>
      <dc:creator>deleted-user-3rTxRfVTcNm-</dc:creator>
      <dc:date>2015-04-29T18:34:34Z</dc:date>
    </item>
    <item>
      <title>Re: Creating multiple fields with ranks using arcpy</title>
      <link>https://community.esri.com/t5/python-questions/creating-multiple-fields-with-ranks-using-arcpy/m-p/544538#M42465</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;What type of data are you working with? That is a very long feature class name, and I tend to avoid dashes in my feature class names because it has caused me problems in the past.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;If you are using a file geodatabase doesn't your workspace variable need to have the .gdb extension?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE __default_attr="python" __jive_macro_name="code" class="_jivemacro_uid_14303343925943173 jive_macro_code jive_text_macro" data-renderedposition="113_8_913_16" jivemacro_uid="_14303343925943173"&gt;&lt;P&gt;arcpy.env.workspace = &lt;SPAN class="string"&gt;"D:/M1 Geomatique/Programmation II/Dossier.gdb"&amp;nbsp; &lt;/SPAN&gt;&lt;/P&gt;&lt;/PRE&gt;&lt;P&gt;&lt;SPAN class="string"&gt; &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;Or if you are working with a shapefile you are missing the .shp extension in your fc variable and the field name is probably too long.&lt;SPAN class="string"&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 29 Apr 2015 19:08:43 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/creating-multiple-fields-with-ranks-using-arcpy/m-p/544538#M42465</guid>
      <dc:creator>JeffWard</dc:creator>
      <dc:date>2015-04-29T19:08:43Z</dc:date>
    </item>
    <item>
      <title>Re: Creating multiple fields with ranks using arcpy</title>
      <link>https://community.esri.com/t5/python-questions/creating-multiple-fields-with-ranks-using-arcpy/m-p/544539#M42466</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I'm working with a shapefile, not with a geodatabase, in that case, I omitted the .shp extension.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 29 Apr 2015 21:02:14 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/creating-multiple-fields-with-ranks-using-arcpy/m-p/544539#M42466</guid>
      <dc:creator>deleted-user-3rTxRfVTcNm-</dc:creator>
      <dc:date>2015-04-29T21:02:14Z</dc:date>
    </item>
    <item>
      <title>Re: Creating multiple fields with ranks using arcpy</title>
      <link>https://community.esri.com/t5/python-questions/creating-multiple-fields-with-ranks-using-arcpy/m-p/544540#M42467</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Then you will need to add .shp to the end of your feature class name.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;fc = &lt;SPAN class="string"&gt;"zones-de-rattachement-des-bureaux-de-vote-en-2014.shp"&amp;nbsp; 
&lt;/SPAN&gt;&lt;/PRE&gt;&lt;P&gt;&lt;SPAN class="string"&gt; &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN class="string"&gt;Also, your field name is too long, they need to be 10 or fewer.&amp;nbsp; Since you are going to be tacking on up to two characters to the end, you will need to have a field name 8 characters or fewer.&lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 23:33:42 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/creating-multiple-fields-with-ranks-using-arcpy/m-p/544540#M42467</guid>
      <dc:creator>JeffWard</dc:creator>
      <dc:date>2021-12-11T23:33:42Z</dc:date>
    </item>
    <item>
      <title>Re: Creating multiple fields with ranks using arcpy</title>
      <link>https://community.esri.com/t5/python-questions/creating-multiple-fields-with-ranks-using-arcpy/m-p/544541#M42468</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Done, it worked, now I have a script that actually creates 20 fields. I've also modified the name of .shp, as it was just too long.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 30 Apr 2015 06:36:18 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/creating-multiple-fields-with-ranks-using-arcpy/m-p/544541#M42468</guid>
      <dc:creator>deleted-user-3rTxRfVTcNm-</dc:creator>
      <dc:date>2015-04-30T06:36:18Z</dc:date>
    </item>
    <item>
      <title>Re: Creating multiple fields with ranks using arcpy</title>
      <link>https://community.esri.com/t5/python-questions/creating-multiple-fields-with-ranks-using-arcpy/m-p/544542#M42469</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Trying to rank rows which are part of a certain arrondise, in terms of size of shape_area. To increase visibility I updated the first post.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 30 Apr 2015 07:14:02 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/creating-multiple-fields-with-ranks-using-arcpy/m-p/544542#M42469</guid>
      <dc:creator>deleted-user-3rTxRfVTcNm-</dc:creator>
      <dc:date>2015-04-30T07:14:02Z</dc:date>
    </item>
    <item>
      <title>Re: Creating multiple fields with ranks using arcpy</title>
      <link>https://community.esri.com/t5/python-questions/creating-multiple-fields-with-ranks-using-arcpy/m-p/544543#M42470</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Then don't use shapefiles.&amp;nbsp; It's pretty simple to migrate your data to a File Geodatabase, a scratch workspace, or I'd even consider just adding the source data you intend to process to in_memory feature class if possible.&amp;nbsp; You won't have to deal with shapefile limitations.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 30 Apr 2015 14:23:04 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/creating-multiple-fields-with-ranks-using-arcpy/m-p/544543#M42470</guid>
      <dc:creator>JamesCrandall</dc:creator>
      <dc:date>2015-04-30T14:23:04Z</dc:date>
    </item>
  </channel>
</rss>

