Select to view content in your preferred language

Discover if a workspace is a geodatabase or a feature dataset

700
3
Jump to solution
10-24-2012 08:19 PM
CarlBeyerhelm
Frequent Contributor
How can I discover if the os.path.dirname of a feature class is a feature dataset or a geodatabase?  I need to generate a stand-alone frequency table of values from the feature class, but I can only create that stand-alone table at the geodatabase level, not at the feature dataset level.

Thanks...
Tags (2)
0 Kudos
1 Solution

Accepted Solutions
JakeSkinner
Esri Esteemed Contributor
Hi Carl,

If you're iterating through feature classes within a geodatabase, it will only return stand-alone feature classes unless you specify a feature dataset within the arcpy.ListFeatureClasses function.  Ex:  (will only return stand-alon feature classes)

lstFCs = arcpy.ListFeatureClasses("*") for fc in lstFCs:     print fc



If you're not iterating using the arcpy.ListFeatureClasses function, you can use the describe method that Wayne mentioned.  Ex:

dir = os.path.dirname(env.workspace + os.sep + fc) desc = arcpy.Describe(dir) if desc.dataType == "Workspace":     <remaining code>

View solution in original post

0 Kudos
3 Replies
T__WayneWhitley
Honored Contributor
...think you can use Describe for this.  The datasetType property should return a string, FeatureDataset or FeatureClass, etc.

See the sample code here:
http://help.arcgis.com/en/arcgisdesktop/10.0/help/index.html#//000v0000002n000000
0 Kudos
JakeSkinner
Esri Esteemed Contributor
Hi Carl,

If you're iterating through feature classes within a geodatabase, it will only return stand-alone feature classes unless you specify a feature dataset within the arcpy.ListFeatureClasses function.  Ex:  (will only return stand-alon feature classes)

lstFCs = arcpy.ListFeatureClasses("*") for fc in lstFCs:     print fc



If you're not iterating using the arcpy.ListFeatureClasses function, you can use the describe method that Wayne mentioned.  Ex:

dir = os.path.dirname(env.workspace + os.sep + fc) desc = arcpy.Describe(dir) if desc.dataType == "Workspace":     <remaining code>
0 Kudos
CarlBeyerhelm
Frequent Contributor
OK, another rookie mistake on my part.

I'd been using the datasetType property without success, but the dataType property of os.path.dirname(feature class) distinguishes between a Folder, a Geodatabase, and a Feature dataset...which is what I needed.

Thanks to Wayne and Jake for nudging my pea-brain in the right direction...
0 Kudos