Search in sources :

Example 11 with FeatureId

use of org.opengis.filter.identity.FeatureId in project geonetwork by georchestra.

the class SpatialIndexWriter method index.

/**
 * Add a metadata record to the index
 *
 * @param schemasDir
 *            the base directory that contains the different metadata
 *            schemas
 * @param metadata
 *            the metadata
 */
public void index(String schemaDir, String id, Element metadata) throws Exception {
    _lock.lock();
    try {
        _index = null;
        Geometry geometry = extractGeometriesFrom(schemaDir, metadata, _parser);
        if (geometry != null) {
            FeatureCollection<SimpleFeatureType, SimpleFeature> features = FeatureCollections.newCollection();
            Object[] data;
            SimpleFeatureType schema = _featureStore.getSchema();
            if (schema.getDescriptor(0) == schema.getGeometryDescriptor()) {
                data = new Object[] { geometry, id };
            } else {
                data = new Object[] { id, geometry };
            }
            features.add(SimpleFeatureBuilder.build(schema, data, SimpleFeatureBuilder.createDefaultFeatureId()));
            List<FeatureId> ids = _featureStore.addFeatures(features);
            for (FeatureId featureId : ids) {
                String id2 = featureId.getID();
                SpatialFilter.getJCSCache().remove(id2);
            }
            _writes++;
            if (!_autocommit && _writes > _maxWrites) {
                _transaction.commit();
                _writes = 0;
            }
        }
    } finally {
        _lock.unlock();
    }
}
Also used : Geometry(com.vividsolutions.jts.geom.Geometry) FeatureId(org.opengis.filter.identity.FeatureId) SimpleFeatureType(org.opengis.feature.simple.SimpleFeatureType) SimpleFeature(org.opengis.feature.simple.SimpleFeature)

Example 12 with FeatureId

use of org.opengis.filter.identity.FeatureId in project geonetwork by georchestra.

the class SpatialIndexWriter method populateIndex.

private void populateIndex() throws IOException {
    _index = new STRtree();
    FeatureIterator<SimpleFeature> features = _featureStore.getFeatures().features();
    try {
        while (features.hasNext()) {
            SimpleFeature feature = features.next();
            Pair<FeatureId, Object> data = Pair.read(feature.getIdentifier(), feature.getAttribute(_idColumn));
            _index.insert(((Geometry) feature.getDefaultGeometry()).getEnvelopeInternal(), data);
        }
    } finally {
        features.close();
    }
}
Also used : FeatureId(org.opengis.filter.identity.FeatureId) STRtree(com.vividsolutions.jts.index.strtree.STRtree) SimpleFeature(org.opengis.feature.simple.SimpleFeature)

Example 13 with FeatureId

use of org.opengis.filter.identity.FeatureId in project core-geonetwork by geonetwork.

the class SpatialFilter method processCachedFeatures.

private void processCachedFeatures(GroupCacheAccess jcs, Set<FeatureId> matches, Multimap<FeatureId, Integer> docIndexLookup, OpenBitSet bits) {
    for (java.util.Iterator<FeatureId> iter = matches.iterator(); iter.hasNext(); ) {
        FeatureId id = iter.next();
        Geometry geom = (Geometry) jcs.get(id.getID());
        if (geom != null) {
            iter.remove();
            final SimpleFeatureBuilder simpleFeatureBuilder = new SimpleFeatureBuilder(this.sourceAccessor.one().getSchema());
            simpleFeatureBuilder.set(this.sourceAccessor.one().getSchema().getGeometryDescriptor().getName(), geom);
            final SimpleFeature simpleFeature = simpleFeatureBuilder.buildFeature(id.getID());
            evaluateFeature(simpleFeature, bits, docIndexLookup);
        }
    }
}
Also used : FeatureId(org.opengis.filter.identity.FeatureId) Geometry(org.locationtech.jts.geom.Geometry) SimpleFeature(org.opengis.feature.simple.SimpleFeature) SimpleFeatureBuilder(org.geotools.feature.simple.SimpleFeatureBuilder)

Example 14 with FeatureId

use of org.opengis.filter.identity.FeatureId in project core-geonetwork by geonetwork.

the class SpatialFilter method processNonCachedFeature.

