Select to view content in your preferred language

View FeatureClasses in gdb file using c#

5346
1
01-21-2013 11:12 PM
ArunYegi
New Contributor
Hi,

I am having a .gdb file(World.gdb). I want to display or i want to see the content of this gdb file in winForms programmatically(C#). How can i do it? I dont want to view via ArcCatalog.

Please help soon.

Regards,
Arun
0 Kudos
1 Reply
Jan-Tschada
Esri Contributor
Just open the workspace by using the path to the geodatabase and then enumerate through the containing datasets.
The code below iterates through all feature datasets and their containing feature classes. If your feature classes are not within a feature dataset you have to modify the third line by using a type of esriDTFeatureClass for getting those.


var workspaceFactory = (IWorkspaceFactory) Activator.CreateInstance(typeof(FileGDBWorkspaceFactoryClass));
var featureWorkspace = workspaceFactory.OpenFromFile(@"C:\data\OpenStreetMap\Germany.gdb", 0);
   
var datasets = featureWorkspace.Datasets[esriDatasetType.esriDTFeatureDataset];
datasets.Reset();

IDataset dataset;
while (null != (dataset = datasets.Next()))
{
 var featureDataset = (IFeatureDataset) dataset;
 var featureSubsets = featureDataset.Subsets;

 IDataset subset;
 while (null != (subset = featureSubsets.Next()))
 {
  if (esriDatasetType.esriDTFeatureClass == subset.Type)
  {
   var featureClass = (IFeatureClass) subset;
  }
 }
}




Happy coding
Product Manager
Developers and Location Services
Germany and Switzerland
0 Kudos