Added by Mauricio Pazos, last edited by jgarnett on Dec 04, 2007  (view change)

Labels

 

This module is focused on the "Common Query Language" format defined by an OGC Catalog specification. In plain terms it gives us something nice and readable like an SQL where clause.

Your interaction with this module should be via a single utility class - CQL.

What is it Good For?

Here is the most common use for the CQL class - asking for Features:

Filter filter = CQL.toFilter("attName >= 5");
FeatureCollection features = featureSource.getFeatures( filter );

The construct produced is a <b>Filter</b>; you can create Filters by hand (using a FilterFactory) but this is much easier.

Background

The org.geotools.filter.text.cql2.CQL utility class has static methods to parse an input String into either a org.opengis.filter.Filter, a org.opengis.filter.expression.Expression, or a List<org.opengis.filter.Filter>.

The input string defining the query predicate that CQL accepts has to respond to the grammar of the OGC Common Query Language, defined in the Catalog Service for Web, v2.0.1, from the OGC. We've added a couple extensions and fixes to that grammar in order to fix a bug in the definition of temporal expressions and to leverage its use in the GeoTools library.

Quick Guide

If you're developing with GeoTools, you can easily try out the CQL parser by importing the cql module as an eclipse project and running the FilterBuilder class as a normal Java application. It will present a prompt on the console (standard input) from where you can input cql strings and will get back the corresponding Filter in xml encoding.