2

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

3
  • So you'd like the geodatabases themselves renamed? (As opposed to just getting a list of them in lower case.)
    – Erica
    Commented Dec 6, 2013 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
    Commented Dec 6, 2013 at 14:49
  • Right, of course -- I read that and then typed something else. Sorry.
    – Erica
    Commented Dec 6, 2013 at 15:05

2 Answers 2

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')
3
  • 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
    Commented Dec 6, 2013 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
    Commented Dec 6, 2013 at 15:18
  • Thanks Erica! That is just what I was looking for. I got stuck on the case insesitive problem.
    – zarbo
    Commented Dec 6, 2013 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 and acknowledge you have read our privacy policy.

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