Query with CQL filters

View inMAUIUWPWPFWinUIView on GitHub

Query data from an OGC API feature service using CQL filters.

Image of Query with CQL Filters

Use case

CQL (Common Query Language) is an OGC-created query language used to query for subsets of features. Use CQL filters to narrow geometry results from an OGC feature table.

How to use the sample

Enter a CQL query. Press the "Apply query" button to see the query applied to the OGC API features shown on the map.

How it works

  1. Create an OgcFeatureCollectionTable object using a URL to an OGC API feature service and a collection ID.
  2. Create a QueryParameters object.
  3. Set the QueryParameters.WhereClause property.
  4. Set the QueryParameters.MaxFeatures property.
  5. Create Datetime objects for the start time and end time being queried.
  6. Create a TimeExtent object using the start and end Datetime objects. Set the QueryParameters.TimeExtent property
  7. Populate the OgcFeatureCollectionTable using PopulateFromServiceAsync() with the custom QueryParameters created in the previous steps.
  8. Use MapView.SetViewpointGeometryAsync() with the OgcFeatureCollectionTable.Extent to view the newly-queried features.

Relevant API

  • OgcFeatureCollectionTable
  • QueryParameters
  • TimeExtent

About the data

The Daraa, Syria test data is OpenStreetMap data converted to the Topographic Data Store schema of NGA.

Additional information

See the OGC API website for more information on the OGC API family of standards. See the CQL documentation to learn more about the common query language.

Tags

browse, catalog, common query language, CQL, feature table, filter, OGC, OGC API, query, service, web

Sample Code

QueryCQLFilters.xamlQueryCQLFilters.xamlQueryCQLFilters.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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
<UserControl x:Class="ArcGIS.UWP.Samples.QueryCQLFilters.QueryCQLFilters"
             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 />
                    <RowDefinition />
                    <RowDefinition />
                    <RowDefinition />
                    <RowDefinition />
                    <RowDefinition />
                    <RowDefinition />
                    <RowDefinition />
                    <RowDefinition />
                </Grid.RowDefinitions>
                <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="auto" />
                    <ColumnDefinition Width="*" />
                </Grid.ColumnDefinitions>
                <TextBlock Grid.Row="0"
                           Grid.ColumnSpan="2"
                           FontWeight="Bold"
                           Foreground="Black"
                           Text="Populate query parameters" />
                <TextBlock Grid.Row="1"
                           Grid.Column="0"
                           VerticalAlignment="Center"
                           Text="Where clause:" />
                <ComboBox x:Name="WhereClauseBox"
                          Grid.Row="1"
                          Grid.Column="1"
                          Margin="5"
                          HorizontalAlignment="Stretch"
                          IsEditable="True" />
                <TextBlock Grid.Row="2"
                           Grid.Column="0"
                           VerticalAlignment="Center"
                           Text="Max features:" />
                <TextBox x:Name="MaxFeaturesBox"
                         Grid.Row="2"
                         Grid.Column="1"
                         Margin="5" />
                <CheckBox x:Name="DateBox"
                          Grid.Row="3"
                          Grid.ColumnSpan="2"
                          Margin="5"
                          Checked="DateBox_Checked"
                          Content="Time extent:"
                          IsChecked="True"
                          Unchecked="DateBox_Checked" />
                <DatePicker x:Name="StartDatePicker"
                            Grid.Row="4"
                            Grid.ColumnSpan="2"
                            Margin="5" />
                <DatePicker x:Name="EndDatePicker"
                            Grid.Row="5"
                            Grid.ColumnSpan="2"
                            Margin="5" />
                <Button x:Name="ApplyQuery"
                        Grid.Row="6"
                        Grid.Column="0"
                        Margin="5"
                        Click="ApplyQuery_Click"
                        Content="Apply query" />
                <Button x:Name="ResetQuery"
                        Grid.Row="6"
                        Grid.Column="1"
                        Margin="5"
                        Click="ResetQuery_Click"
                        Content="Reset" />
                <TextBlock x:Name="NumberOfReturnedFeatures"
                           Grid.Row="7"
                           Grid.ColumnSpan="2" />
                <ProgressBar x:Name="LoadingProgressBar"
                             Grid.Row="8"
                             Grid.ColumnSpan="2"
                             Height="10"
                             Margin="5"
                             IsEnabled="True"
                             IsIndeterminate="True"
                             Visibility="Visible" />
            </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.