use of org.geotoolkit.image.io.metadata.SpatialMetadata in project geotoolkit by Geomatys.
the class ImageCoverageReader method getImageMetadata.
/**
* Gets the spatial metadata from the given image reader, or return {@code null}
* if none were found. This method asks only for the metadata nodes listed in the
* {@link #METADATA_NODES} collection. Note however that most {@link ImageReader}
* implementations will return all metadata anyway.
*
* @param imageReader The image reader from which to get the metadata.
* @param index The index of the image to be queried.
* @return The metadata of the given index, or {@code null} if none.
* @throws IOException If an error occurred while reading the metadata.
*
* @see #getCoverageMetadata(int)
*/
private SpatialMetadata getImageMetadata(final ImageReader imageReader, final int index) throws IOException {
if (imageMetadataIndex != index) {
final IIOMetadata metadata = imageReader.getImageMetadata(index, GEOTK_FORMAT_NAME, METADATA_NODES);
if (metadata == null || metadata instanceof SpatialMetadata) {
imageMetadata = (SpatialMetadata) metadata;
} else {
imageMetadata = new SpatialMetadata(false, imageReader, metadata);
}
imageMetadataIndex = index;
}
return imageMetadata;
}
use of org.geotoolkit.image.io.metadata.SpatialMetadata in project geotoolkit by Geomatys.
the class ImageCoverageReader method getSampleDimensions.
public List<SampleDimension> getSampleDimensions(final int index) throws CoverageStoreException {
List<SampleDimension> sd = getCached(sampleDimensions, index);
if (sd == null) {
// Protect from changes.
final ImageReader imageReader = this.imageReader;
if (imageReader == null) {
throw new IllegalStateException(formatErrorMessage(Errors.Keys.NoImageInput));
}
/*
* Get the required information from the SpatialMetadata, if any.
* Here we just collect them - they will be processed by MetadataHelper.
*/
List<org.geotoolkit.image.io.metadata.SampleDimension> bands = null;
try {
final SpatialMetadata metadata = getImageMetadata(imageReader, index);
if (metadata != null && hasDimensionMetadata(metadata)) {
DimensionAccessor accessor = new DimensionAccessor(metadata);
sd = accessor.getSampleDimensions();
if (sd != null)
return sd;
bands = metadata.getListForType(org.geotoolkit.image.io.metadata.SampleDimension.class);
}
if (isNullOrEmpty(bands)) {
// See the convention documented below.
sd = Collections.emptyList();
} else
try {
// MetadataHelper default implementation returns an unmodifiable list.
sd = getMetadataHelper().getSampleDimensions(bands);
} catch (ImageMetadataException e) {
throw new CoverageStoreException(formatErrorMessage(e), e);
}
if (sd == null || sd.isEmpty()) {
// Create mock dimension, because new Coverage API does not allow null sample dimensions.
sd = mock(getDataModel(imageReader, index));
}
} catch (IOException e) {
throw new CoverageStoreException(formatErrorMessage(e), e);
}
Map.Entry<Map<Integer, List<SampleDimension>>, List<SampleDimension>> entry = setCached(sd, sampleDimensions, 0);
sampleDimensions = entry.getKey();
sd = entry.getValue();
}
return sd;
}
use of org.geotoolkit.image.io.metadata.SpatialMetadata in project geotoolkit by Geomatys.
the class ImageCoverageReader method getCoverageMetadata.
/**
* Returns the metadata associated with the given coverage, or {@code null} if none.
* The default implementation delegates to the {@linkplain #imageReader image reader},
* wrapping the {@link IIOMetadata} in a {@code SpatialMetadata} if necessary.
*
* @return The metadata associated with the given coverage, or {@code null}.
* @throws CoverageStoreException if an error occurs reading the information from the input source.
*
* @since 3.14
*/
public SpatialMetadata getCoverageMetadata() throws CoverageStoreException {
final int index = 0;
// Protect from changes.
final ImageReader imageReader = this.imageReader;
if (imageReader == null) {
throw new IllegalStateException(formatErrorMessage(Errors.Keys.NoImageInput));
}
try {
final IIOMetadata metadata = imageReader.getImageMetadata(index);
if (metadata instanceof SpatialMetadata) {
return (SpatialMetadata) metadata;
} else if (metadata != null) {
return new SpatialMetadata(false, imageReader, metadata);
} else {
return null;
}
} catch (IOException e) {
throw new CoverageStoreException(formatErrorMessage(e), e);
}
}
use of org.geotoolkit.image.io.metadata.SpatialMetadata in project geotoolkit by Geomatys.
the class ImageReaderAdapter method getImageMetadata.
/**
* Returns metadata associated with the given image. The default implementation ensures
* (indirectly, though a call to {@link #getNumImages(boolean)}) that the {@linkplain #main}
* reader is initialized, then delegates to the {@linkplain #createMetadata(int)} method as
* documented in the {@linkplain SpatialImageReader#getImageMetadata(int) super-class method}.
* <p>
* Subclasses should consider overriding the {@link #createMetadata(int)} method instead
* than this one.
*/
@Override
public SpatialMetadata getImageMetadata(final int imageIndex) throws IOException {
final SpatialMetadata metadata = super.getImageMetadata(imageIndex);
sync();
return metadata;
}
use of org.geotoolkit.image.io.metadata.SpatialMetadata in project geotoolkit by Geomatys.
the class ImageReaderAdapter method getStreamMetadata.
/**
* Returns metadata associated with the input source as a whole. The default implementation
* ensures that the {@linkplain #main} reader is initialized, then delegates to the
* {@linkplain #createMetadata(int)} method as documented in the
* {@linkplain SpatialImageReader#getStreamMetadata() super-class method}.
* <p>
* Subclasses should consider overriding the {@link #createMetadata(int)} method instead
* than this one.
*/
@Override
public SpatialMetadata getStreamMetadata() throws IOException {
ensureInitialized();
final SpatialMetadata metadata = super.getStreamMetadata();
sync();
return metadata;
}
Aggregations