Returning feature dataset name for a feature class

5853
5
03-30-2014 10:40 AM
WesKing
New Contributor
Python noob here wondering if there's a direct way to return the name of a feature dataset for a feature class.

I know I can return the data source and extract the dataset name, but I figure there's got to be a way to directly return only the dataset name.

Along the same line, is there a way to check if a feature class belongs to a feature dataset?

Thanks in advance for any help.
Wes
Tags (2)
0 Kudos
5 Replies
benberman
Occasional Contributor
Python noob here wondering if there's a direct way to return the name of a feature dataset for a feature class.

I know I can return the data source and extract the dataset name, but I figure there's got to be a way to directly return only the dataset name.

Along the same line, is there a way to check if a feature class belongs to a feature dataset?

Thanks in advance for any help.
Wes


arcpy.env.workspace= "your workspace"
lstdataset = arcpy.ListDatasets()
for item in lstdataset:
     print item
     lstfeatureclass=arcpy.ListFeatureClasses()
     for fc in lstfeatureclass:
          print fc


you can plug in writers and other syntax to present it as a report. Hope this helps.
0 Kudos
WesKing
New Contributor
Thanks FLBB,
I looked into using list datasets/feature classes functions and they would work with some manipulation, which I know is normal.  I was just hoping there was something like a describe function that would return the exact feature dataset name (if it existed) for the feature class.

I appreciate your reply.

Wes
0 Kudos
benberman
Occasional Contributor
Thanks FLBB,
I looked into using list datasets/feature classes functions and they would work with some manipulation, which I know is normal.  I was just hoping there was something like a describe function that would return the exact feature dataset name (if it existed) for the feature class.

I appreciate your reply.

Wes


I guess I didnt understand your question clearly. Yes we have that available as well.

desc=arcpy.Describe(workspace)

print desc.datasetType

hope this helps
0 Kudos
benberman
Occasional Contributor
you could also do this...

for dirpath,dirnames,filenames in arcpy.da.Walk(workspace to dataset):
...     print filenames
0 Kudos
T__WayneWhitley
Frequent Contributor
That's not going to work.  The question clearly states the feature dataset name of a feature class is desired.  Since that should be in the pathname or 'catalogPath', Curtis Price posted in May 2011 a function to return it (if the fc is indeed part of a feature dataset)--

http://forums.arcgis.com/threads/31513-Test-if-SDE-feature-class-is-part-of-a-feature-dataset#3

Pretty straightforward, arcpy.describe(FC).catalogPath returns that path that includes the feature dataset as the 2nd to last pathname component, if it exists....the existence is checked by using dirname to return the path without the basename, then tested for dataType.......if FeatureDataset the name is returned.  Clever Curtis!

import arcpy, os

def GetFDS(FC):
  """ Returns the feature dataset for a feature class
  or feature layer FC.

  If the feature class is not within a feature dataset,
  returns None."""
  # get the path to the feature class
  fcPath = arcpy.describe(FC).catalogPath
  # get the path to its container
  fcHome = os.path.dirname(fcPath)
  # is it a feature dataset??
  if arcpy.describe(fcHome).dataType == "FeatureDataset":
    return fcHome
  else:
    return None



@FLBB:  The complete 'walk' approach is here:
https://arcpy.wordpress.com/tag/listfeatureclasses/