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!!
Solved! Go to Solution.
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");
}
}
});
I would like to add the feature class to the active map.
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");
}
}
});
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
Thank you! This was very helpful.
Thank you! This worked great. Just what I was looking to do. This is greatly appreciated.