Click or drag to resize

FeatureTableQueryFeatureCountAsync Method

Asynchronously queries the count of all features that satisfy the provided parameters.

Namespace:  Esri.ArcGISRuntime.Data
Assembly:  Esri.ArcGISRuntime (in Esri.ArcGISRuntime.dll) Version: 100.11.0
public Task<long> QueryFeatureCountAsync(
	QueryParameters queryParameters


Type: Esri.ArcGISRuntime.DataQueryParameters
The parameters of the query.

Return Value

Type: TaskInt64
A task that represents the asynchronous query of feature count. The value of the task result contains a Int64.


Example Name: QueryFeatureCountAndExtent

Zoom to features matching a query and count the features in the current visible extent.

Code example screen shot.

// Copyright 2018 Esri.
// Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License.
// You may obtain a copy of the License at:
// Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific
// language governing permissions and limitations under the License.

using Esri.ArcGISRuntime.Data;
using Esri.ArcGISRuntime.Geometry;
using Esri.ArcGISRuntime.Mapping;
using System;
using System.Windows;

namespace ArcGISRuntime.WPF.Samples.QueryFeatureCountAndExtent
        name: "Query feature count and extent",
        category: "Analysis",
        description: "Zoom to features matching a query and count the features in the current visible extent.",
        instructions: "Use the button to zoom to the extent of the state specified (by abbreviation) in the textbox or use the button to count the features in the current extent.",
        tags: new[] { "count", "feature layer", "feature table", "features", "filter", "number", "query" })]
    public partial class QueryFeatureCountAndExtent
        // URL to the feature service.
        private readonly Uri _medicareHospitalSpendLayer =
            new Uri("");

        // Feature table to query.
        private ServiceFeatureTable _featureTable;

        public QueryFeatureCountAndExtent()

        private async void Initialize()
            // Create the map with a basemap.
            Map myMap = new Map(BasemapStyle.ArcGISDarkGray);

            // Create the feature table from the service URL.
            _featureTable = new ServiceFeatureTable(_medicareHospitalSpendLayer);

            // Create the feature layer from the table.
            FeatureLayer myFeatureLayer = new FeatureLayer(_featureTable);

            // Add the feature layer to the map.

                // Wait for the feature layer to load.
                await myFeatureLayer.LoadAsync();

                // Set the map initial extent to the extent of the feature layer.
                myMap.InitialViewpoint = new Viewpoint(myFeatureLayer.FullExtent);

                // Add the map to the MapView.
                MyMapView.Map = myMap;
            catch (Exception e)
                MessageBox.Show(e.ToString(), "Error");

        private async void BtnZoomToFeaturesClick(object sender, RoutedEventArgs e)
                // Create the query parameters.
                QueryParameters queryStates = new QueryParameters{WhereClause = $"upper(State) LIKE '%{StateTextbox.Text}%'"};

                // Get the extent from the query.
                Envelope resultExtent = await _featureTable.QueryExtentAsync(queryStates);

                // Return if there is no result (might happen if query is invalid).
                if (resultExtent?.SpatialReference == null)
                    ResultsTextbox.Text = "No results. Search for an abbreviated name (e.g. NH).";

                // Create a viewpoint from the extent.
                Viewpoint resultViewpoint = new Viewpoint(resultExtent);

                // Zoom to the viewpoint.
                await MyMapView.SetViewpointAsync(resultViewpoint);

                // Update the UI.
                ResultsTextbox.Text = $"Zoomed to features in {StateTextbox.Text}";
            catch (Exception ex)
                MessageBox.Show(ex.ToString(), "Error");

        private async void BtnCountFeaturesClick(object sender, RoutedEventArgs e)
                // Get the current visible extent.
                Geometry currentExtent = MyMapView.GetCurrentViewpoint(ViewpointType.BoundingGeometry).TargetGeometry;

                // Create the query parameters.
                QueryParameters queryCityCount = new QueryParameters
                    Geometry = currentExtent,
                    // Specify the interpretation of the Geometry query parameters.
                    SpatialRelationship = SpatialRelationship.Intersects

                // Get the count of matching features.
                long count = await _featureTable.QueryFeatureCountAsync(queryCityCount);

                // Update the UI.
                ResultsTextbox.Text = $"{count} features in extent";
            catch (Exception ex)
                MessageBox.Show(ex.ToString(), "Error");
<UserControl x:Class="ArcGISRuntime.WPF.Samples.QueryFeatureCountAndExtent.QueryFeatureCountAndExtent"
        <Style TargetType="Button">
            <Setter Property="Margin" Value="5,5,5,0" />
        <Style TargetType="TextBox">
            <Setter Property="Margin" Value="5,5,5,0" />
        <esri:MapView x:Name="MyMapView"/>
        <Border Style="{StaticResource BorderStyle}">
                    <RowDefinition Height="auto" />
                    <RowDefinition Height="auto" />
                    <RowDefinition Height="auto" />
                    <RowDefinition Height="auto" />
                    <ColumnDefinition Width="*" />
                    <ColumnDefinition Width="*" />
                <TextBlock Text="Click 'Zoom to matching features' to zoom to features matching the given state abbreviation. Click 'Count features in extent' to count the features in the current extent (regardless of the results of the query)."
                           Grid.Row="0" Grid.Column="0" Grid.ColumnSpan="2"
                           TextWrapping="Wrap" FontWeight="SemiBold" />
                <TextBox x:Name="StateTextbox" 
                         Grid.Row="1" Grid.Column="0" Grid.ColumnSpan="2" 
                <Button Content="Zoom to matching features" 
                        Grid.Row="2" Grid.Column="0" 
                        Click="BtnZoomToFeaturesClick" />
                <Button Content="Count features in extent" 
                        Grid.Row="2" Grid.Column="1" 
                        Click="BtnCountFeaturesClick" />
                <TextBox x:Name="ResultsTextbox"
                         Grid.Row="3" Grid.Column="0" Grid.ColumnSpan="2" 
                         IsEnabled="False" />
See Also
Additional Examples
Hyperlink to ExampleDescription
FindServiceAreasForMultipleFacilitiesFind the service areas of several facilities from a feature service.
QueryFeatureCountAndExtentZoom to features matching a query and count the features in the current visible extent.