use of org.geotools.data.sort.SortedFeatureReader in project GeoGig by boundlessgeo.
the class GeogigFeatureSource method getReaderInternal.
@Override
protected FeatureReader<SimpleFeatureType, SimpleFeature> getReaderInternal(final Query query) throws IOException {
FeatureReader<SimpleFeatureType, SimpleFeature> reader;
final boolean naturalOrder = isNaturalOrder(query.getSortBy());
final int startIndex = Optional.fromNullable(query.getStartIndex()).or(Integer.valueOf(0));
final Integer maxFeatures = query.getMaxFeatures() == Integer.MAX_VALUE ? null : query.getMaxFeatures();
final Filter filter = query.getFilter();
final ScreenMap screenMap = (ScreenMap) query.getHints().get(Hints.SCREENMAP);
final String[] propertyNames = query.getPropertyNames();
if (naturalOrder) {
reader = getNativeReader(propertyNames, filter, startIndex, maxFeatures, screenMap);
} else {
reader = getNativeReader(propertyNames, filter, null, null, screenMap);
// sorting
reader = new SortedFeatureReader(DataUtilities.simple(reader), query);
if (startIndex > 0) {
// skip the first n records
for (int i = 0; i < startIndex && reader.hasNext(); i++) {
reader.next();
}
}
if (maxFeatures != null && maxFeatures > 0) {
reader = new MaxFeatureReader<SimpleFeatureType, SimpleFeature>(reader, maxFeatures);
}
}
return reader;
}
Aggregations