Search in sources :

Example 1 with SortedFeatureReader

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;
}
Also used : SimpleFeatureType(org.opengis.feature.simple.SimpleFeatureType) Filter(org.opengis.filter.Filter) ScreenMap(org.geotools.renderer.ScreenMap) SortedFeatureReader(org.geotools.data.sort.SortedFeatureReader) SimpleFeature(org.opengis.feature.simple.SimpleFeature)

Aggregations

SortedFeatureReader (org.geotools.data.sort.SortedFeatureReader)1 ScreenMap (org.geotools.renderer.ScreenMap)1 SimpleFeature (org.opengis.feature.simple.SimpleFeature)1 SimpleFeatureType (org.opengis.feature.simple.SimpleFeatureType)1 Filter (org.opengis.filter.Filter)1