Search in sources :

Example 1 with SimplifyingFilterVisitor

use of org.geotools.filter.visitor.SimplifyingFilterVisitor 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 2 with SimplifyingFilterVisitor

use of org.geotools.filter.visitor.SimplifyingFilterVisitor in project GeoGig by boundlessgeo.

the class GeogigFeatureSource method getNativeReader.

/**
     * @param propertyNames properties to retrieve, empty array for no properties at all
     *        {@link Query#NO_NAMES}, {@code null} means all properties {@link Query#ALL_NAMES}
     */
private FeatureReader<SimpleFeatureType, SimpleFeature> getNativeReader(@Nullable String[] propertyNames, Filter filter, @Nullable Integer offset, @Nullable Integer maxFeatures, @Nullable final ScreenMap screenMap) {
    if (screenMap == null) {
        LOGGER.trace("GeoGigFeatureSource.getNativeReader: no screenMap provided");
    } else {
        LOGGER.trace("GeoGigFeatureSource.getNativeReader: using screenMap filter");
    }
    LOGGER.trace("Query filter: {}", filter);
    filter = (Filter) filter.accept(new SimplifyingFilterVisitor(), null);
    LOGGER.trace("Simplified filter: {}", filter);
    GeogigFeatureReader<SimpleFeatureType, SimpleFeature> nativeReader;
    final String rootRef = getRootRef();
    final String featureTypeTreePath = getTypeTreePath();
    final SimpleFeatureType fullType = getSchema();
    boolean ignoreAttributes = false;
    if (propertyNames != null && propertyNames.length == 0) {
        String[] inProcessFilteringAttributes = Filters.attributeNames(filter, fullType);
        ignoreAttributes = inProcessFilteringAttributes.length == 0;
    }
    final String compareRootRef = oldRoot();
    final GeoGigDataStore.ChangeType changeType = changeType();
    final Context context = getCommandLocator();
    nativeReader = new GeogigFeatureReader<SimpleFeatureType, SimpleFeature>(context, fullType, filter, featureTypeTreePath, rootRef, compareRootRef, changeType, offset, maxFeatures, screenMap, ignoreAttributes);
    return nativeReader;
}
Also used : Context(org.locationtech.geogig.api.Context) SimpleFeatureType(org.opengis.feature.simple.SimpleFeatureType) ChangeType(org.locationtech.geogig.geotools.data.GeoGigDataStore.ChangeType) SimplifyingFilterVisitor(org.geotools.filter.visitor.SimplifyingFilterVisitor) SimpleFeature(org.opengis.feature.simple.SimpleFeature)

Example 3 with SimplifyingFilterVisitor

use of org.geotools.filter.visitor.SimplifyingFilterVisitor in project GeoGig by boundlessgeo.

the class GeogigFeatureStore method removeFeatures.

@Override
public void removeFeatures(Filter filter) throws IOException {
    Preconditions.checkState(getDataStore().isAllowTransactions(), "Transactions not supported; head is not a local branch");
    final WorkingTree workingTree = delegate.getWorkingTree();
    final String typeTreePath = delegate.getTypeTreePath();
    filter = (Filter) filter.accept(new SimplifyingFilterVisitor(), null);
    if (Filter.INCLUDE.equals(filter)) {
        workingTree.delete(typeTreePath);
        return;
    }
    if (Filter.EXCLUDE.equals(filter)) {
        return;
    }
    Iterator<SimpleFeature> featureIterator = featureIterator(filter);
    Iterator<String> affectedFeaturePaths = Iterators.transform(featureIterator, new Function<SimpleFeature, String>() {

        @Override
        public String apply(SimpleFeature input) {
            String fid = input.getID();
            return NodeRef.appendChild(typeTreePath, fid);
        }
    });
    workingTree.delete(affectedFeaturePaths);
}
Also used : WorkingTree(org.locationtech.geogig.repository.WorkingTree) SimplifyingFilterVisitor(org.geotools.filter.visitor.SimplifyingFilterVisitor) SimpleFeature(org.opengis.feature.simple.SimpleFeature)

Example 4 with SimplifyingFilterVisitor

use of org.geotools.filter.visitor.SimplifyingFilterVisitor 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

SimplifyingFilterVisitor (org.geotools.filter.visitor.SimplifyingFilterVisitor)4 SimpleFeature (org.opengis.feature.simple.SimpleFeature)4 SimpleFeatureType (org.opengis.feature.simple.SimpleFeatureType)3 ScreenMap (org.geotools.renderer.ScreenMap)2 Filter (org.opengis.filter.Filter)2 ReferencedEnvelope (org.geotools.geometry.jts.ReferencedEnvelope)1 Context (org.locationtech.geogig.api.Context)1 NodeRef (org.locationtech.geogig.api.NodeRef)1 RevTree (org.locationtech.geogig.api.RevTree)1 ChangeType (org.locationtech.geogig.geotools.data.GeoGigDataStore.ChangeType)1 WorkingTree (org.locationtech.geogig.repository.WorkingTree)1 CoordinateReferenceSystem (org.opengis.referencing.crs.CoordinateReferenceSystem)1