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