[GIS] Determining feature dataset of feature class using ArcPy

arcpyfeature-classfeature-datasetfile-geodatabase

Is there a way to check if a feature class full path string is a path to a feature class within a file geodatabase feature dataset in arcpy?

For example:

C:\test\test.gdb\testdataset\featureclass

I'd like to return testdataset.

I can't find it in any of the applicable Describe objects. I can do it with string manipulation…

fullpath = r"C:\test\test.gdb\testdataset\featureclass"
pathlen = len(fullpath.split (".gdb")[0]) + 4
namelen = len(fullpath.split ("\\")[-1])
dataset = fullpath[pathlen:-namelen].replace ("\\", "")

This seems like too much code though.

Is there a better way?

Best Answer

Maybe this:

>>> #testfc is a fc within a fd, as shown with this catalogPath statement:
>>> desc = arcpy.Describe('testfc')
>>> desc.catalogPath
    u'C:\\Users\\whitley-wayne\\Desktop\\data.gdb\\dataset1\\testfc'
>>>
>>> #this shows how to essentially use the Describe method twice to get the fd name:
>>> desc = arcpy.Describe(fc)
>>> if hasattr(desc, 'path'):
...     descPth = arcpy.Describe(desc.path)
...     if hasattr(descPth, 'dataType'):
...         if descPth.dataType == 'FeatureDataset': 
...             print 'the feature dataset name: {0}'.format(descPth.name)
...             
    the feature dataset name: dataset1
>>> 
Related Question