retrieve layers name from file gdb dataset

113
1
Jump to solution
10-08-2019 01:46 AM
VikrantJain2
New Contributor

Hi,

I am newbie to arcobjects (just couple of day old).

TASK :  I want to upload the the file gdb from given path and show it on arcmap using arcobject.

PROGESS : I can upload the file gdb from the location and able to load layers present in gdb if they are bundled as feature class, but as soon i try to load the gdb contains the layers bundled in dataset, things won't work.

also, suggest me the best practices for doing so.

sorry, in case if it is previously asked.

Thanks in advance.

Reply
0 Kudos
1 Solution

Accepted Solutions
VikrantJain2
New Contributor

Well, I find something 

public List<ILayer> IFeatureDataset_Example(IFeatureDataset featureDataset, IFeatureWorkspace workspace)
{
//This function lists the feature classes in a feature dataset.
//If you just need to browse the available datasets, an alternative,
//lighter-weight interface to use is IFeatureDatasetName.
List<ILayer> layers = new List<ILayer>();
IEnumDataset enumDataset = featureDataset.Subsets;

//loop through each dataset, check if it is a feature class
IDataset dataset = enumDataset.Next();
while (dataset != null)
{
if (dataset.Type == esriDatasetType.esriDTFeatureClass)
{
IFeatureClass featureClass = workspace.OpenFeatureClass(dataset.Name);
IFeatureLayer featureLayer = new FeatureLayerClass();
featureLayer.FeatureClass = featureClass;
ILayer layer = (ILayer)featureLayer;
layer.Name = dataset.Name;
layers.Add(layer);
}
dataset = enumDataset.Next();
}
return layers;
}‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍

I use this function read and return all the layers as a list and later show the layers list in map document directly.

The inspiration of above code is http://resources.esri.com/help/9.3/ArcGISEngine/ArcObjects/esriGeodatabase/IFeatureDataset_Example.h...

View solution in original post

Reply
0 Kudos
1 Reply
VikrantJain2
New Contributor

Well, I find something 

public List<ILayer> IFeatureDataset_Example(IFeatureDataset featureDataset, IFeatureWorkspace workspace)
{
//This function lists the feature classes in a feature dataset.
//If you just need to browse the available datasets, an alternative,
//lighter-weight interface to use is IFeatureDatasetName.
List<ILayer> layers = new List<ILayer>();
IEnumDataset enumDataset = featureDataset.Subsets;

//loop through each dataset, check if it is a feature class
IDataset dataset = enumDataset.Next();
while (dataset != null)
{
if (dataset.Type == esriDatasetType.esriDTFeatureClass)
{
IFeatureClass featureClass = workspace.OpenFeatureClass(dataset.Name);
IFeatureLayer featureLayer = new FeatureLayerClass();
featureLayer.FeatureClass = featureClass;
ILayer layer = (ILayer)featureLayer;
layer.Name = dataset.Name;
layers.Add(layer);
}
dataset = enumDataset.Next();
}
return layers;
}‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍

I use this function read and return all the layers as a list and later show the layers list in map document directly.

The inspiration of above code is http://resources.esri.com/help/9.3/ArcGISEngine/ArcObjects/esriGeodatabase/IFeatureDataset_Example.h...

View solution in original post

Reply
0 Kudos