Search in sources :

Example 1 with Identifier

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);
    }
}
Also used : RyaStatement(org.apache.rya.api.domain.RyaStatement) Statement(org.openrdf.model.Statement) RyaStatement(org.apache.rya.api.domain.RyaStatement) SimpleFeature(org.opengis.feature.simple.SimpleFeature) FilterFactory(org.opengis.filter.FilterFactory) Identifier(org.opengis.filter.identity.Identifier) Filter(org.opengis.filter.Filter) Literal(org.openrdf.model.Literal) ParseException(com.vividsolutions.jts.io.ParseException) DefaultFeatureCollection(org.geotools.feature.DefaultFeatureCollection) HashSet(java.util.HashSet)

Example 2 with Identifier

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();
}
Also used : Identifier(org.opengis.filter.identity.Identifier) DefaultTransaction(org.geotools.data.DefaultTransaction) DefaultFeatureCollection(org.geotools.feature.DefaultFeatureCollection) HashSet(java.util.HashSet)

Example 3 with Identifier

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);
    }
}
Also used : RyaStatement(org.apache.rya.api.domain.RyaStatement) Statement(org.openrdf.model.Statement) RyaStatement(org.apache.rya.api.domain.RyaStatement) SimpleFeature(org.opengis.feature.simple.SimpleFeature) FilterFactory(org.opengis.filter.FilterFactory) Identifier(org.opengis.filter.identity.Identifier) Filter(org.opengis.filter.Filter) Literal(org.openrdf.model.Literal) ParseException(com.vividsolutions.jts.io.ParseException) CQLException(org.geotools.filter.text.cql2.CQLException) DefaultFeatureCollection(org.geotools.feature.DefaultFeatureCollection) HashSet(java.util.HashSet)

Aggregations

HashSet (java.util.HashSet)3 DefaultFeatureCollection (org.geotools.feature.DefaultFeatureCollection)3 Identifier (org.opengis.filter.identity.Identifier)3 ParseException (com.vividsolutions.jts.io.ParseException)2 RyaStatement (org.apache.rya.api.domain.RyaStatement)2 SimpleFeature (org.opengis.feature.simple.SimpleFeature)2 Filter (org.opengis.filter.Filter)2 FilterFactory (org.opengis.filter.FilterFactory)2 Literal (org.openrdf.model.Literal)2 Statement (org.openrdf.model.Statement)2 DefaultTransaction (org.geotools.data.DefaultTransaction)1 CQLException (org.geotools.filter.text.cql2.CQLException)1