List feature classes in a geodatabase using Python

33922
18
05-25-2011 12:43 PM
JoshThompson
New Contributor III
I am attempting to generate a list of all the feature classes in a file geodatabase using the Python window in ArcCatalog. I want to list all features, by feature dataset, to deliver to the staff at my office. Is this even possible? I am running ArcInfo 10 and not well versed with Python. I have failed miserably in my feeble attempts to generate the list on my own. Any help is greatly appreciated.

Thanks,
Josh
Tags (2)
18 Replies
AnthonyFarndon
Occasional Contributor
I think this is what you are asking for?


datasetList = arcpy.ListDatasets("*", "Feature")
for dataset in datasetList:
    print dataset
    fcList = arcpy.ListFeatureClasses("*","",dataset)
    for fc in fcList:
        print fc

Remember to set env workspace
JoshThompson
New Contributor III
Thanks for the quick response. I've been out of the office for a week, so my apologies for the delayed response. The script worked fine, so thanks for that. I do have one question, though. It generated a list in random order, not in alphabetical order as they are shown in the geodatabase. Do you know why this happens?

Thanks again for your help,
Josh
ChrisFox3
Occasional Contributor III
Hi Josh,

This is the order in which they are stored in the database, what you see in ArcCatalog has been sorted alphabetically to assist you in finding the proper feature class.

If you wish to display the list of feature classes alphabetically in Python just call the sort method on the list of feature classes

datasetList = arcpy.ListDatasets("*", "Feature")
for dataset in datasetList:
    print dataset
    fcList = arcpy.ListFeatureClasses("*","",dataset)
    fcList.sort()
    for fc in fcList:
        print fc
JoshThompson
New Contributor III
Okay, we are making progress. Thanks so much for your help. I now have a new problem: Within the list, some of the feature classes are not included. All the feature datasets are included, but randomly, the feature classes will be missing from the dataset. I am one tier below beginner when it comes to Python, so any help is greatly appreciated.

Thanks,
Josh
0 Kudos
ChrisFox3
Occasional Contributor III
Josh,

Is it truly random or if you run it on the same feature dataset every time are the same feature classes printed or ormitted each time? Could you send an example of what is printed and what actually exists in the geodatabase? Initially I am guessing that for example you have a topology in the feature dataset and this is printed, which is expected. ListFeatureClasses() will not return topologies. There are other data types that will not be returned as well. So you should look closely at what data types are not actually being returned in python.
curtvprice
MVP Esteemed Contributor
I want to list all features, by feature dataset, to deliver to the staff at my office.


Since you're not well-versed with Python, you may want to look into ModelBuilder 10. I never used to suggest this, but have been very impressed with the new iterator functionality.

To generate a list of anything (even recursively in a folder tree) in model builder right-click, choose Iterators and what you want to list. Then double click it and enter the particulars (ie where you want to look), and then pipe the pathname output into the Collect Values tool and run it.  This easily generates a list of with no coding; you could use Calculate Value to convert it to a string to paste into a text file or whatever.
JoshThompson
New Contributor III
Chris,

I do have some topologies included in the geodatabase, however, I do not want them to print, so that is actually a positive outcome. I am referring specifically to feature classes that are not being listed. I have included an excel file with the geodatabase contents compared to the outcome of the fcList, with some formatting to easily compare results. Thanks for the help.

Josh
JoshThompson
New Contributor III
Curtis,

Someone else actually mentioned this as a way to get familiar with Python. I think after this exercise, I will certainly try that. Thanks for your reply.

Josh
0 Kudos
ChrisFox3
Occasional Contributor III
Josh,

From your spreadsheet it looks like anytime there is a feature class that shares the same name as the feature dataset it is in, that no feature classes are returned from listfeatureclasses(). I have attempted to test the same scenario with some of my data, but couldn't reproduce the issue.

Could you share your complete code? What kind of geodatabase are these feature classes stored in and do you know what version the geodabatase is?