o = files[i].toURI().toURL();
if (format.accepts(o)) {
buffer.append("ACCEPTED").append("\n");
// getting a reader
GeoTiffReader reader = new GeoTiffReader(o, new Hints(Hints.FORCE_LONGITUDE_FIRST_AXIS_ORDER, Boolean.TRUE));
if (reader != null) {
// reading the coverage
final GridCoverage2D coverage = (GridCoverage2D) reader.read(null);
// Crs and envelope
if (TestData.isInteractiveTest()) {
buffer.append("CRS: ").append(
coverage.getCoordinateReferenceSystem2D()
.toWKT()).append("\n");
buffer.append("GG: ").append(
coverage.getGridGeometry().toString()).append("\n");
}
// display metadata
if (org.geotools.TestData.isExtensiveTest()) {
IIOMetadataDumper iIOMetadataDumper = new IIOMetadataDumper(
((GeoTiffReader) reader).getMetadata()
.getRootNode());
buffer.append("TIFF metadata: ").append(
iIOMetadataDumper.getMetadata()).append("\n");
}
// layout checks
final ImageLayout layout = reader.getImageLayout();
assertNotNull(layout);
assertNotNull(layout.getColorModel(null));
assertNotNull(layout.getSampleModel(null));
assertEquals(0,layout.getMinX(null));
assertEquals(0,layout.getMinY(null));
assertTrue(layout.getWidth(null) > 0);
assertTrue(layout.getHeight(null) > 0);
assertEquals(0,layout.getTileGridXOffset(null));
assertEquals(0,layout.getTileGridYOffset(null));
assertTrue(layout.getTileHeight(null) > 0);
assertTrue(layout.getTileWidth(null) > 0);
// showing it
if (TestData.isInteractiveTest()){
coverage.show();
}
else {
PlanarImage.wrapRenderedImage(coverage.getRenderedImage()).getTiles();
}
// write and read back
final File destFile = File.createTempFile("test", ".tif",writeDirectory);
final GeoTiffWriter writer= new GeoTiffWriter(destFile);
writer.write(coverage, null);
writer.dispose();
// read back
assertTrue(format.accepts(destFile));
reader = new GeoTiffReader(destFile, new Hints(Hints.FORCE_LONGITUDE_FIRST_AXIS_ORDER, Boolean.TRUE));
final GridCoverage2D destCoverage = (GridCoverage2D) reader.read(null);
reader.dispose();
final double eps=XAffineTransform.getScaleX0((AffineTransform)coverage.getGridGeometry().getGridToCRS())*1E-2;
assertTrue("CRS comparison failed:" +o.toString(),CRS.findMathTransform(coverage.getCoordinateReferenceSystem(), destCoverage.getCoordinateReferenceSystem(), true).isIdentity());