FilterFactory ff = CommonFactoryFinder.getFilterFactory(null);
BBOX filter = ff.bbox(geom.getLocalName(), nativeEnv.getMinX(),
nativeEnv.getMinY(), nativeEnv.getMaxX(), nativeEnv.getMaxY(), null);
// build an optimized query (only the necessary attributes
DefaultQuery q = new DefaultQuery();
q.setFilter(filter);
q.setPropertyNames(new String[] { geom.getLocalName(), attribute });
// TODO: enable this when JTS learns how to compute centroids
// without triggering the
// generation of Coordinate[] out of the sequences...
// q.setHints(new Hints(Hints.JTS_COORDINATE_SEQUENCE_FACTORY,
// PackedCoordinateSequenceFactory.class));
q.setSortBy(new SortBy[] { ff.sort(attribute, SortOrder.DESCENDING) });
// return the reader
return fs.getFeatures(q).features();
}