2

Can anybody anyone point me to directions on how to convert file geodatabase feature class names to lower case by using Python?

  • So you'd like the geodatabases themselves renamed? (As opposed to just getting a list of them in lower case.) – Erica Dec 6 '13 at 14:43
  • I'd like to rename the actual feature classes inside the geodatabase. So for example a polygon called "awesome_DOG_PARK" would be renamed to "awesome_dog_park" – zarbo Dec 6 '13 at 14:49
  • Right, of course -- I read that and then typed something else. Sorry. – Erica Dec 6 '13 at 15:05
7

Using a combination of string manipulation and renaming the feature classes using arcpy.Rename_management works, sort of.

There's an odd problem with doing this directly. Since your output and input names are technically the same in ArcMap's opinion (this is apparently one of its operations that's case insensitive), it will complain if you just convert them directly.

fcList = arcpy.ListFeatureClasses()
for fcName in fcList:
    fcLCName = fcName.lower()
    arcpy.Rename_management(fcName, fcLCName, 'FeatureClass')

However, you can work around this by renaming to a dummy variable first, and then converting that to the actual lowercase name...

    arcpy.Rename_management(fcName, 'TEMPNAME', 'FeatureClass')
    arcpy.Rename_management('TEMPNAME', fcLCName, 'FeatureClass')
  • Note that this method will overwrite the original feature class name; if you're worried about this for any reason, then Jason's answer is a better choice :) – Erica Dec 6 '13 at 15:09
  • 1
    I have done this except just add something like "_temp" to the end of the existing name for the first step. That way if there is an error you can still locate the proper feature class later with out wondering what it was called, especially if you are renaming a bunch of layers in batch. – Lemur Dec 6 '13 at 15:18
  • Thanks Erica! That is just what I was looking for. I got stuck on the case insesitive problem. – zarbo Dec 6 '13 at 15:59
3

You could do this by copying each featureclass with a new name, though this could take some time if there are many or if they are large datasets. This may not be the most elegant solution, but it should work:

import arcpy,os
arcpy.env.workspace = r'c:\geodatabase.gdb'
arcpy.CreateFileGDB_management(r'c:','geodatabase_lowercase.gdb')
for fc in arcpy.ListFeatureClasses('*'): arcpy.CopyFeatures_management(fc,os.path.join(r'c:\geodatabase_lowercase.gdb',fc.lower()))

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.