@Test
public void testDownloadRaster() throws Exception {
// Estimator process for checking limits
DownloadEstimatorProcess limits = new DownloadEstimatorProcess(
new StaticDownloadServiceConfiguration(), getGeoServer());
final WPSResourceManager resourceManager = new WPSResourceManager();
// Creates the new process for the download
DownloadProcess downloadProcess = new DownloadProcess(getGeoServer(), limits,
resourceManager);
// test ROI
Polygon roi = (Polygon) new WKTReader2()
.read("POLYGON (( -127.57473954542964 54.06575021619523, -130.88669845369998 52.00807146727025, -129.50812897394974 49.85372324691927, -130.5300633861675 49.20465679591609, -129.25955033314003 48.60392508062591, -128.00975216684665 50.986137055052474, -125.8623089087404 48.63154492960477, -123.984159178178 50.68231871628503, -126.91186316993704 52.15307567440926, -125.3444367403868 53.54787804784162, -127.57473954542964 54.06575021619523 ))");
roi.setSRID(4326);
// ROI reprojection
Polygon roiResampled = (Polygon) JTS.transform(
roi,
CRS.findMathTransform(CRS.decode("EPSG:4326", true),
CRS.decode("EPSG:900913", true)));
// Download the coverage as tiff (Not reprojected)
File rasterZip = downloadProcess.execute(getLayerId(MockData.USA_WORLDIMG), // layerName
null, // filter
"image/tiff", // outputFormat
null, // targetCRS
CRS.decode("EPSG:4326", true), // roiCRS
roi, // roi
true, // cropToGeometry
new NullProgressListener() // progressListener
);
// Final checks on the result
Assert.assertNotNull(rasterZip);
GeoTiffReader reader = null;
GridCoverage2D gc = null, gcResampled = null;
try {
final File[] tiffFiles = extractTIFFFile(rasterZip);
Assert.assertNotNull(tiffFiles);
Assert.assertTrue(tiffFiles.length > 0);
reader = new GeoTiffReader(tiffFiles[0]);
gc = reader.read(null);
Assert.assertNotNull(gc);
Assert.assertEquals(-130.88669845369998,
gc.getEnvelope().getLowerCorner().getOrdinate(0), 1E-6);
Assert.assertEquals(48.611129008700004, gc.getEnvelope().getLowerCorner()
.getOrdinate(1), 1E-6);
Assert.assertEquals(-123.95304462109999,
gc.getEnvelope().getUpperCorner().getOrdinate(0), 1E-6);
Assert.assertEquals(54.0861661371, gc.getEnvelope().getUpperCorner().getOrdinate(1),
1E-6);
} finally {
if (gc != null) {
CoverageCleanerCallback.disposeCoverage(gc);
}
if (reader != null) {
reader.dispose();
}
// clean up process
resourceManager.finished(resourceManager.getExecutionId(true));
}
// Download the coverage as tiff (Reprojected)
File resampledZip = downloadProcess.execute(getLayerId(MockData.USA_WORLDIMG), // layerName
null, // filter
"image/tiff", // outputFormat
CRS.decode("EPSG:900913", true), // targetCRS
CRS.decode("EPSG:900913", true), // roiCRS
roiResampled, // roi
true, // cropToGeometry
new NullProgressListener() // progressListener
);
// Final checks on the result
Assert.assertNotNull(resampledZip);
try {
File[] files = extractTIFFFile(resampledZip);
reader = new GeoTiffReader(files[files.length - 1]);
gcResampled = reader.read(null);
Assert.assertNotNull(gcResampled);
Assert.assertEquals(-1.457024062347863E7, gcResampled.getEnvelope().getLowerCorner()
.getOrdinate(0), 1E-6);
Assert.assertEquals(6209706.404894806, gcResampled.getEnvelope().getLowerCorner()
.getOrdinate(1), 1E-6);
Assert.assertEquals(-1.379838980949677E7, gcResampled.getEnvelope().getUpperCorner()
.getOrdinate(0), 1E-6);
Assert.assertEquals(7187128.139081598, gcResampled.getEnvelope().getUpperCorner()
.getOrdinate(1), 1E-6);
} finally {
if (gcResampled != null) {
CoverageCleanerCallback.disposeCoverage(gcResampled);
}
if (reader != null)
reader.dispose();
// clean up process
resourceManager.finished(resourceManager.getExecutionId(true));
}
}