2

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

nmtoken
13.6k5 gold badges39 silver badges91 bronze badges
asked Dec 6, 2013 at 14:29
3
  • So you'd like the geodatabases themselves renamed? (As opposed to just getting a list of them in lower case.) 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" Commented Dec 6, 2013 at 14:49
  • Right, of course -- I read that and then typed something else. Sorry. 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')
answered Dec 6, 2013 at 15:05
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 :) 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. 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. 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()))
answered Dec 6, 2013 at 15:02

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.