Search in sources :

Example 1 with TiffImageReader

use of org.geotoolkit.image.io.plugin.TiffImageReader in project geotoolkit by Geomatys.

the class LandsatResource method readGridSlice.

@Override
protected GridCoverage readGridSlice(GridGeometry resultGrid, int[] areaLower, int[] areaUpper, int[] subsampling, int... range) throws DataStoreException {
    GridGeometry geometry = getGridGeometry(getGridGeometry(), areaLower, areaUpper, subsampling);
    // -- get all needed band to build coverage (see Landsat spec)
    final int[] bandId = group.bands;
    final RenderedImage[] bands = new RenderedImage[bandId.length];
    try {
        int currentCov = 0;
        for (int i : bandId) {
            // -- get band name
            final String bandName = metadataParser.getValue(true, BAND_NAME_LABEL + i);
            // -- add to coverage name
            final Path band = parentDirectory.resolve(bandName);
            // -- reader config
            final TiffImageReader tiffReader = (TiffImageReader) TIFF_SPI.createReaderInstance();
            tiffReader.setInput(band);
            Rectangle rec = new Rectangle(areaLower[0], areaLower[1], areaUpper[0] - areaLower[0], areaUpper[1] - areaLower[1]);
            final ImageReadParam readParam = tiffReader.getDefaultReadParam();
            readParam.setSourceRegion(rec);
            readParam.setSourceSubsampling(subsampling[0], subsampling[1], 0, 0);
            try {
                BufferedImage read = tiffReader.read(0, readParam);
                bands[currentCov++] = read;
            } finally {
                tiffReader.dispose();
            }
        }
        final ProcessDescriptor desc = ProcessFinder.getProcessDescriptor("geotoolkit", "image:bandcombine");
        final ParameterValueGroup params = desc.getInputDescriptor().createValue();
        params.parameter("images").setValue(bands);
        final org.geotoolkit.process.Process process = desc.createProcess(params);
        final ParameterValueGroup result = process.call();
        final RenderedImage outImage = (RenderedImage) result.parameter("result").getValue();
        final GridCoverageBuilder gcb = new GridCoverageBuilder();
        gcb.setValues(outImage);
        gcb.setDomain(geometry);
        return gcb.build();
    } catch (IOException | NoSuchIdentifierException | ProcessException ex) {
        throw new DataStoreException(ex.getMessage(), ex);
    }
}
Also used : Path(java.nio.file.Path) GridGeometry(org.apache.sis.coverage.grid.GridGeometry) DataStoreException(org.apache.sis.storage.DataStoreException) ParameterValueGroup(org.opengis.parameter.ParameterValueGroup) Rectangle(java.awt.Rectangle) IOException(java.io.IOException) BufferedImage(java.awt.image.BufferedImage) ImageReadParam(javax.imageio.ImageReadParam) ProcessException(org.geotoolkit.process.ProcessException) GridCoverageBuilder(org.apache.sis.coverage.grid.GridCoverageBuilder) NoSuchIdentifierException(org.opengis.util.NoSuchIdentifierException) ProcessDescriptor(org.geotoolkit.process.ProcessDescriptor) RenderedImage(java.awt.image.RenderedImage) TiffImageReader(org.geotoolkit.image.io.plugin.TiffImageReader)

Example 2 with TiffImageReader

use of org.geotoolkit.image.io.plugin.TiffImageReader in project geotoolkit by Geomatys.

the class GeoTiffRWTest method test.

private void test(final String fileName, final CoordinateReferenceSystem crs, final AffineTransform gridToCRS) throws IOException, DataStoreException {
    File file = TestData.file(GeoTiffRWTest.class, fileName);
    ImageCoverageReader reader = new ImageCoverageReader();
    reader.setInput(file);
    try {
        // first test
        GridCoverage coverage = reader.read(null);
        compare(coverage, crs, gridToCRS);
        // write it and test again
        file = write(coverage, reader.getCoverageMetadata());
        reader.dispose();
        final ImageReader imgReader = new TiffImageReader(new TiffImageReader.Spi());
        imgReader.setInput(file);
        reader = (ImageCoverageReader) CoverageIO.createSimpleReader(imgReader);
        // second test
        coverage = reader.read(null);
        compare(coverage, crs, gridToCRS);
    } finally {
        reader.dispose();
    }
}
Also used : ImageCoverageReader(org.geotoolkit.coverage.io.ImageCoverageReader) GridCoverage(org.apache.sis.coverage.grid.GridCoverage) TiffImageReader(org.geotoolkit.image.io.plugin.TiffImageReader) ImageReader(javax.imageio.ImageReader) TiffImageReader(org.geotoolkit.image.io.plugin.TiffImageReader) File(java.io.File)

Aggregations

TiffImageReader (org.geotoolkit.image.io.plugin.TiffImageReader)2 Rectangle (java.awt.Rectangle)1 BufferedImage (java.awt.image.BufferedImage)1 RenderedImage (java.awt.image.RenderedImage)1 File (java.io.File)1 IOException (java.io.IOException)1 Path (java.nio.file.Path)1 ImageReadParam (javax.imageio.ImageReadParam)1 ImageReader (javax.imageio.ImageReader)1 GridCoverage (org.apache.sis.coverage.grid.GridCoverage)1 GridCoverageBuilder (org.apache.sis.coverage.grid.GridCoverageBuilder)1 GridGeometry (org.apache.sis.coverage.grid.GridGeometry)1 DataStoreException (org.apache.sis.storage.DataStoreException)1 ImageCoverageReader (org.geotoolkit.coverage.io.ImageCoverageReader)1 ProcessDescriptor (org.geotoolkit.process.ProcessDescriptor)1 ProcessException (org.geotoolkit.process.ProcessException)1 ParameterValueGroup (org.opengis.parameter.ParameterValueGroup)1 NoSuchIdentifierException (org.opengis.util.NoSuchIdentifierException)1