FGDB and working with it.

144
6
Jump to solution
05-10-2022 04:46 AM
DavidMrázek
Occasional Contributor II

Hi,
is there any way to select all FC and datasets from FileGDB? I would like to extract all elements from the path to .gdb and add them to the list. Is it possible?

Thank you
David

1 Solution

Accepted Solutions
AashisLamsal1
Esri Contributor

You can call GetDefinitions for individual dataset types: 

var fcDefinitions = geodatabase.GetDefinitions<FeatureClassDefinition>();
var tableDefinitions = geodatabase.GetDefinitions<TableDefinition>();
var datasetDefinitions = geodatabase.GetDefinitions<FeatureDatasetDefinition>();
.....
// Similar for other dataset types

// Loop through the results
foreach (var definition in datasetDefinitions)
{
  Console.WriteLine(definition.GetName() + "=>" + definition.DatasetType);

  definition.Dispose();

}

View solution in original post

6 Replies
AashisLamsal1
Esri Contributor

You can call GetDefinitions for individual dataset types: 

var fcDefinitions = geodatabase.GetDefinitions<FeatureClassDefinition>();
var tableDefinitions = geodatabase.GetDefinitions<TableDefinition>();
var datasetDefinitions = geodatabase.GetDefinitions<FeatureDatasetDefinition>();
.....
// Similar for other dataset types

// Loop through the results
foreach (var definition in datasetDefinitions)
{
  Console.WriteLine(definition.GetName() + "=>" + definition.DatasetType);

  definition.Dispose();

}

DavidMrázek
Occasional Contributor II

Thank you very much that's it 🙂

0 Kudos
DavidMrázek
Occasional Contributor II

Just a question, I'm trying to make Layers out of it, but I don't know how to put it together to select FeatureClass and FeatureDataset.

 var seznamFeateruLayer = new List<FeatureLayer>();
                    Geodatabase geodatabase =
                        new Geodatabase(
                            new FileGeodatabaseConnectionPath(
                                new Uri(_cesta))); //C:\Users\mrazekd\Documents\ArcGIS\Projects\test\test.gdb
                    var fcDefinice = geodatabase.GetDefinitions<FeatureClassDefinition>();
                    var datasetDefinice = geodatabase.GetDefinitions<FeatureDatasetDefinition>();
                    if (datasetDefinice.Count != 0)
                    {
                        foreach (var definition in datasetDefinice)
                        {
                            var jmenoFcDataset = definition.GetName();
                            var url = _cesta + @"\" + jmenoFcDataset;
                            Uri uri = new Uri(url);
                            await QueuedTask.Run(() => LayerFactory.Instance.CreateLayer(uri, mapView.Map));
                            if (fcDefinice.Count != 0)
                            {
                                foreach (var definice in fcDefinice)
                                {
                                    var jmenoFc = definice.GetName();
                                    if ()//I don't know how to separate the two here
                                    {
                                        var urlFc = _cesta + @"\" + jmenoFc;
                                        Uri uriFc = new Uri(urlFc);
                                        await QueuedTask.Run(() => LayerFactory.Instance.CreateLayer(uriFc, mapView.Map));
                                    }
                                    FeatureLayer featureLayerJmeno =
                                        mapView.Map.FindLayers(jmenoFc).First() as FeatureLayer;
                                    seznamFeateruLayer.Add(featureLayerJmeno);
                                }
                            }
                        }
                    }
0 Kudos
AashisLamsal1
Esri Contributor

This snippet shows you the path differences in feature datasets and feature classes. 

You can get the path using featureClass.GetPath().

 

var fcName = featureClassDef.GetName();
using (var fc = geodatabase.OpenDataset<FeatureClass>(fcName))
{
  FeatureDataset featureDataset = fc.GetFeatureDataset();
  if(featureDataset !=null)
  {
   // do something with feature class inside feature dataset
  }
  
  var path = fc.GetPath();
  LayerFactory.Instance.CreateLayer(path, MapView.Active.Map);
}

 

To filter the feature classes only inside the feature dataset you can use geodatabase.GetRelatedDefinitions() method.

 

foreach (var featureDatasetDef in featureDatasetDefinitions)
{
 IReadOnlyList<Definition> datasetsInFeatureDataset = geodatabase.GetRelatedDefinitions(featureDatasetDef, DefinitionRelationshipType.DatasetInFeatureDataset);
 foreach(Definition datsetInFeatureDataset in datasetsInFeatureDataset)
 {
  if(datsetInFeatureDataset.DatasetType == DatasetType.FeatureClass)
  {
	using (FeatureClassDefinition featureClassDefinition = datsetInFeatureDataset as FeatureClassDefinition) 
	{
	  var fcName = featureClassDefinition.GetName();
	  using (var fc = geodatabase.OpenDataset<FeatureClass>(fcName))
	  {
		var path = fc.GetPath();
		LayerFactory.Instance.CreateLayer(path, MapView.Active.Map, layerName:$"From Dataset{fcName}");
	  }
	}              
   }
  }
}

 

DavidMrázek
Occasional Contributor II

Thank you very much !!!

0 Kudos