Statistical query

View inAndroidFormsUWPWPFWinUIiOSView on GitHub

Query a table to get aggregated statistics back for a specific field.

Image of statistical query

Use case

For example, a county boundaries table with population information can be queried to return aggregated results for total, average, maximum, and minimum population, rather than downloading the values for every county and calculating statistics manually.

How to use the sample

Pan and zoom to define the extent for the query. Use the 'Cities in current extent' checkbox to control whether the query only includes features in the visible extent. Use the 'Cities grater than 5M' checkbox to filter the results to only those cities with a population greater than 5 million people. Click 'Get statistics' to perform the query. The query will return population-based statistics from the combined results of all features matching the query criteria.

How it works

  1. Create a ServiceFeatureTable with a URL to the feature service.
  2. Create StatisticsQueryParameters, and StatisticDefinition objects, and add to the parameters.
  3. Execute QueryStatistics on the ServiceFeatureTable. Depending on the state of the two checkboxes, additional parameters are set.
  4. Display each StatisticRecord in the first returned QueryStatisticsResult.

Relevant API

  • QueryParameters
  • ServiceFeatureTable
  • StatisticDefinition
  • StatisticRecord
  • StatisticsQueryParameters
  • StatisticsQueryResult
  • StatisticType

Tags

analysis, average, bounding geometry, filter, intersect, maximum, mean, minimum, query, spatial query, standard deviation, statistics, sum, variance

Sample Code

StatisticalQuery.xamlStatisticalQuery.xamlStatisticalQuery.xaml.cs
Use dark colors for code blocksCopy
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
<UserControl
    x:Class="ArcGISRuntime.UWP.Samples.StatisticalQuery.StatisticalQuery"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:esriUI="using:Esri.ArcGISRuntime.UI.Controls">
    <Grid>
        <esriUI:MapView x:Name="MyMapView"/>
        <Border Style="{StaticResource BorderStyle}">
            <Grid>
                <Grid.RowDefinitions>
                    <RowDefinition Height="Auto"/>
                    <RowDefinition Height="Auto"/>
                    <RowDefinition Height="Auto"/>
                    <RowDefinition Height="Auto"/>
                </Grid.RowDefinitions>
                <CheckBox x:Name="OnlyInExtentCheckbox"
                          Grid.Row="0"
                          Content="Cities in current extent"
                          FontWeight="SemiBold" />
                <CheckBox x:Name="OnlyBigCitiesCheckbox"
                          Grid.Row="1"
                          Content="Cities larger than 5M"
                          FontWeight="SemiBold"/>
                <ListBox x:Name="StatResultsListBox"
                         Margin="0,5,0,5"
                         Grid.Row="2"
                         HorizontalAlignment="Stretch"/>
                <Button Content="Get statistics"
                        Grid.Row="3"
                        Margin="0,5,0,0"
                        HorizontalAlignment="Stretch"
                        Click="OnExecuteStatisticsQueryClicked"/>
            </Grid>
        </Border>
    </Grid>
</UserControl>

Your browser is no longer supported. Please upgrade your browser for the best experience. See our browser deprecation post for more details.