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. Tap '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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
<?xml version="1.0" encoding="utf-8" ?>
<ContentPage x:Class="ArcGISRuntime.Samples.StatisticalQuery.StatisticalQuery"
             xmlns="http://xamarin.com/schemas/2014/forms"
             xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
             xmlns:esriUI="clr-namespace:Esri.ArcGISRuntime.Xamarin.Forms;assembly=Esri.ArcGISRuntime.Xamarin.Forms">
    <Grid>
        <Grid.RowDefinitions>
            <RowDefinition Height="auto" />
            <RowDefinition />
        </Grid.RowDefinitions>
        <Grid>
            <Grid.RowDefinitions>
                <RowDefinition />
                <RowDefinition />
                <RowDefinition />
            </Grid.RowDefinitions>
            <Grid.ColumnDefinitions>
                <ColumnDefinition />
                <ColumnDefinition Width="3*" />
            </Grid.ColumnDefinitions>
            <Switch x:Name="OnlyInExtentSwitch"
                    Grid.Row="0"
                    Grid.Column="0"
                    HorizontalOptions="End" />
            <Label Grid.Row="0"
                   Grid.Column="1"
                   Margin="10,0"
                   Text="Cities in current extent"
                   VerticalOptions="Center" />
            <Switch x:Name="OnlyBigCitiesSwitch"
                    Grid.Row="1"
                    Grid.Column="0"
                    HorizontalOptions="End" />
            <Label Grid.Row="1"
                   Grid.Column="1"
                   Margin="10,0"
                   Text="Cities larger than 5M"
                   VerticalOptions="Center" />
            <Button x:Name="GetStatsButton"
                    Grid.Row="2"
                    Grid.Column="0"
                    Grid.ColumnSpan="2"
                    Margin="5,0"
                    Clicked="OnExecuteStatisticsQueryClicked"
                    Text="Get Statistics" />
        </Grid>

        <esriUI:MapView x:Name="MyMapView" Grid.Row="1" />
        <Grid x:Name="ResultsGrid"
              Grid.Row="1"
              BackgroundColor="Gainsboro"
              IsVisible="False">
            <Grid.RowDefinitions>
                <RowDefinition Height="auto" />
                <RowDefinition Height="50" />
            </Grid.RowDefinitions>
            <ListView x:Name="StatResultsList" />
            <Button Grid.Row="1"
                    Margin="5"
                    Clicked="HideResults"
                    Text="Dismiss" />
        </Grid>
    </Grid>
</ContentPage>

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