<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Feature Layer Count based on layer created from selection in ArcGIS Pro SDK Questions</title>
    <link>https://community.esri.com/t5/arcgis-pro-sdk-questions/feature-layer-count-based-on-layer-created-from/m-p/1632039#M13043</link>
    <description>&lt;P&gt;If you select all features in the newly created layer you can use GetSelection () and the selection count on the layer, otherwise you have to use a RowCursor on the FeatureLayer itself (not on the underlying FeatureClass or Table):&lt;/P&gt;&lt;LI-CODE lang="csharp"&gt;try
{
  // get all feature layers in the current map
  var map = MapView.Active.Map;
  if (map == null)
  {
    MessageBox.Show("No active map found.", "Error", System.Windows.MessageBoxButton.OK, System.Windows.MessageBoxImage.Error);
    return;
  }
  var featureLayers = map.GetLayersAsFlattenedList().OfType&amp;lt;FeatureLayer&amp;gt;().ToList();
  if (featureLayers.Count == 0)
  {
    MessageBox.Show("No feature layers found in the active map.", "Information", System.Windows.MessageBoxButton.OK, System.Windows.MessageBoxImage.Information);
    return;
  }
  // count rows in each feature layer
  StringBuilder result = new StringBuilder();
  await QueuedTask.Run(() =&amp;gt;
  {
    foreach (FeatureLayer layer in featureLayers)
    {
      // Get the row count for the feature layer
      // this is not working since it is getting the underlying table (which has all records in
      // the case where a layer is created with a 'select' clause
      // long rowCount = layer.GetTable().GetCount();

      // create a cursor for the layer (not the table)
      var rowCursor = layer.Search();
      long rowCount = 0;
      while (rowCursor.MoveNext())
      {
        rowCount++;
      }
      result.AppendLine($"{layer.Name}: {rowCount} rows");
    }
  });
  // Show the result in a message box
  MessageBox.Show(result.ToString(), "Row Count Results", System.Windows.MessageBoxButton.OK, System.Windows.MessageBoxImage.Information);
}
catch (Exception ex)
{
  MessageBox.Show($"An error occurred: {ex.Message}", "Error", System.Windows.MessageBoxButton.OK, System.Windows.MessageBoxImage.Error);
}&lt;/LI-CODE&gt;</description>
    <pubDate>Thu, 10 Jul 2025 15:24:44 GMT</pubDate>
    <dc:creator>Wolf</dc:creator>
    <dc:date>2025-07-10T15:24:44Z</dc:date>
    <item>
      <title>Feature Layer Count based on layer created from selection</title>
      <link>https://community.esri.com/t5/arcgis-pro-sdk-questions/feature-layer-count-based-on-layer-created-from/m-p/1630786#M13026</link>
      <description>&lt;P&gt;Hi,&amp;nbsp;&lt;/P&gt;&lt;P&gt;Is it possible to get the current count of a feature layer without using the underlying feature class or having to iterate through a search and incrementing a counter? I have a layer that was created using a selection and I've tried getting the count of that layer but it only displays the count based on the underlying feature class.&lt;/P&gt;</description>
      <pubDate>Mon, 07 Jul 2025 18:30:15 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-sdk-questions/feature-layer-count-based-on-layer-created-from/m-p/1630786#M13026</guid>
      <dc:creator>ChrisRobles</dc:creator>
      <dc:date>2025-07-07T18:30:15Z</dc:date>
    </item>
    <item>
      <title>Re: Feature Layer Count based on layer created from selection</title>
      <link>https://community.esri.com/t5/arcgis-pro-sdk-questions/feature-layer-count-based-on-layer-created-from/m-p/1632039#M13043</link>
      <description>&lt;P&gt;If you select all features in the newly created layer you can use GetSelection () and the selection count on the layer, otherwise you have to use a RowCursor on the FeatureLayer itself (not on the underlying FeatureClass or Table):&lt;/P&gt;&lt;LI-CODE lang="csharp"&gt;try
{
  // get all feature layers in the current map
  var map = MapView.Active.Map;
  if (map == null)
  {
    MessageBox.Show("No active map found.", "Error", System.Windows.MessageBoxButton.OK, System.Windows.MessageBoxImage.Error);
    return;
  }
  var featureLayers = map.GetLayersAsFlattenedList().OfType&amp;lt;FeatureLayer&amp;gt;().ToList();
  if (featureLayers.Count == 0)
  {
    MessageBox.Show("No feature layers found in the active map.", "Information", System.Windows.MessageBoxButton.OK, System.Windows.MessageBoxImage.Information);
    return;
  }
  // count rows in each feature layer
  StringBuilder result = new StringBuilder();
  await QueuedTask.Run(() =&amp;gt;
  {
    foreach (FeatureLayer layer in featureLayers)
    {
      // Get the row count for the feature layer
      // this is not working since it is getting the underlying table (which has all records in
      // the case where a layer is created with a 'select' clause
      // long rowCount = layer.GetTable().GetCount();

      // create a cursor for the layer (not the table)
      var rowCursor = layer.Search();
      long rowCount = 0;
      while (rowCursor.MoveNext())
      {
        rowCount++;
      }
      result.AppendLine($"{layer.Name}: {rowCount} rows");
    }
  });
  // Show the result in a message box
  MessageBox.Show(result.ToString(), "Row Count Results", System.Windows.MessageBoxButton.OK, System.Windows.MessageBoxImage.Information);
}
catch (Exception ex)
{
  MessageBox.Show($"An error occurred: {ex.Message}", "Error", System.Windows.MessageBoxButton.OK, System.Windows.MessageBoxImage.Error);
}&lt;/LI-CODE&gt;</description>
      <pubDate>Thu, 10 Jul 2025 15:24:44 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-sdk-questions/feature-layer-count-based-on-layer-created-from/m-p/1632039#M13043</guid>
      <dc:creator>Wolf</dc:creator>
      <dc:date>2025-07-10T15:24:44Z</dc:date>
    </item>
    <item>
      <title>Re: Feature Layer Count based on layer created from selection</title>
      <link>https://community.esri.com/t5/arcgis-pro-sdk-questions/feature-layer-count-based-on-layer-created-from/m-p/1632509#M13048</link>
      <description>&lt;P&gt;Thank you for the reply Wolf, is there any way you would suggest doing the count on a layer that has thousands or tens of thousands of features? I think having to select all features or iterating through each row would cause delay.&lt;/P&gt;</description>
      <pubDate>Fri, 11 Jul 2025 17:07:42 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-sdk-questions/feature-layer-count-based-on-layer-created-from/m-p/1632509#M13048</guid>
      <dc:creator>ChrisRobles</dc:creator>
      <dc:date>2025-07-11T17:07:42Z</dc:date>
    </item>
    <item>
      <title>Re: Feature Layer Count based on layer created from selection</title>
      <link>https://community.esri.com/t5/arcgis-pro-sdk-questions/feature-layer-count-based-on-layer-created-from/m-p/1632961#M13059</link>
      <description>&lt;P&gt;I don't see another way, however, i think processing will be fast since the layer data is cached in memory.&amp;nbsp; Here is my sample:&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Wolf_0-1752527153933.png" style="width: 400px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/136485i0E1D0D2065B08655/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Wolf_0-1752527153933.png" alt="Wolf_0-1752527153933.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;3141 records in 0.017 seconds.&amp;nbsp;&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;These are the code changes to measure the timing:&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;LI-CODE lang="csharp"&gt;// count rows in each feature layer
