use of org.geotoolkit.storage.coverage.DefiningTiledGridCoverageResource in project geotoolkit by Geomatys.
the class InMemoryAggregate method add.
@Override
public synchronized Resource add(Resource resource) throws DataStoreException {
Resource newr;
if (resource instanceof FeatureSet) {
final FeatureSet fs = (FeatureSet) resource;
final InMemoryFeatureSet newres = new InMemoryFeatureSet(fs.getType());
try (Stream<Feature> stream = fs.features(false)) {
newres.add(stream.iterator());
}
newr = newres;
} else if (resource instanceof DefiningTiledGridCoverageResource) {
final DefiningTiledGridCoverageResource cr = (DefiningTiledGridCoverageResource) resource;
final GenericName name = cr.getIdentifier().orElse(null);
newr = new InMemoryTiledGridCoverageResource(name);
} else if (resource instanceof GridCoverageResource && resource instanceof TiledResource) {
final GridCoverageResource cr = (GridCoverageResource) resource;
final GenericName name = cr.getIdentifier().orElse(null);
newr = new InMemoryTiledGridCoverageResource(name);
} else if (resource instanceof GridCoverageResource) {
final GridCoverageResource cr = (GridCoverageResource) resource;
final GenericName name = cr.getIdentifier().orElse(null);
final InMemoryGridCoverageResource newres = new InMemoryGridCoverageResource(name);
newres.write(cr.read(null));
newr = newres;
} else if (resource instanceof DefiningGridCoverageResource) {
final DefiningGridCoverageResource cr = (DefiningGridCoverageResource) resource;
final GenericName name = cr.getIdentifier().orElse(null);
newr = new InMemoryGridCoverageResource(name);
} else if (resource instanceof Aggregate) {
final Aggregate agg = (Aggregate) resource;
final InMemoryAggregate newres = new InMemoryAggregate(agg.getIdentifier().orElse(null));
for (Resource r : agg.components()) {
newres.add(r);
}
newr = newres;
} else {
throw new DataStoreException("Unsupported resource type " + resource);
}
resources.add(newr);
listeners.fire(new AggregationEvent(this, AggregationEvent.TYPE_ADD, newr), AggregationEvent.class);
return newr;
}
Aggregations