I need to iterate through an already sorted SimpleFeatureCollection by theirs geometrie's area.
I figured out that the classic SimpleFeatureIterator comes unsorted and a SortedFeatureIterator( SimpleFeatureIterator iterator, SimpleFeatureType schema,SortBy[] sortBy, int maxFeatures) object exists, which I tried to use.
This sortBy object needs a PropertyName, which must be generated by a FilterFactory I guess. Here is my problem : I cannot find how to set this property to run with a function. I found that org.opengis.filter.expression.Function exists, such as org.opengis.filter.expression.Function.AreaFunction would be appropriate. But as PropertyName and AreaFunction both extends the org.opengis.filter.expression.Expression interface, I cannot find a way to put the function into the SortBy object. I tried couple of things and looked, but found no solution.
Any idea? Am I having the right way of thinking and did I miss a salvation methods? Thanks a lot for your help.
PS: Area is not an attribute of my collection (though about that for a dirty hack solution, but I try to avoid them...)
Code example:
SimpleFeatureIterator sfcIt = sfc.features();
FilterFactory2 ff = FeatureUtilities.DEFAULT_FILTER_FACTORY;
Function function = new AreaFunction();
//first intention
SortBy[] s = {ff.sort(function.toString(), SortOrder.ASCENDING)};
//second intention
Expression expr = ff.function(function.toString(), ff.property("the_geom"));
//desperate intention
final PropertyName propertyName = (PropertyName) function; //utopic
final PropertyName propertyName = ff.arithmeticOperators(true, function); //that isn't the same function object...
SortBy[] sort = { new SortByImpl(expr, SortOrder.ASCENDING) };
SortBy[] sort = { new SortByImpl(propertyName, SortOrder.ASCENDING) };
SortedFeatureIterator sfcIter = new SortedFeatureIterator(sfcIter, sfc.getSchema(), sort, sfc.size());
Thanks for your opinion ! Maxime Colomb