Search in sources :

Example 1 with DefiningTiledGridCoverageResource

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;
}
Also used : DataStoreException(org.apache.sis.storage.DataStoreException) DefiningGridCoverageResource(org.geotoolkit.storage.coverage.DefiningGridCoverageResource) AggregationEvent(org.geotoolkit.storage.event.AggregationEvent) DefiningTiledGridCoverageResource(org.geotoolkit.storage.coverage.DefiningTiledGridCoverageResource) Resource(org.apache.sis.storage.Resource) AbstractResource(org.apache.sis.storage.AbstractResource) TiledResource(org.geotoolkit.storage.multires.TiledResource) GridCoverageResource(org.apache.sis.storage.GridCoverageResource) DefiningGridCoverageResource(org.geotoolkit.storage.coverage.DefiningGridCoverageResource) DefiningTiledGridCoverageResource(org.geotoolkit.storage.coverage.DefiningTiledGridCoverageResource) Feature(org.opengis.feature.Feature) GenericName(org.opengis.util.GenericName) TiledResource(org.geotoolkit.storage.multires.TiledResource) DefiningTiledGridCoverageResource(org.geotoolkit.storage.coverage.DefiningTiledGridCoverageResource) GridCoverageResource(org.apache.sis.storage.GridCoverageResource) DefiningGridCoverageResource(org.geotoolkit.storage.coverage.DefiningGridCoverageResource) FeatureSet(org.apache.sis.storage.FeatureSet) WritableAggregate(org.apache.sis.storage.WritableAggregate) Aggregate(org.apache.sis.storage.Aggregate)

Aggregations

AbstractResource (org.apache.sis.storage.AbstractResource)1 Aggregate (org.apache.sis.storage.Aggregate)1 DataStoreException (org.apache.sis.storage.DataStoreException)1 FeatureSet (org.apache.sis.storage.FeatureSet)1 GridCoverageResource (org.apache.sis.storage.GridCoverageResource)1 Resource (org.apache.sis.storage.Resource)1 WritableAggregate (org.apache.sis.storage.WritableAggregate)1 DefiningGridCoverageResource (org.geotoolkit.storage.coverage.DefiningGridCoverageResource)1 DefiningTiledGridCoverageResource (org.geotoolkit.storage.coverage.DefiningTiledGridCoverageResource)1 AggregationEvent (org.geotoolkit.storage.event.AggregationEvent)1 TiledResource (org.geotoolkit.storage.multires.TiledResource)1 Feature (org.opengis.feature.Feature)1 GenericName (org.opengis.util.GenericName)1