<?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: Sorting Issue in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/sorting-issue/m-p/1111386#M62793</link>
    <description>&lt;P&gt;Can you elaborate on "it is making features bigger?"&amp;nbsp; And can you give an example?&lt;/P&gt;</description>
    <pubDate>Tue, 26 Oct 2021 18:30:52 GMT</pubDate>
    <dc:creator>JoshuaBixby</dc:creator>
    <dc:date>2021-10-26T18:30:52Z</dc:date>
    <item>
      <title>Sorting Issue</title>
      <link>https://community.esri.com/t5/python-questions/sorting-issue/m-p/1111383#M62792</link>
      <description>&lt;P&gt;I have a shapefile that I am trying to sort a specific field but for some weird reason it changing the shape of the features, . The following does short the field I want but it is making the features bigger. I am not sure why this is happening?&lt;/P&gt;&lt;LI-CODE lang="c"&gt;BPs ="BPs1"
data = []  
with arcpy.da.SearchCursor(BPs,"*") as cursor:  
    for row in cursor:  
        data.append(row)  
         
data.sort(key=lambda tup: tup[21]) # sorts based on the 21st field  
count = 0  
with arcpy.da.UpdateCursor(BPs,"*") as cursor:  
    for row in cursor:  
        row = data[count]  
        count += 1  
        cursor.updateRow(row)&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 26 Oct 2021 18:18:57 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/sorting-issue/m-p/1111383#M62792</guid>
      <dc:creator>TonyAlmeida</dc:creator>
      <dc:date>2021-10-26T18:18:57Z</dc:date>
    </item>
    <item>
      <title>Re: Sorting Issue</title>
      <link>https://community.esri.com/t5/python-questions/sorting-issue/m-p/1111386#M62793</link>
      <description>&lt;P&gt;Can you elaborate on "it is making features bigger?"&amp;nbsp; And can you give an example?&lt;/P&gt;</description>
      <pubDate>Tue, 26 Oct 2021 18:30:52 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/sorting-issue/m-p/1111386#M62793</guid>
      <dc:creator>JoshuaBixby</dc:creator>
      <dc:date>2021-10-26T18:30:52Z</dc:date>
    </item>
    <item>
      <title>Re: Sorting Issue</title>
      <link>https://community.esri.com/t5/python-questions/sorting-issue/m-p/1111390#M62794</link>
      <description>&lt;P&gt;The first image is what the actual feature should be but after I run the sort I post it sorts the features but changes the shape, makes them bigger.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;no&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="2.png" style="width: 290px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/26236i11428740B66C0C09/image-size/large?v=v2&amp;amp;px=999" role="button" title="2.png" alt="2.png" /&gt;&lt;/span&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="1.png" style="width: 191px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/26237i16848A49CD52F499/image-size/large?v=v2&amp;amp;px=999" role="button" title="1.png" alt="1.png" /&gt;&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 26 Oct 2021 18:40:06 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/sorting-issue/m-p/1111390#M62794</guid>
      <dc:creator>TonyAlmeida</dc:creator>
      <dc:date>2021-10-26T18:40:06Z</dc:date>
    </item>
    <item>
      <title>Re: Sorting Issue</title>
      <link>https://community.esri.com/t5/python-questions/sorting-issue/m-p/1111391#M62795</link>
      <description>&lt;P&gt;Did you try&amp;nbsp;&lt;A href="https://pro.arcgis.com/en/pro-app/latest/tool-reference/data-management/sort.htm#GUID-26359B3D-A0C8-4666-B99B-40C8B4D91449" target="_self"&gt;Sort (Data Management)&lt;/A&gt;&amp;nbsp;instead?&lt;/P&gt;</description>
      <pubDate>Tue, 26 Oct 2021 18:40:34 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/sorting-issue/m-p/1111391#M62795</guid>
      <dc:creator>JayantaPoddar</dc:creator>
      <dc:date>2021-10-26T18:40:34Z</dc:date>
    </item>
    <item>
      <title>Re: Sorting Issue</title>
      <link>https://community.esri.com/t5/python-questions/sorting-issue/m-p/1111393#M62796</link>
      <description>&lt;P&gt;I was trying to use the arcpy.da.UpdateCursor because I need to add an increment to the features that are sorted.&lt;/P&gt;</description>
      <pubDate>Tue, 26 Oct 2021 18:42:23 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/sorting-issue/m-p/1111393#M62796</guid>
      <dc:creator>TonyAlmeida</dc:creator>
      <dc:date>2021-10-26T18:42:23Z</dc:date>
    </item>
    <item>
      <title>Re: Sorting Issue</title>
      <link>https://community.esri.com/t5/python-questions/sorting-issue/m-p/1111400#M62798</link>
      <description>&lt;P&gt;I don't know if this would cause your issues but I would recommend specifying the field names (searchcursor and updatecursor docs recommend this) and using SHAPE@ for the geometry because it returns a geometry object which is less likely to get rounded or manipulated.&lt;/P&gt;&lt;P&gt;So above your SearchCursor I would add a line:&lt;/P&gt;&lt;LI-CODE lang="python"&gt;fields = [f.name for f in arcpy.ListFields(BPs)]
fields = fields - ['Shape'] + ['SHAPE@']&lt;/LI-CODE&gt;&lt;P&gt;And then in your SearchCursor and UpdateCursor, pass the fields variable instead of "*"&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 26 Oct 2021 19:05:53 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/sorting-issue/m-p/1111400#M62798</guid>
      <dc:creator>JoshKalovGIS</dc:creator>
      <dc:date>2021-10-26T19:05:53Z</dc:date>
    </item>
    <item>
      <title>Re: Sorting Issue</title>
      <link>https://community.esri.com/t5/python-questions/sorting-issue/m-p/1111447#M62801</link>
      <description>&lt;P&gt;You can also sort within the cursor using the sql clause so you could probably avoid having to create that sort list,&amp;nbsp;&lt;/P&gt;&lt;P&gt;Edited:&amp;nbsp; but it lookes liek you are trying to created a sorted featureclass I'd probably create a new featureclass instead of updating the old.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;with arcpy.da.UpdateCursor(BPs,fields, sql_clause=(None, ' ORDER BY ' + field + ' DESC'), where_clause=(field + ' IS NOT NULL')) as cursor:  
    count=0
    for row in cursor:  
        row[0] = count # or other calc based on what you need.
        count += 1  
        cursor.updateRow(row)&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;or to create the sorted list:&lt;/P&gt;&lt;LI-CODE lang="python"&gt;data = [row for row in with arcpy.da.SearchCursor(BPs,"*", sql_clause=(None, ' ORDER BY ' + field + ' DESC'), where_clause=(field + ' IS NOT NULL'))]&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 26 Oct 2021 21:23:37 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/sorting-issue/m-p/1111447#M62801</guid>
      <dc:creator>Anonymous User</dc:creator>
      <dc:date>2021-10-26T21:23:37Z</dc:date>
    </item>
  </channel>
</rss>

