Get list of layers/Tables from a File Geodatabase

2739
2
Jump to solution
06-01-2016 08:29 AM
Highlighted
New Contributor II

I am trying to use a GP tool to export a Layer to a File GDB. Is there a way to find which layers are already present in the GDB so that I can give a different name to my Layer. The code below works but was hoping there is a better way to do this.

thank you,

Vijay

            string featureClassName = AppConstants.ExportProposedBuildingName;

            IReadOnlyList<string> valueArray = null;

            await QueuedTask.Run(() =>

            {

                Geodatabase fileGeodatabase = new Geodatabase(@"c:\0_Projects\CapeCodCommission\CapeCod.gdb");

                bool isFound = true;

                int index = 0;

                while (isFound)

                {

                    try

                    {

                        fileGeodatabase.OpenDataset<Table>(featureClassName);

                        isFound = true;

                        featureClassName = AppConstants.ExportProposedBuildingName + "_" + ++index;

                    }

                    catch

                    {

                        isFound = false;

                    }

                }

                valueArray = Geoprocessing.MakeValueArray

                    (proposedBuildingLayer, @"C:\0_Projects\CapeCodCommission\CapeCod.gdb\" + featureClassName);

            });

Tags (1)
Reply
0 Kudos
1 Solution

Accepted Solutions
Highlighted
New Contributor II

Hi Vijay,

You can use the GetDefinitions (ArcGIS Pro 1.2 API Reference Guide) method instead. The Definition is a much lighter weight construct which does not open the feature class. One more thing to remember is that getting the TableDefinitions will not give you the FeatureClassDefinitions.

Try the following code out. It uses the LINQ syntax for more concise code.

            string featureClassName = AppConstants.ExportProposedBuildingName;

            IReadOnlyList<string> valueArray = null;

            await QueuedTask.Run(() =>

            {

                Geodatabase fileGeodatabase = new Geodatabase(@"c:\0_Projects\CapeCodCommission\CapeCod.gdb");

                List<Definition> definitions = new List<Definition>();

                definitions.AddRange(fileGeodatabase.GetDefinitions<TableDefinition>());

                definitions.AddRange(fileGeodatabase.GetDefinitions<FeatureClassDefinition>());

                 int index = 0;

                 while(definitions.Any(definition => definition.GetName().Equals(featureClassName)))

                     featureClassName = AppConstants.ExportProposedBuildingName + "_" + ++index;

                 valueArray = Geoprocessing.MakeValueArray

                    (proposedBuildingLayer, @"C:\0_Projects\CapeCodCommission\CapeCod.gdb\" + featureClassName);

            });

-Sree

View solution in original post

Reply
0 Kudos
2 Replies
Highlighted
New Contributor II

Hi Vijay,

You can use the GetDefinitions (ArcGIS Pro 1.2 API Reference Guide) method instead. The Definition is a much lighter weight construct which does not open the feature class. One more thing to remember is that getting the TableDefinitions will not give you the FeatureClassDefinitions.

Try the following code out. It uses the LINQ syntax for more concise code.

            string featureClassName = AppConstants.ExportProposedBuildingName;

            IReadOnlyList<string> valueArray = null;

            await QueuedTask.Run(() =>

            {

                Geodatabase fileGeodatabase = new Geodatabase(@"c:\0_Projects\CapeCodCommission\CapeCod.gdb");

                List<Definition> definitions = new List<Definition>();

                definitions.AddRange(fileGeodatabase.GetDefinitions<TableDefinition>());

                definitions.AddRange(fileGeodatabase.GetDefinitions<FeatureClassDefinition>());

                 int index = 0;

                 while(definitions.Any(definition => definition.GetName().Equals(featureClassName)))

                     featureClassName = AppConstants.ExportProposedBuildingName + "_" + ++index;

                 valueArray = Geoprocessing.MakeValueArray

                    (proposedBuildingLayer, @"C:\0_Projects\CapeCodCommission\CapeCod.gdb\" + featureClassName);

            });

-Sree

View solution in original post

Reply
0 Kudos
Highlighted
New Contributor II

Thank you Sree!! That was exactly what I needed!

Reply
0 Kudos