GeoTools

OSGeo

Tuesday, May 6, 2014

Filter Cleanup and ECQL Fixes

Quick update from the GeoTools development pipeline. It is kind of a tricky update to be excited about ... here is what it looks like:

Eclipse Auto-Complete

So what are you looking at? You are looking at Eclipse auto-complete for Filter. Since GeoTools 2.3 we have had two filter interfaces in the system:

a) org.opengis.filter.Filter - read only interface from GeoTools 2.3
b) org.geotools.filter.Filter - read/write interface from GeoTools 2.0

For the next release of GeoTools we are down to one, making GeoTools that much easier to get started with.

FilterFactory2 ff = CommonFactoryFinder.getFilterFactory2();
Filter filter = ff.equals(ff.property("type"), ff.literal("city"));
SimpleFeatureCollection features = source.getFeatures( filter );

More importantly, and the motivation for the work, no more surprising ClassCastExceptions. Thanks to Boundless for sponsoring this work (and Andrea for reviewing the pull request).

Another bit of code seeing some love is the ECQL representation of Filter. ECQL is our "enhanced" version of OGC common query language.

String cql = ECQL.toCQL(filter);

Will produce: type = 'city'

In effect ECQL is similar to the "WHERE" part of an SQL statement. Be aware that GeoTools is not executing SQL directly, instead the filter data structure is translated into SQL specific for each database we support.

I took the opportunity to make sure some of the more interesting ECQL output correctly:

filter = ECQL.toFilter("type IN ('city','town')");

Thanks to Andrew Hulbert on the geotools-user list for helping catch these glitches.

For more information on filter check out our documentation on the subject.