use of org.opengis.feature.simple.SimpleFeatureType 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.opengis.feature.simple.SimpleFeatureType in project GeoGig by boundlessgeo.
the class GeogigFeatureSource method buildFeatureType.
@Override
protected SimpleFeatureType buildFeatureType() throws IOException {
SimpleFeatureType featureType = getNativeType();
final Name name = featureType.getName();
final Name assignedName = getEntry().getName();
if (assignedName.getNamespaceURI() != null && !assignedName.equals(name)) {
SimpleFeatureTypeBuilder builder = new SimpleFeatureTypeBuilder();
builder.init(featureType);
builder.setName(assignedName);
featureType = builder.buildFeatureType();
}
return featureType;
}
use of org.opengis.feature.simple.SimpleFeatureType 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.opengis.feature.simple.SimpleFeatureType in project GeoGig by boundlessgeo.
the class ImportOp method getFeatureSource.
@SuppressWarnings({ "rawtypes", "unchecked" })
private FeatureSource getFeatureSource(String typeName) {
FeatureSource featureSource;
try {
featureSource = dataStore.getFeatureSource(typeName);
} catch (Exception e) {
throw new GeoToolsOpException(StatusCode.UNABLE_TO_GET_FEATURES);
}
return new ForwardingFeatureSource(featureSource) {
@Override
public FeatureCollection getFeatures(Query query) throws IOException {
final FeatureCollection features = super.getFeatures(query);
return new ForwardingFeatureCollection(features) {
@Override
public FeatureIterator features() {
final FeatureType featureType = getSchema();
final String fidPrefix = featureType.getName().getLocalPart() + ".";
FeatureIterator iterator = delegate.features();
return new FidAndFtReplacerIterator(iterator, fidAttribute, fidPrefix, (SimpleFeatureType) featureType);
}
};
}
};
}
use of org.opengis.feature.simple.SimpleFeatureType in project GeoGig by boundlessgeo.
the class GeogigFeatureStore method getWriterInternal.
@Override
protected FeatureWriter<SimpleFeatureType, SimpleFeature> getWriterInternal(Query query, final int flags) throws IOException {
Preconditions.checkArgument(flags != 0, "no write flags set");
Preconditions.checkState(getDataStore().isAllowTransactions(), "Transactions not supported; head is not a local branch");
FeatureReader<SimpleFeatureType, SimpleFeature> features;
if ((flags | WRITER_UPDATE) == WRITER_UPDATE) {
features = delegate.getReader(query);
} else {
features = new EmptyFeatureReader<SimpleFeatureType, SimpleFeature>(getSchema());
}
String path = delegate.getTypeTreePath();
WorkingTree wtree = getFeatureSource().getWorkingTree();
GeoGigFeatureWriter writer;
if ((flags | WRITER_ADD) == WRITER_ADD) {
writer = GeoGigFeatureWriter.createAppendable(features, path, wtree);
} else {
writer = GeoGigFeatureWriter.create(features, path, wtree);
}
return writer;
}
Aggregations