StringBuilder result = new StringBuilder();
await QueuedTask.Run(() =&amp;gt;
{
  foreach (FeatureLayer layer in featureLayers)
  {
    // Get the row count for the feature layer
    // this is not working since it is getting the underlying table (which has all records in
    // the case where a layer is created with a 'select' clause
    // long rowCount = layer.GetTable().GetCount();

    // create a cursor for the layer (not the table)
    var rowCursor = layer.Search();
    long rowCount = 0;
    var timer = new Stopwatch();
    timer.Start(); 
    while (rowCursor.MoveNext())
    {
      rowCount++;
    }
    timer.Stop();
    var elapsedTime = timer.Elapsed;
    result.AppendLine($"{layer.Name}: {rowCount} rows  {elapsedTime:m\\:ss\\.fff} min.");
  }
});
// Show the result in a message box
MessageBox.Show(result.ToString(), "Row Count Results", System.Windows.MessageBoxButton.OK, System.Windows.MessageBoxImage.Information);&lt;/LI-CODE&gt;</description>
      <pubDate>Mon, 14 Jul 2025 21:08:04 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-sdk-questions/feature-layer-count-based-on-layer-created-from/m-p/1632961#M13059</guid>
      <dc:creator>Wolf</dc:creator>
      <dc:date>2025-07-14T21:08:04Z</dc:date>
    </item>
    <item>
      <title>Re: Feature Layer Count based on layer created from selection</title>
      <link>https://community.esri.com/t5/arcgis-pro-sdk-questions/feature-layer-count-based-on-layer-created-from/m-p/1642611#M13086</link>
      <description>&lt;P&gt;That worked great thank you!&lt;/P&gt;</description>
      <pubDate>Fri, 15 Aug 2025 21:18:33 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-sdk-questions/feature-layer-count-based-on-layer-created-from/m-p/1642611#M13086</guid>
      <dc:creator>ChrisRobles</dc:creator>
      <dc:date>2025-08-15T21:18:33Z</dc:date>
    </item>
  </channel>
</rss>

