Search in sources :

Example 6 with GridCoverageResource

use of org.apache.sis.storage.GridCoverageResource in project sis by apache.

the class Reader method getImage.

/**
 * Returns the potentially pyramided <cite>Image File Directories</cite> (IFDs) at the given index.
 * If the pyramid has already been initialized, then it is returned.
 * Otherwise this method initializes the pyramid now and returns it.
 *
 * <p>This method assumes that the first IFD is the full resolution image and all following IFDs having
 * {@link ImageFileDirectory#isReducedResolution()} flag set are the same image at lower resolutions.
 * This is the <cite>cloud optimized GeoTIFF</cite> convention.</p>
 *
 * @return the pyramid if we found it, or {@code null} if there is no more pyramid at the given index.
 * @throws ArithmeticException if the pointer to a next IFD is too far.
 */
final GridCoverageResource getImage(final int index) throws IOException, DataStoreException {
    while (index >= images.size()) {
        int imageIndex = images.size();
        ImageFileDirectory fullResolution = lastIFD;
        if (fullResolution == null) {
            fullResolution = getImageFileDirectory(imageIndex);
            if (fullResolution == null) {
                return null;
            }
        }
        // Clear now in case of error.
        lastIFD = null;
        // In case next image is full-resolution.
        imageIndex++;
        ImageFileDirectory image;
        final List<ImageFileDirectory> overviews = new ArrayList<>();
        while ((image = getImageFileDirectory(imageIndex)) != null) {
            if (image.isReducedResolution()) {
                overviews.add(image);
            } else {
                lastIFD = image;
                break;
            }
        }
        /*
             * All pyramid levels have been read. If there is only one level,
             * use the image directly. Otherwise create the pyramid.
             */
        if (overviews.isEmpty()) {
            images.add(fullResolution);
        } else {
            overviews.add(0, fullResolution);
            images.add(new MultiResolutionImage(overviews));
        }
    }
    final GridCoverageResource image = images.get(index);
    if (image instanceof ImageFileDirectory) {
        resolveDeferredEntries((ImageFileDirectory) image);
    }
    return image;
}
Also used : ArrayList(java.util.ArrayList) GridCoverageResource(org.apache.sis.storage.GridCoverageResource)

Example 7 with GridCoverageResource

use of org.apache.sis.storage.GridCoverageResource in project sis by apache.

the class GridResourceWrapper method addListener.

/*
     * Do not override `subset(Query)`. We want the subset to delegate to this wrapper.
     */
/**
 * Registers a listener to notify when the specified kind of event occurs in this resource or in children.
 * The default implementation delegates to the source.
 *
 * @param  <T>        compile-time value of the {@code eventType} argument.
 * @param  listener   listener to notify about events.
 * @param  eventType  type of {@link StoreEvent} to listen (can not be {@code null}).
 */
@Override
public <T extends StoreEvent> void addListener(Class<T> eventType, StoreListener<? super T> listener) {
    final GridCoverageResource source;
    try {
        source = source();
    } catch (DataStoreException e) {
        throw new BackingStoreException(e);
    }
    source.addListener(eventType, listener);
}
Also used : DataStoreException(org.apache.sis.storage.DataStoreException) GridCoverageResource(org.apache.sis.storage.GridCoverageResource) BackingStoreException(org.apache.sis.util.collection.BackingStoreException)

Example 8 with GridCoverageResource

use of org.apache.sis.storage.GridCoverageResource in project sis by apache.

the class CoverageControls method load.

/**
 * Sets the view content to the given coverage.
 * This method is invoked when a new source of data (either a resource or a coverage) is specified,
 * or when a previously hidden view is made visible. This implementation starts a background thread.
 *
 * @param  request  the resource or coverage to set, or {@code null} for clearing the view.
 */
@Override
final void load(final ImageRequest request) {
    final GridCoverageResource resource;
    final GridCoverage coverage;
    if (request != null) {
        resource = request.resource;
        coverage = request.getCoverage().orElse(null);
    } else {
        resource = null;
        coverage = null;
    }
    view.setCoverage(resource, coverage);
}
Also used : GridCoverage(org.apache.sis.coverage.grid.GridCoverage) GridCoverageResource(org.apache.sis.storage.GridCoverageResource)

Example 9 with GridCoverageResource

use of org.apache.sis.storage.GridCoverageResource in project sis by apache.

the class GridResourceWrapper method closeDataStore.

/**
 * Closes the data store associated to the resource, then discards the resource.
 * This method does not verify if the data store is still used by other resources.
 *
 * @throws DataStoreException if an error occurred while closing the data store.
 */
public final void closeDataStore() throws DataStoreException {
    final GridCoverageResource s = source;
    source = null;
    if (s instanceof StoreResource) {
        ((StoreResource) s).getOriginator().close();
    }
}
Also used : GridCoverageResource(org.apache.sis.storage.GridCoverageResource)

Aggregations

GridCoverageResource (org.apache.sis.storage.GridCoverageResource)9 DataStoreException (org.apache.sis.storage.DataStoreException)3 IOException (java.io.IOException)2 GridCoverage (org.apache.sis.coverage.grid.GridCoverage)2 CoverageExplorer (org.apache.sis.gui.coverage.CoverageExplorer)2 FeatureSet (org.apache.sis.storage.FeatureSet)2 BackingStoreException (org.apache.sis.util.collection.BackingStoreException)2 ArrayList (java.util.ArrayList)1 TitledPane (javafx.scene.control.TitledPane)1 Region (javafx.scene.layout.Region)1 ImageRequest (org.apache.sis.gui.coverage.ImageRequest)1 MetadataBuilder (org.apache.sis.internal.storage.MetadataBuilder)1 DefaultMetadata (org.apache.sis.metadata.iso.DefaultMetadata)1 MetadataStoreException (org.apache.sis.metadata.sql.MetadataStoreException)1 DataStoreClosedException (org.apache.sis.storage.DataStoreClosedException)1 IllegalNameException (org.apache.sis.storage.IllegalNameException)1 Resource (org.apache.sis.storage.Resource)1