How Can I Retrieve the Number Displayed After "Show Feature Counts" for Legends in Layouts?

159
1
3 weeks ago
MaxWei
by
New Contributor II

As stated in the title, I'm looking to retrieve the number displayed for feature counts in legends within a layout. How can I achieve this?

MaxWei_0-1715242766766.png

How to get this counts

MaxWei_1-1715242896588.png

 

0 Kudos
1 Reply
UmaHarano
Esri Regular Contributor

You can get the number of features in a layer using the Pro API's, FeatureClass.GetCount() method.

 

var featureLayer = MapView.Active.Map.GetLayersAsFlattenedList().OfType<FeatureLayer>().FirstOrDefault(n => n.Name == "TestPoly");
QueuedTask.Run( () => {
  var featureClass = featureLayer.GetFeatureClass();
  var count = featureClass.GetCount();
});
0 Kudos