Search in sources :

Example 11 with ImageCoverageReader

use of org.geotoolkit.coverage.io.ImageCoverageReader in project geotoolkit by Geomatys.

the class LandsatResource method getSampleDimensions.

/**
 * {@inheritDoc }
 *
 * @param index 0, 1 or 2 for respectively ({@link LandsatConstants#REFLECTIVE_LABEL},
 * {@link LandsatConstants#PANCHROMATIC_LABEL}, {@link LandsatConstants#THERMAL_LABEL}).
 */
@Override
public List<SampleDimension> getSampleDimensions() throws DataStoreException, CancellationException {
    if (gsdLandsat != null) {
        return gsdLandsat;
    }
    final int[] bandId = group.bands;
    final List<SampleDimension> gList = new ArrayList<>();
    for (int i : bandId) {
        final String bandName = metadataParser.getValue(true, BAND_NAME_LABEL + i);
        final Path resolve = parentDirectory.resolve(bandName);
        final ImageCoverageReader imageCoverageReader = new ImageCoverageReader();
        try {
            final ImageReader tiffReader = TIFF_SPI.createReaderInstance();
            tiffReader.setInput(resolve);
            imageCoverageReader.setInput(tiffReader);
            final List<SampleDimension> candidates = imageCoverageReader.getSampleDimensions();
            if (candidates != null)
                gList.addAll(candidates);
        } catch (IOException ex) {
            throw new DataStoreException(ex);
        } finally {
            imageCoverageReader.dispose();
        }
    }
    gsdLandsat = gList;
    return gsdLandsat;
}
Also used : Path(java.nio.file.Path) ImageCoverageReader(org.geotoolkit.coverage.io.ImageCoverageReader) DataStoreException(org.apache.sis.storage.DataStoreException) ArrayList(java.util.ArrayList) IOException(java.io.IOException) TiffImageReader(org.geotoolkit.image.io.plugin.TiffImageReader) ImageReader(javax.imageio.ImageReader) SampleDimension(org.apache.sis.coverage.SampleDimension)

Aggregations

ImageCoverageReader (org.geotoolkit.coverage.io.ImageCoverageReader)11 GridCoverage (org.apache.sis.coverage.grid.GridCoverage)7 DataStoreException (org.apache.sis.storage.DataStoreException)6 File (java.io.File)4 IOException (java.io.IOException)4 ImageReader (javax.imageio.ImageReader)4 GridCoverageReadParam (org.geotoolkit.coverage.io.GridCoverageReadParam)4 InputStream (java.io.InputStream)3 MalformedURLException (java.net.MalformedURLException)3 Path (java.nio.file.Path)3 UnconvertibleObjectException (org.apache.sis.util.UnconvertibleObjectException)3 RenderedImage (java.awt.image.RenderedImage)2 ByteArrayInputStream (java.io.ByteArrayInputStream)2 SampleDimension (org.apache.sis.coverage.SampleDimension)2 GeneralEnvelope (org.apache.sis.geometry.GeneralEnvelope)2 MapLayer (org.apache.sis.portrayal.MapLayer)2 TiffImageReader (org.geotoolkit.image.io.plugin.TiffImageReader)2 Test (org.junit.Test)2 Envelope (org.opengis.geometry.Envelope)2 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1