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