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.
Solved! Go to Solution.
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 ...
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,
Please note that I am trying to achieve this in Pro SDK, not Python.
Ah my apologies Alex Zlotin missed your tag!
Victor Tey May have done some work in the Pro SDK space I’ve tagged him.
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 ...
Thanks Charles! I saw the snippet but overlooked the GetRelatedDefinitionsMethod.