@Test
public void trim() throws Exception {
// check we can read it as a TIFF and it is similar to the original one
GridCoverage2D targetCoverage = null, sourceCoverage=null;
GeoTiffReader readerTarget = null;
try {
// source
sourceCoverage=(GridCoverage2D) this.getCatalog().getCoverageByName("BlueMarble").getGridCoverageReader(null, null).read(null);
final Envelope2D sourceEnvelope = sourceCoverage.getEnvelope2D();
// subsample using the original extension
MockHttpServletResponse response = getAsServletResponse("wcs?request=GetCoverage&service=WCS&version=2.0.1" +
"&coverageId=wcs__BlueMarble&&Format=image/tiff" +
"&subset=http://www.opengis.net/def/axis/OGC/0/Long(" +sourceEnvelope.x+","+(sourceEnvelope.x+sourceEnvelope.width/2)+")"+
"&subset=http://www.opengis.net/def/axis/OGC/0/Lat(" +sourceEnvelope.y+","+(sourceEnvelope.y+sourceEnvelope.height/2)+")");
assertEquals("image/tiff", response.getContentType());
byte[] tiffContents = getBinary(response);
File file = File.createTempFile("bm_gtiff", "bm_gtiff.tiff", new File("./target"));
FileUtils.writeByteArrayToFile(file, tiffContents);
readerTarget = new GeoTiffReader(file);
targetCoverage = readerTarget.read(null);
// checks
assertEquals(sourceCoverage.getCoordinateReferenceSystem(), targetCoverage.getCoordinateReferenceSystem());
assertEquals(180, targetCoverage.getGridGeometry().getGridRange().getSpan(0));
assertEquals(180, targetCoverage.getGridGeometry().getGridRange().getSpan(1));
assertEquals(0, targetCoverage.getGridGeometry().getGridRange().getLow(0));
assertEquals(0, targetCoverage.getGridGeometry().getGridRange().getLow(1));
// === request does not intersect
response = getAsServletResponse("wcs?request=GetCoverage&service=WCS&version=2.0.1"
+ "&coverageId=wcs__BlueMarble&&Format=image/tiff"+
"&subset=http://www.opengis.net/def/axis/OGC/0/Long(" +(sourceEnvelope.x+1.1*sourceEnvelope.width)+","+(sourceEnvelope.x+1.2*sourceEnvelope.width)+")"+
"&subset=http://www.opengis.net/def/axis/OGC/0/Lat(" +(sourceEnvelope.y+1.1*sourceEnvelope.height)+","+(sourceEnvelope.y+1.2*sourceEnvelope.height)
+")");
assertEquals("application/xml", response.getContentType());
checkOws20Exception(response, 404, WCS20ExceptionCode.InvalidSubsetting.getExceptionCode(),"");
// === trim low > high Lat
response = getAsServletResponse("wcs?request=GetCoverage&service=WCS&version=2.0.1"
+ "&coverageId=wcs__BlueMarble&&Format=image/tiff"+
"&subset=http://www.opengis.net/def/axis/OGC/0/Long(" +(sourceEnvelope.x)+","+(sourceEnvelope.x+sourceEnvelope.width)+")"+
"&subset=http://www.opengis.net/def/axis/OGC/0/Lat(" +(sourceEnvelope.y+sourceEnvelope.height)+","+(sourceEnvelope.y)
+")");
assertEquals("application/xml", response.getContentType());
checkOws20Exception(response, 404, WCS20ExceptionCode.InvalidSubsetting.getExceptionCode(),Double.toString((sourceEnvelope.y+sourceEnvelope.height)));
} finally {
try{
if(readerTarget!=null){
readerTarget.dispose();
}
} catch (Exception e) {
LOGGER.log(Level.WARNING,e.getLocalizedMessage(),e);
}
try{