Hi All.. So here is what I'm trying to do. I know how to calculate Unique ID's. What I'm trying to do is calculate them based the the sort of the table. My data was randomly selected and on this field the table has been sorted. I want to then calculate the Unique ID's based on this sort. So my first record will get a 1 and so on. What currently happens is the unique ID is created based on the object ID or FID not sure which causing my sort on my field to be invalid. Is there a way to force the Unique ID to calculate based on the table sort? Thanks
-Jeremy
rank fields in
https://community.esri.com/docs/DOC-14928-free-tools-for-arcgis-pro-table-tools
Because I actually used his. I Yours most likely works as well I just don't have experience with coding and modifying it. If I could mark them both as correct I would have.
Just out of courtesy, how about you mark Dan's reply as the answer.
Thanks for the reply Joe!
Thanks Dan I was able to use your tools and do what I needed to do.
See if this approach works for you. In the example below, I use the arcpy.da.UpdateCursor with a sql clause to ORDER By (sort) by PARCEL which is a text field:
<SPAN class="keyword token">import</SPAN> arcpy fc <SPAN class="operator token">=</SPAN> r<SPAN class="string token">'C:\Temp\Junk.gdb\points'</SPAN> id <SPAN class="operator token">=</SPAN> <SPAN class="number token">0</SPAN> <SPAN class="keyword token">with</SPAN> arcpy<SPAN class="punctuation token">.</SPAN>da<SPAN class="punctuation token">.</SPAN>UpdateCursor<SPAN class="punctuation token">(</SPAN>fc<SPAN class="punctuation token">,</SPAN><SPAN class="string token">'SortID'</SPAN><SPAN class="punctuation token">,</SPAN> sql_clause<SPAN class="operator token">=</SPAN><SPAN class="punctuation token">(</SPAN>None<SPAN class="punctuation token">,</SPAN> <SPAN class="string token">'ORDER BY PARCEL'</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">)</SPAN> <SPAN class="keyword token">as</SPAN> cursor<SPAN class="punctuation token">:</SPAN> <SPAN class="keyword token">for</SPAN> row <SPAN class="keyword token">in</SPAN> cursor<SPAN class="punctuation token">:</SPAN> id<SPAN class="operator token">+=</SPAN><SPAN class="number token">1</SPAN> row<SPAN class="punctuation token">[</SPAN><SPAN class="number token">0</SPAN><SPAN class="punctuation token">]</SPAN> <SPAN class="operator token">=</SPAN> id cursor<SPAN class="punctuation token">.</SPAN>updateRow<SPAN class="punctuation token">(</SPAN>row<SPAN class="punctuation token">)</SPAN><SPAN class="line-numbers-rows"><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN></SPAN>
Here is a screen capture of my results:
Les membres connectés peuvent publier, suivre les mises à jour, et plus encore. Nouveau ici ? Inscrivez-vous gratuitement.
Find useful guides, FAQs, and documents to help you navigate and make the most of Esri Community.