Search in sources :

Example 1 with AggregationEvent

use of org.geotoolkit.storage.event.AggregationEvent in project geotoolkit by Geomatys.

the class AggregatedCoverageResource method add.

/**
 * Add a new resource in the aggregation.
 * The resource is not copied.
 *
 * @param resource
 * @return the same resource
 * @throws DataStoreException if new resource is incompatible with other resources.
 */
@Override
public synchronized Resource add(Resource resource) throws DataStoreException {
    if (resource instanceof GridCoverageResource) {
        final GridCoverageResource gcr = (GridCoverageResource) resource;
        if (bands.isEmpty()) {
            // first resource in the aggregation
            bands.addAll(toMapping(Arrays.asList(gcr)));
            eraseCaches();
            listeners.fire(new AggregationEvent(this, AggregationEvent.TYPE_ADD, resource), AggregationEvent.class);
            return resource;
        }
        final List<SampleDimension> sampleDimensions = gcr.getSampleDimensions();
        if (sampleDimensions.size() != bands.size()) {
            throw new DataStoreException("Coverage sample dimension size " + sampleDimensions.size() + "do not match bands size " + bands.size());
        }
        for (int i = 0, n = sampleDimensions.size(); i < n; i++) {
            final VirtualBand band = bands.get(i);
            band.sources.add(new Source(gcr, i));
        }
        eraseCaches();
        try {
            initModel();
        } catch (DataStoreException ex) {
            // restore to an usable state
            remove(resource, false);
            throw ex;
        }
        listeners.fire(new AggregationEvent(this, AggregationEvent.TYPE_ADD, resource), AggregationEvent.class);
        return resource;
    } else {
        throw new DataStoreException("Resource must be an instance of GridCoverageResource");
    }
}
Also used : DataStoreException(org.apache.sis.storage.DataStoreException) AggregationEvent(org.geotoolkit.storage.event.AggregationEvent) GridCoverageResource(org.apache.sis.storage.GridCoverageResource) SampleDimension(org.apache.sis.coverage.SampleDimension) Point(java.awt.Point)

Example 2 with AggregationEvent

use of org.geotoolkit.storage.event.AggregationEvent in project geotoolkit by Geomatys.

the class AggregatedCoverageResource method remove.

private synchronized void remove(Resource resource, boolean sendEvent) throws DataStoreException {
    ArgumentChecks.ensureNonNull("resource", resource);
    boolean found = false;
    for (VirtualBand band : bands) {
        final ListIterator<Source> ite = band.sources.listIterator();
        while (ite.hasNext()) {
            Source source = ite.next();
            if (source.resource == resource) {
                found = true;
                ite.remove();
            }
        }
    }
    if (!found) {
        throw new DataStoreException("Resource not found");
    }
    if (sendEvent) {
        listeners.fire(new AggregationEvent(this, AggregationEvent.TYPE_REMOVE, resource), AggregationEvent.class);
    }
    eraseCaches();
}
Also used : DataStoreException(org.apache.sis.storage.DataStoreException) AggregationEvent(org.geotoolkit.storage.event.AggregationEvent)

Example 3 with AggregationEvent

use of org.geotoolkit.storage.event.AggregationEvent in project geotoolkit by Geomatys.

the class AggregatedCoverageResource method removeAll.

/**
 * Remove all resources from aggregation.
 * This method does not delete any data.
 */
public synchronized void removeAll() {
    final Set<Resource> removed = new HashSet<>();
    for (VirtualBand band : bands) {
        for (Source source : band.sources) {
            removed.add(source.resource);
        }
        band.sources.clear();
    }
    listeners.fire(new AggregationEvent(this, AggregationEvent.TYPE_REMOVE, removed.toArray(new Resource[0])), AggregationEvent.class);
    eraseCaches();
}
Also used : AggregationEvent(org.geotoolkit.storage.event.AggregationEvent) Resource(org.apache.sis.storage.Resource) GridCoverageResource(org.apache.sis.storage.GridCoverageResource)

Example 4 with AggregationEvent

use of org.geotoolkit.storage.event.AggregationEvent 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

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