Search in sources :

Example 16 with SpatialMetadata

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;
}
Also used : IIOMetadata(javax.imageio.metadata.IIOMetadata) SpatialMetadata(org.geotoolkit.image.io.metadata.SpatialMetadata)

Example 17 with SpatialMetadata

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;
}
Also used : SpatialMetadata(org.geotoolkit.image.io.metadata.SpatialMetadata) IOException(java.io.IOException) SampleDimension(org.apache.sis.coverage.SampleDimension) ImageMetadataException(org.geotoolkit.image.io.ImageMetadataException) ArrayList(java.util.ArrayList) List(java.util.List) NodeList(org.w3c.dom.NodeList) ImageReader(javax.imageio.ImageReader) SpatialImageReader(org.geotoolkit.image.io.SpatialImageReader) DimensionAccessor(org.geotoolkit.internal.image.io.DimensionAccessor) Map(java.util.Map) HashMap(java.util.HashMap)

Example 18 with SpatialMetadata

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);
    }
}
Also used : IIOMetadata(javax.imageio.metadata.IIOMetadata) SpatialMetadata(org.geotoolkit.image.io.metadata.SpatialMetadata) IOException(java.io.IOException) ImageReader(javax.imageio.ImageReader) SpatialImageReader(org.geotoolkit.image.io.SpatialImageReader)

Example 19 with SpatialMetadata

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;
}
Also used : SpatialMetadata(org.geotoolkit.image.io.metadata.SpatialMetadata)

Example 20 with SpatialMetadata

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;
}
Also used : SpatialMetadata(org.geotoolkit.image.io.metadata.SpatialMetadata)

Aggregations

SpatialMetadata (org.geotoolkit.image.io.metadata.SpatialMetadata)29 DimensionAccessor (org.geotoolkit.internal.image.io.DimensionAccessor)9 IOException (java.io.IOException)6 GridDomainAccessor (org.geotoolkit.internal.image.io.GridDomainAccessor)6 CoordinateReferenceSystem (org.opengis.referencing.crs.CoordinateReferenceSystem)5 IIOMetadata (javax.imageio.metadata.IIOMetadata)4 SampleDimension (org.apache.sis.coverage.SampleDimension)4 SpatialImageReader (org.geotoolkit.image.io.SpatialImageReader)4 ReferencingBuilder (org.geotoolkit.image.io.metadata.ReferencingBuilder)4 RectifiedGrid (org.opengis.coverage.grid.RectifiedGrid)4 FactoryException (org.opengis.util.FactoryException)4 AffineTransform (java.awt.geom.AffineTransform)3 ImageReader (javax.imageio.ImageReader)3 MetadataHelper (org.geotoolkit.image.io.metadata.MetadataHelper)3 RenderedImage (java.awt.image.RenderedImage)2 File (java.io.File)2 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2 List (java.util.List)2 Map (java.util.Map)2