Query feature count and extent

View inWPFUWPFormsiOSAndroid
View on GitHub

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

Image of query feature count and extent

Use case

Queries can be used to search for features in a feature table using text entry. This is helpful for finding a specific feature by name in a large feature table. A query can also be used to count features in an extent. This could be used to count the number of a traffic incidents in a particular region when working with an incident dataset for a larger area.

How to use the sample

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.

How it works

Querying by state abbreviation:

  1. A QueryParameters object is created with a WhereClause.
  2. FeatureTable.QueryExtentAsync is called with the QueryParameters object to obtain the extent that contains all matching features.
  3. The extent is converted to a Viewpoint, which is passed to MapView.SetViewpointAsync.

Counting features in the current extent:

  1. The current visible extent is obtained from a call to MapView.GetCurrentViewpoint(ViewpointType).
  2. A QueryParameters object is created with the visible extent and a defined SpatialRelationship (in this case 'intersects').
  3. The count of matching features is obtained from a call to FeatureTable.QueryFeatureCountAsync.

Relevant API

  • FeatureTable.QueryExtentAsync
  • FeatureTable.QueryFeatureCountAsync
  • MapView.GetCurrentViewpoint(ViewpointType)
  • QueryParameters
  • QueryParameters.Geometry
  • QueryParameters.SpatialRelationship
  • QueryParameters.WhereClause

About the data

See the Medicare Hospital Spending per Patient, 2016 layer on ArcGIS Online.

Hospitals in blue/turquoise spend less than the national average. Red/salmon indicates higher spending relative to other hospitals, while gray is average.


count, feature layer, feature table, features, filter, number, query

Sample Code

        <esriUI:MapView x:Name="MyMapView" />
        <Border Style="{StaticResource BorderStyle}">
                <RowDefinition Height="Auto" />
                    <RowDefinition Height="auto" />
                    <RowDefinition Height="auto" />
                    <RowDefinition Height="auto" />
                    <RowDefinition Height="Auto" />
                    <RowDefinition Height="Auto" />
                <TextBlock Text="Tap '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)."
                           FontWeight="SemiBold" TextWrapping="Wrap" />
                <TextBox x:Name="StateEntry"
                         PlaceholderText="e.g. NY" />
                <Button Content="Zoom to matching features"
                        Click="BtnZoomToFeaturesClick" />
                <Button Content="Count features in extent"
                        Click="BtnCountFeaturesClick" />
                <TextBlock x:Name="ResultView"
                           FontWeight="SemiBold" TextAlignment="Center" />