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;
}
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;
}
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);
}
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;
}
Aggregations