assertEquals("image/tiff", response.getContentType());
byte[] tiffContents = getBinary(response);
File file = File.createTempFile("rain_gtiff", "rain_gtiff.tiff", new File("./target"));
FileUtils.writeByteArrayToFile(file, tiffContents);
GeoTiffReader readerTarget = new GeoTiffReader(file);
GridCoverage2D targetCoverage = null;
try {
targetCoverage = readerTarget.read(null);
// check we got the right envelope
Envelope2D envelope = targetCoverage.getEnvelope2D();
assertEquals(160, envelope.getMinX(), 0d);
assertEquals(0, envelope.getMinY(), 0d);
assertEquals(200, envelope.getMaxX(), 0d);
assertEquals(40, envelope.getMaxY(), 0d);
assertTrue(CRS.equalsIgnoreMetadata(DefaultGeographicCRS.WGS84,
targetCoverage.getCoordinateReferenceSystem2D()));
// check we actually read the right stuff. For this case, we
// just check we have the pixels in the range of values of that area
Raster data = targetCoverage.getRenderedImage().getData();
double[] pixel = new double[1];
for (int i = data.getMinY(); i < data.getMinY() + data.getHeight(); i++) {
for (int j = data.getMinX(); j < data.getMinX() + data.getWidth(); j++) {
data.getPixel(i, j, pixel);
double d = pixel[0];
assertTrue(String.valueOf(d), d > 500 && d < 5500);
}
}
} finally {
readerTarget.dispose();
scheduleForCleaning(targetCoverage);
}
}