I have been trying to figure out how to change the sorting order for a file geodatabase for ArcGIS. I have been using Python and Arcpy to convert many CAD files into a File Geodatabase Feature Dataset. I succeeded in doing this, but the results are reported in lexicographic order, I understand it correctly. That is it is sorted as such:
1, 10, 12, 2, 20, 200, 3, 33, 34, etc.
While this is is a sensible reading style, I have been looking to get it into a 'natural / human' order. I have done plenty of research on this concept, and found the code that makes this happen.
How to sort alpha numeric set in python
Sorting alphanumeric strings in Python
So now the issue is reordering all of my feature datasets in 'natural order.'
This is the code that allows me to print the datasets in order, but it does not actually edit the geodatabase in mind.
import re, arcpy
arcpy.env.workspace = r"<input geodatabase location>"
datasets = arcpy.ListDatasets()
# Natural sort through input
def sorted_nicely(l):
""" Sort the given iterable in the way that humans expect."""
convert = lambda text: int(text) if text.isdigit() else text
alphanum_key = lambda key: [ convert(c) for c in re.split('([0-9]+)', key) ]
return sorted(l, key = alphanum_key)
# Iterate through listed datasets
for x in sorted_nicely(datasets):
print(x)
This piece of code, of which the difficult sorting script was used from the above sources, sorts and prints the desired result in my IDE, but it does not actually do anything to my file geodatabase.
I would like to do this without using any modules that are not pre-installed since that would require me to get permissions for further downloads (i.e. further complication).
Thanks!