Friday, April 30, 2010

A faster, better GeoTools 2.7

GeoTools 2.7.x is current development branch (or "trunk"). Consider this a sneak peak of some of the ideas that are taking shape for the future.

First up we have speed. One of the common use-cases we have on the geotools-gt2-users email list is displaying a Map in a Java Swing application. Still it is nice to see something; especially when learning. With this in mind we have recast our initial introduction tutorials to be a bit more visual.

Out of the box GeoTools focus on providing a standard compliant SLD rendering engine. This engine is not specific to display - and actually never loads data into memory (it simply streams it off disk onto the screen).

In the interest of performance Andrea has donated a wrapper that will cache data in memory (storing it in a JTS spatial index).

File file = JFileDataStoreChooser.showOpenFile("shp", null);

FileDataStore store = FileDataStoreFinder.getDataStore(file);

FeatureSource featureSource = store.getFeatureSource();


CachingFeatureSource cache = new CachingFeatureSource(featureSource);


MapContext map = new DefaultMapContext();

map.setTitle("Using cached features");

map.addLayer(cache, null);


JMapFrame.showMap(map);


For more details please see the updated (and aptly named) Quickstart. This functionality has been back ported to 2.6.x and we are soliciting feedback (and test cases) from users.

Returning to 2.7 we have two great usability improvements:
  • For the longest time we have had a Query interface and a DefaultQuery implementation. These have been combined making code examples just that much readable.
  • We introduced the use of Generics to support application schema work. While we now have a happy team working on application schema; it did impact readably.
    Specifically FeatureCollection < SimpleFeatureType, SimpleFeature > gets tiring.
    Introducing SimpleFeatureCollection to the rescue.
With this in mind a couple of recent proposals have allowed us to write the following:


SimpleFeatureSource source = dataStore.getFeatureSource( typeName );

Query query = new Query( typeName, filter, attributes );

SimpleFeatureCollection features = source.getFeatures(query);


It is all good!

If you are using maven switch to 2.7-SNAPSHOT to try out these improvements today; we will issue a milestone release laster this month.