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