private void processNonCachedFeature(JeevesJCS jcs, Set<FeatureId> matches, Multimap<FeatureId, Integer> docIndexLookup, OpenBitSet bits) throws IOException {
    while (!matches.isEmpty()) {
        Id fidFilter;
        if (matches.size() > MAX_FIDS_PER_QUERY) {
            FeatureId[] subset = new FeatureId[MAX_FIDS_PER_QUERY];
            int i = 0;
            Iterator<FeatureId> iter = matches.iterator();
            while (iter.hasNext() && i < MAX_FIDS_PER_QUERY) {
                subset[i] = iter.next();
                iter.remove();
                i++;
            }
            fidFilter = _filterFactory.id(subset);
        } else {
            fidFilter = _filterFactory.id(matches);
            matches = Collections.emptySet();
        }
        FeatureSource<SimpleFeatureType, SimpleFeature> _featureSource = sourceAccessor.one();
        String ftn = _featureSource.getSchema().getName().getLocalPart();
        String[] geomAtt = { _featureSource.getSchema().getGeometryDescriptor().getLocalName() };
        FeatureCollection<SimpleFeatureType, SimpleFeature> features = _featureSource.getFeatures(new org.geotools.data.Query(ftn, fidFilter, geomAtt));
        FeatureIterator<SimpleFeature> iterator = features.features();
        try {
            while (iterator.hasNext()) {
                SimpleFeature feature = iterator.next();
                FeatureId featureId = feature.getIdentifier();
                jcs.put(featureId.getID(), feature.getDefaultGeometry());
                evaluateFeature(feature, bits, docIndexLookup);
            }
        } catch (CacheException e) {
            throw new Error(e);
        } finally {
            iterator.close();
        }
    }
}
Also used : CacheException(org.apache.jcs.access.exception.CacheException) SimpleFeature(org.opengis.feature.simple.SimpleFeature) FeatureId(org.opengis.filter.identity.FeatureId) SimpleFeatureType(org.opengis.feature.simple.SimpleFeatureType) FeatureId(org.opengis.filter.identity.FeatureId) Id(org.opengis.filter.Id)

Example 15 with FeatureId

use of org.opengis.filter.identity.FeatureId in project geonetwork-eea by eea.

the class SpatialFilter method applySpatialFilter.

private OpenBitSet applySpatialFilter(Set<FeatureId> matches, Multimap<FeatureId, Integer> docIndexLookup, OpenBitSet bits) throws IOException {
    JeevesJCS jcs = getJCSCache();
    processCachedFeatures(jcs, matches, docIndexLookup, bits);
    Id fidFilter = _filterFactory.id(matches);
    FeatureSource<SimpleFeatureType, SimpleFeature> _featureSource = sourceAccessor.one();
    String ftn = _featureSource.getSchema().getName().getLocalPart();
    String[] geomAtt = { _featureSource.getSchema().getGeometryDescriptor().getLocalName() };
    FeatureCollection<SimpleFeatureType, SimpleFeature> features = _featureSource.getFeatures(new DefaultQuery(ftn, fidFilter, geomAtt));
    FeatureIterator<SimpleFeature> iterator = features.features();
    try {
        while (iterator.hasNext()) {
            SimpleFeature feature = iterator.next();
            FeatureId featureId = feature.getIdentifier();
            jcs.put(featureId.getID(), feature.getDefaultGeometry());
            if (evaluateFeature(feature)) {
                for (int doc : docIndexLookup.get(featureId)) {
                    bits.set(doc);
                }
            }
        }
    } catch (CacheException e) {
        throw new Error(e);
    } finally {
        iterator.close();
    }
    return bits;
}
Also used : DefaultQuery(org.geotools.data.DefaultQuery) CacheException(org.apache.jcs.access.exception.CacheException) SimpleFeature(org.opengis.feature.simple.SimpleFeature) FeatureId(org.opengis.filter.identity.FeatureId) JeevesJCS(jeeves.JeevesJCS) SimpleFeatureType(org.opengis.feature.simple.SimpleFeatureType) FeatureId(org.opengis.filter.identity.FeatureId) Id(org.opengis.filter.Id)

Aggregations

FeatureId (org.opengis.filter.identity.FeatureId)30 SimpleFeature (org.opengis.feature.simple.SimpleFeature)20 SimpleFeatureType (org.opengis.feature.simple.SimpleFeatureType)12 IOException (java.io.IOException)8 CacheException (org.apache.jcs.access.exception.CacheException)8 Geometry (com.vividsolutions.jts.geom.Geometry)6 Test (org.junit.Test)5 Id (org.opengis.filter.Id)5 TopologyException (com.vividsolutions.jts.geom.TopologyException)4 DefaultTransaction (org.geotools.data.DefaultTransaction)4 Transaction (org.geotools.data.Transaction)4 HashSet (java.util.HashSet)3 Document (org.apache.lucene.document.Document)3 Collector (org.apache.lucene.search.Collector)3 IndexSearcher (org.apache.lucene.search.IndexSearcher)3 Scorer (org.apache.lucene.search.Scorer)3 OpenBitSet (org.apache.lucene.util.OpenBitSet)3 Feature (org.opengis.feature.Feature)3 Optional (com.google.common.base.Optional)2 STRtree (com.vividsolutions.jts.index.strtree.STRtree)2