Query with CQL filters

View inWPFUWPFormsiOSAndroid
View 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.xmlQueryCQLFilters.cs
                                                                                                         
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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
<?xml version="1.0" encoding="utf-8" ?>
<android.support.constraint.ConstraintLayout
        xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:tools="http://schemas.android.com/tools"
        xmlns:app="http://schemas.android.com/apk/res-auto"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        tools:context=".MainActivity">
    <Esri.ArcGISRuntime.UI.Controls.MapView
            android:layout_width="match_parent"
            android:layout_height="0dp"
            app:layout_constraintBottom_toTopOf="@+id/queryLayout"
            app:layout_constraintTop_toTopOf="parent"
            android:id="@+id/MapView"/>
    <LinearLayout
        android:orientation="vertical"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:id="@+id/queryLayout"
        app:layout_constraintTop_toBottomOf="@+id/MapView"
        app:layout_constraintBottom_toBottomOf="parent"
        android:showDividers="middle"
        android:divider="@android:drawable/divider_horizontal_dark">
        <TextView
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:text="Where clause:"
            android:textSize="20dp" />
        <Spinner
            android:id="@+id/whereClauseSpinner"
            android:layout_height="wrap_content"
            android:text=""
            android:layout_width="match_parent"
            android:layout_weight="1"/>
        <LinearLayout
            android:orientation="horizontal"
            android:layout_width="match_parent"
            android:layout_height="wrap_content">
            <TextView
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:layout_weight="0.5"
                android:text="Max features:"
                android:textSize="20dp" />
            <EditText
                android:id="@+id/maxFeatures"
                android:layout_weight="0.5"
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:inputType="number"
                android:text="Max features:"/>
        </LinearLayout>
        <Switch
            android:id="@+id/dateSwitch"
            android:layout_weight="1"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="Time extent:"
            android:checked="true"/>
        <LinearLayout
            android:orientation="horizontal"
            android:layout_width="match_parent"
            android:layout_height="wrap_content">
            <Button
                android:id="@+id/startDateButton"
                android:layout_width="0dp"
                android:layout_weight="0.5"
                android:layout_height="wrap_content"
                android:text="Start Date"/>
            <Button
                android:id="@+id/endDateButton"
                android:layout_width="0dp"
                android:layout_weight="0.5"
                android:layout_height="wrap_content"
                android:text="End Date"/>
        </LinearLayout>
        <LinearLayout
            android:orientation="horizontal"
            android:layout_width="match_parent"
            android:layout_height="wrap_content">
            <Button
                android:id="@+id/applyButton"
                android:layout_width="0dp"
                android:layout_weight="0.5"
                android:layout_height="wrap_content"
                android:text="Apply"/>
            <Button
                android:id="@+id/resetButton"
                android:layout_width="0dp"
                android:layout_weight="0.5"
                android:layout_height="wrap_content"
                android:text="Reset"/>
        </LinearLayout>
    </LinearLayout>
    <ProgressBar
        android:id="@+id/progressBar"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        app:layout_constraintTop_toTopOf="@+id/MapView"
        app:layout_constraintBottom_toBottomOf="@id/MapView"
        app:layout_constraintLeft_toLeftOf="@id/MapView"
        app:layout_constraintRight_toRightOf="@id/MapView"
      />
</android.support.constraint.ConstraintLayout>

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