View on GitHub Sample viewer app

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

The sample loads displaying all 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 toggle the time extent check box to query the data with a time extent. 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 QueryParameters and set a CQL filter string to it using queryParameters.setWhereClause().
  3. Set the maximum amount of features to be returned with queryParamters.setMaxFeatures().
  4. Create a new TimeExtent from start and end date values, and set it to the queryParameters.setTimeExtent() method.
  5. Populate the OGC feature collection table using .populateFromServiceAsync() with the custom QueryParameters created in the previous steps.
  6. 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

module-info.java module-info.java QueryWithCqlFiltersController.java QueryWithCqlFiltersSample.java
/*
* Copyright 2022 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.
*/
module com.esri.samples.query_with_cql_filters {
// require ArcGIS Maps SDK for Java module
requires com.esri.arcgisruntime;
// handle SLF4J http://www.slf4j.org/codes.html#StaticLoggerBinder
requires org.slf4j.nop;
// require JavaFX modules that the application uses
requires javafx.graphics;
requires javafx.controls;
requires javafx.fxml;
// make all @FXML annotated objects reflectively accessible to the javafx.fxml module
opens com.esri.samples.query_with_cql_filters to javafx.fxml;
exports com.esri.samples.query_with_cql_filters;
}