Query data from an OGC API feature service using 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
The sample loads displaying a maximum of 1000 features within the OGC API feature service. Select a sample CQL query from the drop down menu. Optionally, adjust the max features value in the text box, and enter a date range such as June 13, 2011 (06/13/2011) to January 7, 2012 (01/07/2012) to narrow down the results based on time extent. Press the "Query" button to see the query applied to the OGC API features shown on the map.
How it works
Create an OgcFeatureCollectionTable object using a URL to an OGC API feature service and a collection ID.
Create QueryParameters and set a CQL filter string to it using queryParameters.setWhereClause().
Set the maximum amount of features to be returned with queryParamters.setMaxFeatures().
Create a new TimeExtent from start and end date values, and set it to the queryParameters.setTimeExtent() method.
Populate the OGC feature collection table using populateFromService() with the custom QueryParameters created in the previous steps.
Use mapView.setViewpointGeometryAsync() with the OGC feature collection table 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
QueryOGCAPICQLFilters.qml
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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
// [WriteFile Name=QueryOGCAPICQLFilters, Category=Layers]// [Legal]// Copyright 2021 Esri.// Licensed under the Apache License, Version 2.0 (the "License");// you may not use this file except in compliance with the License.// You may obtain a copy of the License at// http://www.apache.org/licenses/LICENSE-2.0// Unless required by applicable law or agreed to in writing, software// distributed under the License is distributed on an "AS IS" BASIS,// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.// See the License for the specific language governing permissions and// limitations under the License.// [Legal]import QtQuick
import QtQuick.Controls
import Esri.ArcGISRuntime
Rectangle {
id: rootRectangleclip: truewidth: 800height: 600MapView {
id: mapViewanchors.fill: parentMap {
initBasemapStyle: Enums.BasemapStyleArcGISTopographic
FeatureLayer {
OgcFeatureCollectionTable {
id: ogcFeatureCollectionTableurl: "https://demo.ldproxy.net/daraa"collectionId: "TransportationGroundCrv"// Enums.FeatureRequestModeManualCache specifies that features from the server will be stored locally for display and querying// In this mode, ServiceFeatureTable::populateFromService() must be called to populate the local cachefeatureRequestMode: Enums.FeatureRequestModeManualCache
onLoadStatusChanged: {
// ogcFeatureCollectionTable.load() will be automatically called when added to a FeatureLayer// populateFromService() will be called with the initial viewpoint extentif (ogcFeatureCollectionTable.loadStatus === Enums.LoadStatusLoaded)
ogcFeatureCollectionTable.populateFromService(queryParameters, false, []);
}
}
renderer: SimpleRenderer {
SimpleLineSymbol {
style: Enums.SimpleLineSymbolStyleSolid
color: "darkMagenta"width: 3 }
}
}
// initial viewPointViewpointCenter {
targetScale: 200000center: Point {
x: 36.10y: 32.62spatialReference: SpatialReference {
wkid: 4326 }
}
}
}
QueryParameters {
id: queryParameters// Set the default value for max features returnedmaxFeatures: 1000// Set the default where clausewhereClause: "F_CODE = 'AP010'" }
Rectangle {
anchors {
fill: controlColumn
margins: -5 }
color: "#efefef"radius: 5border {
color: "darkgray"width: 1 }
}
Column {
id: controlColumnanchors {
left: parent.left
top: parent.top
margins: 10 }
spacing: 5Row {
spacing: 5Text {
id: whereClauseTextanchors.verticalCenter: parent.verticalCenter
text: "Where Clause" }
ComboBox {
id: whereClauseMenuwidth: 200model: ["F_CODE = 'AP010'", "{ \"op\": \"=\", \"args\": [ { \"property\": \"F_CODE\" }, \"AP010\" ] }", "F_CODE LIKE 'AQ%'", "{\"op\": \"and\", \"args\":[{ \"op\": \"=\", \"args\":[{ \"property\" : \"F_CODE\" }, \"AP010\"]}, { \"op\": \"t_before\", \"args\":[{ \"property\" : \"ZI001_SDV\"},\"2013-01-01\"]}]}"]
}
}
Row {
spacing: 8Text {
id: maxFeatureTextanchors.verticalCenter: parent.verticalCenter
text: "Max Features" }
TextField {
id: maxFeatureFieldanchors.verticalCenter: parent.verticalCenter
width: 200text: "1000"selectByMouse: truevalidator: IntValidator {}
}
}
Row {
spacing: 8Text {
id: fromFieldanchors.verticalCenter: parent.verticalCenter
text: "From"rightPadding: 40 }
TextField {
id: fromDateanchors.verticalCenter: parent.verticalCenter
width: 200text: ""selectByMouse: truevalidator: RegularExpressionValidator {
regularExpression: /(0[1-9]|1[012])[/](0[1-9]|[12][0-9]|3[01])[/](19|20)\d\d/ }
placeholderText: "MM/DD/YYYY" }
}
Row {
spacing: 8Text {
id: toFieldanchors.verticalCenter: parent.verticalCenter
text: "To"rightPadding: 53 }
TextField {
id: toDateanchors.verticalCenter: parent.verticalCenter
width: 200text: ""selectByMouse: truevalidator: RegularExpressionValidator {
regularExpression: /(0[1-9]|1[012])[/](0[1-9]|[12][0-9]|3[01])[/](19|20)\d\d/ }
placeholderText: "MM/DD/YYYY" }
}
Button {
anchors.horizontalCenter: parent.horizontalCenter
text: "Query"onClicked: {
if (!ogcFeatureCollectionTable)
return;
queryParameters.whereClause = whereClauseMenu.currentText
queryParameters.geometry = mapView.currentViewpointExtent.extent
queryParameters.maxFeatures = maxFeatureField.text
if (fromDate.text && toDate.text) {
const startDate = newDate(Date.fromLocaleDateString(Qt.locale(), fromDate.text, "MM/dd/yyyy"));
const endDate = newDate(Date.fromLocaleDateString(Qt.locale(), toDate.text, "MM/dd/yyyy"));
const newTimeExtent = ArcGISRuntimeEnvironment.createObject("TimeExtent", {
"startTime": startDate,
"endTime": endDate
});
queryParameters.timeExtent = newTimeExtent;
}
// Populate the feature collection table with features that match the parameters,// clear the cache to prepare for the new query results, and store all table fields ogcFeatureCollectionTable.populateFromService(queryParameters, true, []);
}
}
}
}
}