Search in sources :

Example 1 with ScreenMap

use of org.geotools.renderer.ScreenMap 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)

Example 2 with ScreenMap

use of org.geotools.renderer.ScreenMap in project GeoGig by boundlessgeo.

the class GeogigFeatureSource method getCountInternal.

@Override
protected int getCountInternal(Query query) throws IOException {
    final Filter filter = (Filter) query.getFilter().accept(new SimplifyingFilterVisitor(), null);
    if (Filter.EXCLUDE.equals(filter)) {
        return 0;
    }
    final Integer offset = query.getStartIndex();
    final Integer maxFeatures = query.getMaxFeatures() == Integer.MAX_VALUE ? null : query.getMaxFeatures();
    int size;
    if (Filter.INCLUDE.equals(filter) && oldRoot == null && ChangeType.ADDED.equals(changeType())) {
        RevTree tree = getTypeTree();
        size = (int) tree.size();
        if (offset != null) {
            size = size - offset.intValue();
        }
        if (maxFeatures != null) {
            size = Math.min(size, maxFeatures.intValue());
        }
        return size;
    }
    FeatureReader<SimpleFeatureType, SimpleFeature> features;
    if (isNaturalOrder(query.getSortBy())) {
        ScreenMap screenMap = (ScreenMap) query.getHints().get(Hints.SCREENMAP);
        features = getNativeReader(Query.NO_NAMES, filter, offset, maxFeatures, screenMap);
    } else {
        features = getReader(query);
    }
    int count = 0;
    try {
        while (features.hasNext()) {
            features.next();
            count++;
        }
    } finally {
        features.close();
    }
    return count;
}
Also used : SimpleFeatureType(org.opengis.feature.simple.SimpleFeatureType) Filter(org.opengis.filter.Filter) ScreenMap(org.geotools.renderer.ScreenMap) SimplifyingFilterVisitor(org.geotools.filter.visitor.SimplifyingFilterVisitor) RevTree(org.locationtech.geogig.api.RevTree) SimpleFeature(org.opengis.feature.simple.SimpleFeature)

Example 3 with ScreenMap

use of org.geotools.renderer.ScreenMap in project GeoGig by boundlessgeo.

the class GeogigFeatureSource method getBoundsInternal.

@Override
protected ReferencedEnvelope getBoundsInternal(Query query) throws IOException {
    final Filter filter = (Filter) query.getFilter().accept(new SimplifyingFilterVisitor(), null);
    final CoordinateReferenceSystem crs = getSchema().getCoordinateReferenceSystem();
    if (Filter.INCLUDE.equals(filter) && oldRoot == null && ChangeType.ADDED.equals(changeType())) {
        NodeRef typeRef = getTypeRef();
        ReferencedEnvelope bounds = new ReferencedEnvelope(crs);
        typeRef.getNode().expand(bounds);
        return bounds;
    }
    if (Filter.EXCLUDE.equals(filter)) {
        return ReferencedEnvelope.create(crs);
    }
    FeatureReader<SimpleFeatureType, SimpleFeature> features;
    if (isNaturalOrder(query.getSortBy())) {
        Integer offset = query.getStartIndex();
        Integer maxFeatures = query.getMaxFeatures() == Integer.MAX_VALUE ? null : query.getMaxFeatures();
        ScreenMap screenMap = (ScreenMap) query.getHints().get(Hints.SCREENMAP);
        features = getNativeReader(Query.NO_NAMES, filter, offset, maxFeatures, screenMap);
    } else {
        features = getReader(query);
    }
    ReferencedEnvelope bounds = new ReferencedEnvelope(crs);
    try {
        while (features.hasNext()) {
            bounds.expandToInclude((ReferencedEnvelope) features.next().getBounds());
        }
    } finally {
        features.close();
    }
    return bounds;
}
Also used : NodeRef(org.locationtech.geogig.api.NodeRef) ReferencedEnvelope(org.geotools.geometry.jts.ReferencedEnvelope) SimpleFeatureType(org.opengis.feature.simple.SimpleFeatureType) Filter(org.opengis.filter.Filter) ScreenMap(org.geotools.renderer.ScreenMap) CoordinateReferenceSystem(org.opengis.referencing.crs.CoordinateReferenceSystem) SimplifyingFilterVisitor(org.geotools.filter.visitor.SimplifyingFilterVisitor) SimpleFeature(org.opengis.feature.simple.SimpleFeature)

Aggregations

ScreenMap (org.geotools.renderer.ScreenMap)3 SimpleFeature (org.opengis.feature.simple.SimpleFeature)3 SimpleFeatureType (org.opengis.feature.simple.SimpleFeatureType)3 Filter (org.opengis.filter.Filter)3 SimplifyingFilterVisitor (org.geotools.filter.visitor.SimplifyingFilterVisitor)2 SortedFeatureReader (org.geotools.data.sort.SortedFeatureReader)1 ReferencedEnvelope (org.geotools.geometry.jts.ReferencedEnvelope)1 NodeRef (org.locationtech.geogig.api.NodeRef)1 RevTree (org.locationtech.geogig.api.RevTree)1 CoordinateReferenceSystem (org.opengis.referencing.crs.CoordinateReferenceSystem)1