Getting feature classes in feature dataset

2770
5
Jump to solution
06-25-2020 05:36 PM
AlexZlotin1
New Contributor III

Given a geodatabase and a feature dataset name, what is the proper way to get the names of all feature classes contained in the feature dataset? I can get the list of FeatureClassDefinitions of all feature classes in the geodatabase, open each feature class, call GetFeatureDataset method and see if the feature dataset name of the feature class  matches the input feature dataset name. This looks like a very costly operation though. Thanks.  

0 Kudos
1 Solution

Accepted Solutions
CharlesMacleod
Esri Regular Contributor

Hi Alex,

Look here...

ProSnippets Geodatabase Obtaining List of Defintions from Geodatabase

ProSnippets Geodatabase, Obtaining related definitions from geodatabase

piecing the bits together gives you what you want

//From the snippets...

IReadOnlyList<FeatureDatasetDefinition> featureDatasetDefinitions = geodatabase.GetDefinitions<FeatureDatasetDefinition>();
bool electionRelatedFeatureDatasets = featureDatasetDefinitions.Any(definition => definition.GetName().Contains("Election"));

...and...

FeatureDatasetDefinition featureDatasetDefinition = geodatabase.GetDefinition<FeatureDatasetDefinition>("LocalGovernment.GDB.Address");
IReadOnlyList<Definition> datasetsInAddressDataset = geodatabase.GetRelatedDefinitions(featureDatasetDefinition, DefinitionRelationshipType.DatasetInFeatureDataset);



//put it together and you get...
IReadOnlyList<Definition> fdsList = gdb.GetDefinitions(DatasetType.FeatureDataset);
//get all the feature classes...
foreach (var fdsDef in fdsList) {
    var defsInDataset = gdb.GetRelatedDefinitions(fdsDef, DefinitionRelationshipType.DatasetInFeatureDataset);
                
    foreach (var def in defsInDataset) { //Or use LINQ .Where( d => d.DatasetType ...
       if (def.DatasetType == DatasetType.FeatureClass)
         ... etc ...

‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍

View solution in original post

5 Replies
by Anonymous User
Not applicable

Hi Alex Zlotin‌,

You could run a quick Python script once you set your workspace to your feature dataset. See links below.

ListFeatureClasses—Help | ArcGIS Desktop 

ListFeatureClasses—ArcPy Functions | Documentation 


Cheers,

AlexZlotin1
New Contributor III

Please note that I am trying to achieve this in Pro SDK, not Python.

0 Kudos
by Anonymous User
Not applicable

Ah my apologies Alex Zlotin‌ missed your tag!
Victor Tey May have done some work in the Pro SDK space I’ve tagged him.

CharlesMacleod
Esri Regular Contributor

Hi Alex,

Look here...

ProSnippets Geodatabase Obtaining List of Defintions from Geodatabase

ProSnippets Geodatabase, Obtaining related definitions from geodatabase

piecing the bits together gives you what you want

//From the snippets...

IReadOnlyList<FeatureDatasetDefinition> featureDatasetDefinitions = geodatabase.GetDefinitions<FeatureDatasetDefinition>();
bool electionRelatedFeatureDatasets = featureDatasetDefinitions.Any(definition => definition.GetName().Contains("Election"));

...and...

FeatureDatasetDefinition featureDatasetDefinition = geodatabase.GetDefinition<FeatureDatasetDefinition>("LocalGovernment.GDB.Address");
IReadOnlyList<Definition> datasetsInAddressDataset = geodatabase.GetRelatedDefinitions(featureDatasetDefinition, DefinitionRelationshipType.DatasetInFeatureDataset);



//put it together and you get...
IReadOnlyList<Definition> fdsList = gdb.GetDefinitions(DatasetType.FeatureDataset);
//get all the feature classes...
foreach (var fdsDef in fdsList) {
    var defsInDataset = gdb.GetRelatedDefinitions(fdsDef, DefinitionRelationshipType.DatasetInFeatureDataset);
                
    foreach (var def in defsInDataset) { //Or use LINQ .Where( d => d.DatasetType ...
       if (def.DatasetType == DatasetType.FeatureClass)
         ... etc ...

‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍
AlexZlotin1
New Contributor III

Thanks Charles! I saw the snippet but overlooked the GetRelatedDefinitionsMethod.

0 Kudos