Today we are going to introduce you our latest contribution to GeoServer, WFS paging and sorting for retrieving features.
First off, let's take a step back and see what sorting and paging support is available in the official OGC protocols:
- Neither WMS 1.1 nor WMS 1.3 (or SLD/SE for that matter), have any ability to order the results so that features are painted in a certain order. If features can be organized in categories filters and FeatureTypeStyle elements can do the trick, but that won't work over continous fields
- Same goes for WPS 1.0, which can return significant amounts of vector data that might be useful to page over
- WFS 1.0 does not support either, WFS 1.1 supports sorting, WFS 2.0 supports sorting and paging via the sortBy and startIndex/maxFeature parameters
The last stable GeoServer release does not support WFS 2.0, and allows for sorting only on DBMS based stores. In our latest contribution to the stable series we removed all limitations concerning WFS paging and sorting support:
- WFS 1.0 and 1.1 can now support sorting on top of each and every store kind, using the sortBy parameter as a vendor extension
- WFS 1.0 and 1.1 support paging on top of each and every store, using the startIndex/maxFeatures parameters
Protocol and paging wise we back-ported the work added on trunk along with WFS 2.0 support, and then we merged in some previous work on generic sorting we did for the aggregating store.
Technically speaking, in case the store does not support sorting natively (e.g., shapefile) we gather the features into an optimized merge/sort algorithm that never keeps more than 1000 features in memory, and uses secondary storage to scale up to larger result sets.
But, enough talking, let's see some examples against the states demo layer, using the CSV as the output format for brevity.
First ten features:
states.2,District of Columbia,606900
The next 10 features:
The first ten states with most people (sort on PERSONS, descending):
The second page of the above result set:
These modifications are already available in the GeoServer 2.1.3 release.
There is more work to be done in this area, ordering features before paiting them in WMS, and paging WPS results would both be nice additions. Interested? Let us know!
The GeoSolutions team,