List feature classes in a geodatabase using Python

33903
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
JoshThompson
New Contributor III
Hey Chris,

I came to the same confusing conclusion. When the feature name contains the dataset name, it kicks it and all other features in that dataset out. Strange...but probably something in my code. The features are stored in a file geodatabase, v10 (sp2). Below is the code I am using:

import arcpy

arcpy.env.workspace = "D:\Lakeland_GIS\GDB\Lakeland\Lakeland.gdb"

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

Thanks,
Josh
0 Kudos
ChrisFox3
Occasional Contributor III
Hi Josh,

I think your code looks fine. Is there anything else in the Cemetary Feature Dataset other than the Cemetary Feature Class? Same with Churches? I think the issue is specific to your geodatabase. Would you be able to send me the GDB or if it is too large try pulling out some of the good and offending feature datasets into a new GDB to send?
0 Kudos
TiCrossman
New Contributor
Was there ever a resolution to this issue?  I have code essentially identical to that in this thread, and I am now experiencing the same problem with ListFeatureClasses leaving out feature classes for particular feature datasets.  I am working with a file geodatabase, v10.0 (no service packs--see note below).  In my case I have one feature dataset that has one of ~30 feature classes whose name contains the name of the feature dataset.  I get no feature classes from that dataset.  The fGDB was just thrown at me to work on, and I don't know the provenence.  I suspect, however, that it was exported from SDE.

Notably, there are other anomalies happening, too:  (1) I get no feature classes from another dataset that has just two feature classes, neither of which contains the name of the feature dataset; and (2) In a couple of other datasets, most of the feature class names end with "_MT" or other "_XX" or "XX" (like "ZM") letter combination.  In those cases the feature classes are listed, but the "_XX" (or "XX") suffix is deleted, leaving just the portion of the name to the left of the suffix.  The only other thing of note is the lack of service packs on my system.  I had SP2 installed, but that service pack introduces a bug (now reported as such by ESRI Support) that breaks a lot of my existing scripts.  I had to uninstall SP2.  Anyone have any further info on this problem.  Chris?  Thanks for the help.
0 Kudos
JoshThompson
New Contributor III
I did confirm that if a feature class had the exact same name as the feature dataset, the features were left out of the list. It would list the feature dataset as it appeared, but no feature classes were shown. I had to either change the name of the dataset or the feature class for the script to work correctly.
RobertBlischke
New Contributor
I just had the same issue. For my workspace I'm using a connection file string. I discovered that my connection file string had a hidden carriage return/line feed at the end. Once I removed the hidden characters, the feature classes started listing.
MeleKoneya
Occasional Contributor III
I am using the IGeoProcessor in .NET and have seen the same behavior.   I am using with ArcGIS 10 SP5.     If a Feature Dataset contains a feature class with the same name,   when I use IGeoProcessor.ListFeatureClasses(),  None of the Feature Classes within the Feature Dataset are returned.   


Was there any resolution to this issue?
MatthewRantala
New Contributor II
I just want to confirm that as of 10.2, this still occurs, at least using a postgresql geodatabase (10.2 ArcGIS, postgres 9.2). I was NOT able to re-create the problem using either a file or personal geodatabase.
curtvprice
MVP Esteemed Contributor
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.


I received a request today on how you would use Calculate Value to create the list.

The key is to to connect the dataset of the iterator into the Collect Values tool, then set the output of that as an output parameter, save and close your model. Make a new model and drop your first model into that one. When you run the model you can see the string using Calculate Value with the expression: r"%Collected values%" - which I think will show a ;-delimited string of paths. If you want to print them, one per row, you can use an expression like : chr(10) + chr(10).join(r"%Collected values%".split(";"))

See the 10.2 help article - scroll down to "Advanced Use of Model Iterators".
http://resources.arcgis.com/en/help/...0000007p000000