Getting Access to Feature Classes in File GDB without a Dataset?

1835
4
Jump to solution
05-07-2013 05:04 AM
JohnStephens
Occasional Contributor
I've got a script that works with many different forms of File GDBs.  Sometimes they have datasets and sometimes they dont.  For the ones that have datasets, I have the working code:

C# IWorkspaceFactory wsFact = new FileGDBWorkspaceFactoryClass(); IWorkspace ws = wsFact.OpenFromFile(database, 0); IEnumDataset enumDS = ws.get_Datasets(esriDatasetType.esriDTFeatureDataset); IFeatureDataset ds = (IFeatureDataset)enumDS.Next(); IEnumDataset enumFC = ds.Subsets; IDataset currFC = enumFC.Next(); FeatureClass fc = (FeatureClass)currFC;


But, when the database doesn't have a dataset and it hits the 5th line it throws an error since enumDS.Next() is null.  I've tried to chance the esriDatasetType to esriDTFeatureClass, but that doesn't work.  I've also tried using the GeoProcessor (which I would prefer not to), but the ListFeatureClasses returns a blank string.

I'm sure this has a simple solution, but I just cannot find it.
0 Kudos
1 Solution

Accepted Solutions
NeilClemmons
Regular Contributor III
There are two types of feature classes in a geodatabase - stand-alone and those that belong to feature datasets.  To access them, use the IWorkspace.Datasets method.  You'll have to call it twice - once for datasets and once for stand-alone feature classes.  For the datasets, pass in esriDTFeatureDataset.  It will return an enumeration of the feature datasets that you will need to loop through.  For each dataset, use the Subsets method to return an enumeration of the feature classes it contains.  You'll need to loop through this enumeration to access each feature class.  For the stand-alone feature classes, pass in esriDTFeatureClass.  This will return an enumeration of feature class objects that you will need to loop through.

View solution in original post

0 Kudos
4 Replies
NeilClemmons
Regular Contributor III
If you're trying to open a specific feature class then call the IFeatureWorkspace.OpenFeatureClass method.
0 Kudos
JohnStephens
Occasional Contributor
If you're trying to open a specific feature class then call the IFeatureWorkspace.OpenFeatureClass method.


Hey Neil,

I'm actually trying to get access to something like an enumeration of the Feature Classes, because I need data from all of them.  I'm not sure that's possible with IFeatureWorkspace.

Thanks
0 Kudos
NeilClemmons
Regular Contributor III
There are two types of feature classes in a geodatabase - stand-alone and those that belong to feature datasets.  To access them, use the IWorkspace.Datasets method.  You'll have to call it twice - once for datasets and once for stand-alone feature classes.  For the datasets, pass in esriDTFeatureDataset.  It will return an enumeration of the feature datasets that you will need to loop through.  For each dataset, use the Subsets method to return an enumeration of the feature classes it contains.  You'll need to loop through this enumeration to access each feature class.  For the stand-alone feature classes, pass in esriDTFeatureClass.  This will return an enumeration of feature class objects that you will need to loop through.
0 Kudos
JohnStephens
Occasional Contributor
For the stand-alone feature classes, pass in esriDTFeatureClass.  This will return an enumeration of feature class objects that you will need to loop through.


Thanks Neil.  I had tried that before, but when it threw the initial exception I didn't dig into it at all, thinking the avenue was a bust.  Since you said it was the way to go, I dug into it and using the esriDTFeatureClass works.
0 Kudos