How to add file geodatabase feature class to a map using an ArcGIS Pro button

1841
5
Jump to solution
08-08-2018 06:34 AM
JoshuaO_Neil
New Contributor II

Hello,

I would like to be able to add a file geodatabase feature class to an arcgis pro map using a button created with the ArcGIS Pro SDK. I have been unable to figure out how to do this. Can you please provide an example of the code that would be used in visual studio to create this button?

The path to my data is here:  L:\data\ESRI_10_6\usa\census\states.gdb\states

Thank you!!

0 Kudos
1 Solution

Accepted Solutions
Wolf
by Esri Regular Contributor
Esri Regular Contributor

You can also go through your geodatabase using the geodatabase API first.  In this case you can add your feature classes like this:

// Add this in your OnClick code-behind for the button
if (MapView.Active?.Map == null) return;
ArcGIS.Desktop.Framework.Threading.Tasks.QueuedTask.Run(() =>
{
  // using the community sample dataset
  using (Geodatabase geodatabase = new Geodatabase(new FileGeodatabaseConnectionPath(new Uri(@"C:\Data\FeatureTest\FeatureTest.gdb"))))
  {
    using (FeatureClass addFeatureClass = geodatabase.OpenDataset<FeatureClass>("TestLines"))
    {
      LayerFactory.Instance.CreateFeatureLayer(addFeatureClass, MapView.Active.Map, 0, "New FC");
    }
  }
});

View solution in original post

5 Replies
JoshuaO_Neil
New Contributor II

I would like to add the feature class to the active map.

0 Kudos
Wolf
by Esri Regular Contributor
Esri Regular Contributor

You can also go through your geodatabase using the geodatabase API first.  In this case you can add your feature classes like this:

// Add this in your OnClick code-behind for the button
if (MapView.Active?.Map == null) return;
ArcGIS.Desktop.Framework.Threading.Tasks.QueuedTask.Run(() =>
{
  // using the community sample dataset
  using (Geodatabase geodatabase = new Geodatabase(new FileGeodatabaseConnectionPath(new Uri(@"C:\Data\FeatureTest\FeatureTest.gdb"))))
  {
    using (FeatureClass addFeatureClass = geodatabase.OpenDataset<FeatureClass>("TestLines"))
    {
      LayerFactory.Instance.CreateFeatureLayer(addFeatureClass, MapView.Active.Map, 0, "New FC");
    }
  }
});
UmaHarano
Esri Regular Contributor

Hi Joshua

Here is a snippet on the ArcGIS Pro SDK wiki that adds a feature class to the active map: 

Create and add a layer to the active map

Thanks

Uma

0 Kudos
JoshuaO_Neil
New Contributor II

Thank you! This was very helpful.

0 Kudos
JoshuaO_Neil
New Contributor II

Thank you! This worked great. Just what I was looking to do. This is greatly appreciated.

0 Kudos