use of org.opengis.filter.identity.Identifier in project incubator-rya by apache.
the class GeoMesaGeoIndexer method deleteStatements.
private void deleteStatements(final Collection<RyaStatement> ryaStatements) throws IOException {
// create a feature collection
final DefaultFeatureCollection featureCollection = new DefaultFeatureCollection();
for (final RyaStatement ryaStatement : ryaStatements) {
final Statement statement = RyaToRdfConversions.convertStatement(ryaStatement);
// if the predicate list is empty, accept all predicates.
// Otherwise, make sure the predicate is on the "valid" list
final boolean isValidPredicate = validPredicates.isEmpty() || validPredicates.contains(statement.getPredicate());
if (isValidPredicate && (statement.getObject() instanceof Literal)) {
try {
final SimpleFeature feature = createFeature(featureType, statement);
featureCollection.add(feature);
} catch (final ParseException e) {
logger.warn("Error getting geo from statement: " + statement.toString(), e);
}
}
}
// remove this feature collection from the store
if (!featureCollection.isEmpty()) {
final Set<Identifier> featureIds = new HashSet<Identifier>();
final FilterFactory filterFactory = CommonFactoryFinder.getFilterFactory(null);
final Set<String> stringIds = DataUtilities.fidSet(featureCollection);
for (final String id : stringIds) {
featureIds.add(filterFactory.featureId(id));
}
final Filter filter = filterFactory.id(featureIds);
featureStore.removeFeatures(filter);
}
}
use of org.opengis.filter.identity.Identifier in project polymap4-core by Polymap4.
the class UnitOfWork method prepare.
/**
* Starts a new {@link Transaction} for the underlying {@link FeatureStore},
* checks concurrent modifications and updates {@link FeatureStore}.
*
* @param monitor
* @throws IOException
* @throws {@link ConcurrentModificationException}
*/
public void prepare(IProgressMonitor monitor) throws ConcurrentModificationException, IOException {
assert tx == null : "Pending transaction found.";
if (modified.isEmpty()) {
return;
}
monitor.beginTask("Prepare commit: " + getLabel(), modified.size());
// set transaction
tx = new DefaultTransaction(getClass().getSimpleName() + "-" + hashCode());
fs.setTransaction(tx);
DefaultFeatureCollection added = new DefaultFeatureCollection();
Set<Identifier> removed = new HashSet();
int count = 0;
for (FeatureBufferState buffered : modified.values()) {
if (monitor.isCanceled()) {
return;
}
if ((++count % 100) == 0) {
monitor.subTask("(" + count + ")");
}
if (buffered.isAdded()) {
// no check if fid was created already since it is propably the 'primary key'
added.add((SimpleFeature) buffered.feature());
} else if (buffered.isModified()) {
checkSubmitModified(buffered);
} else if (buffered.isRemoved()) {
removed.add(buffered.feature().getIdentifier());
} else {
log.warn("Buffered feature is not added/removed/modified!");
}
monitor.worked(1);
}
if (!added.isEmpty()) {
fs.addFeatures(added);
monitor.worked(added.size());
}
if (!removed.isEmpty()) {
fs.removeFeatures(ff.id(removed));
monitor.worked(added.size());
}
monitor.done();
}
use of org.opengis.filter.identity.Identifier in project incubator-rya by apache.
the class GeoWaveGeoIndexer method deleteStatements.
private void deleteStatements(final Collection<RyaStatement> ryaStatements) throws IOException {
// create a feature collection
final DefaultFeatureCollection featureCollection = new DefaultFeatureCollection();
for (final RyaStatement ryaStatement : ryaStatements) {
final Statement statement = RyaToRdfConversions.convertStatement(ryaStatement);
// if the predicate list is empty, accept all predicates.
// Otherwise, make sure the predicate is on the "valid" list
final boolean isValidPredicate = validPredicates.isEmpty() || validPredicates.contains(statement.getPredicate());
if (isValidPredicate && (statement.getObject() instanceof Literal)) {
try {
final SimpleFeature feature = createFeature(featureType, statement);
featureCollection.add(feature);
} catch (final ParseException e) {
logger.warn("Error getting geo from statement: " + statement.toString(), e);
}
}
}
// remove this feature collection from the store
if (!featureCollection.isEmpty()) {
final Set<Identifier> featureIds = new HashSet<Identifier>();
final FilterFactory filterFactory = CommonFactoryFinder.getFilterFactory(null);
final Set<String> stringIds = DataUtilities.fidSet(featureCollection);
for (final String id : stringIds) {
featureIds.add(filterFactory.featureId(id));
}
final String filterString = stringIds.stream().collect(Collectors.joining("','", "'", "'"));
Filter filter = null;
try {
filter = ECQL.toFilter(GEO_ID_ATTRIBUTE + " IN (" + filterString + ")", filterFactory);
} catch (final CQLException e) {
logger.error("Unable to generate filter for deleting the statement.", e);
}
featureStore.removeFeatures(filter);
}
}
Aggregations