Query a table to get aggregated statistics back for a specific field.
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
- Create a
ServiceFeatureTable
with a URL to the feature service. - Create
StatisticsQueryParameters
, andStatisticDefinition
objects, and add to the parameters. - Execute
QueryStatistics
on theServiceFeatureTable
. Depending on the state of the two checkboxes, additional parameters are set. - Display each
StatisticRecord
in the first returnedQueryStatisticsResult
.
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
<UserControl x:Class="ArcGISRuntime.WPF.Samples.StatisticalQuery.StatisticalQuery"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:esri="http://schemas.esri.com/arcgis/runtime/2013">
<Grid>
<esri:MapView x:Name="MyMapView" />
<Border Style="{StaticResource BorderStyle}">
<Grid>
<Grid.RowDefinitions>
<RowDefinition />
<RowDefinition />
<RowDefinition Height="150" />
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*" />
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<CheckBox x:Name="OnlyInExtentCheckbox"
Grid.Row="0"
Grid.Column="0"
HorizontalAlignment="Left"
Content="Cities in current extent" />
<CheckBox x:Name="OnlyBigCitiesCheckbox"
Grid.Row="0"
Grid.Column="1"
HorizontalAlignment="Right"
Content="Cities greater than 5M" />
<Button x:Name="GetStatsButton"
Grid.Row="1"
Grid.Column="0"
Grid.ColumnSpan="2"
Margin="0,5,0,5"
Click="OnExecuteStatisticsQueryClicked"
Content="Get Statistics" />
<ListBox x:Name="StatResultsListBox"
Grid.Row="2"
Grid.Column="0"
Grid.ColumnSpan="2" />
</Grid>
</Border>
</Grid>
</UserControl>