}
@Test
public void scaleToExtentWithTrim() throws Exception {
GeoTiffReader readerTarget = null;
GridCoverage2D targetCoverage = null, sourceCoverage=null;
try {
// source
sourceCoverage=(GridCoverage2D) this.getCatalog().getCoverageByName("BlueMarble").getGridCoverageReader(null, null).read(null);
final Envelope2D sourceEnvelope = sourceCoverage.getEnvelope2D();
// subsample
MockHttpServletResponse response = getAsServletResponse("wcs?request=GetCoverage&service=WCS&version=2.0.1" +
"&coverageId=wcs__BlueMarble&&Format=image/tiff&SCALEEXTENT=http://www.opengis.net/def/axis/OGC/1/i(50,149)," +
"http://www.opengis.net/def/axis/OGC/1/j(50,149)" +
"&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);
sourceCoverage=(GridCoverage2D) this.getCatalog().getCoverageByName("BlueMarble").getGridCoverageReader(null, null).read(null);
// checks
assertEquals(sourceCoverage.getCoordinateReferenceSystem(), targetCoverage.getCoordinateReferenceSystem());
final GeneralEnvelope finalEnvelope= new GeneralEnvelope(
new double[]{sourceEnvelope.x,sourceEnvelope.y},
new double[]{sourceEnvelope.x+sourceEnvelope.width/2,sourceEnvelope.y+sourceEnvelope.height/2});
finalEnvelope.setCoordinateReferenceSystem(sourceCoverage.getCoordinateReferenceSystem());
assertEquals(100, targetCoverage.getGridGeometry().getGridRange().getSpan(0));
assertEquals(100, targetCoverage.getGridGeometry().getGridRange().getSpan(1));
// get extrema
assertEquals(29.0,new ImageWorker(targetCoverage.getRenderedImage()).getMaximums()[0]);
} finally {
try{
readerTarget.dispose();
} catch (Exception e) {
LOGGER.log(Level.WARNING,e.getLocalizedMessage(),e);
}
try{
scheduleForCleaning(targetCoverage);
} catch (Exception e) {
LOGGER.log(Level.WARNING,e.getLocalizedMessage(),e);
}
try{
scheduleForCleaning(sourceCoverage);
} catch (Exception e) {
LOGGER.log(Level.WARNING,e.getLocalizedMessage(),e);
}
}
try {
// source
sourceCoverage=(GridCoverage2D) this.getCatalog().getCoverageByName("BlueMarble").getGridCoverageReader(null, null).read(null);
final Envelope2D sourceEnvelope = sourceCoverage.getEnvelope2D();
// upsample
MockHttpServletResponse response = getAsServletResponse("wcs?request=GetCoverage&service=WCS&version=2.0.1" +
"&coverageId=wcs__BlueMarble&&Format=image/tiff&SCALEEXTENT=http://www.opengis.net/def/axis/OGC/1/i(100,1099)," +
"http://www.opengis.net/def/axis/OGC/1/j(100,1099)" +
"&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);
// check we can read it as a TIFF and it is similare to the origina one
readerTarget = new GeoTiffReader(file);
targetCoverage = readerTarget.read(null);
sourceCoverage=(GridCoverage2D) this.getCatalog().getCoverageByName("BlueMarble").getGridCoverageReader(null, null).read(null);
// checks
assertEquals(sourceCoverage.getCoordinateReferenceSystem(), targetCoverage.getCoordinateReferenceSystem());
final GeneralEnvelope finalEnvelope= new GeneralEnvelope(
new double[]{sourceEnvelope.x,sourceEnvelope.y},
new double[]{sourceEnvelope.x+sourceEnvelope.width/2,sourceEnvelope.y+sourceEnvelope.height/2});
finalEnvelope.setCoordinateReferenceSystem(sourceCoverage.getCoordinateReferenceSystem());
assertEquals(1000, targetCoverage.getGridGeometry().getGridRange().getSpan(0));
assertEquals(1000, targetCoverage.getGridGeometry().getGridRange().getSpan(1));
// geotiff encoding looses the min values and pushes to zero
assertEquals(0, targetCoverage.getGridGeometry().getGridRange().getLow(0));
assertEquals(0, targetCoverage.getGridGeometry().getGridRange().getLow(1));
assertEquals(999, targetCoverage.getGridGeometry().getGridRange().getHigh(0));
assertEquals(999, targetCoverage.getGridGeometry().getGridRange().getHigh(1));
// get extrema
assertEquals(29.0,new ImageWorker(targetCoverage.getRenderedImage()).getMaximums()[0]);
} finally {
try{
readerTarget.dispose();
} catch (Exception e) {
LOGGER.log(Level.WARNING,e.getLocalizedMessage(),e);
}
try{
scheduleForCleaning(targetCoverage);
} catch (Exception e) {
LOGGER.log(Level.WARNING,e.getLocalizedMessage(),e);
}
try{
scheduleForCleaning(sourceCoverage);
} catch (Exception e) {
LOGGER.log(Level.WARNING,e.getLocalizedMessage(),e);
}
}
// test coverage directly to make sure we respect LLC & URC
try {
targetCoverage = (GridCoverage2D) executeGetCoverage("wcs?request=GetCoverage&service=WCS&version=2.0.1" +
"&coverageId=wcs__BlueMarble&&Format=image/tiff&SCALEEXTENT=http://www.opengis.net/def/axis/OGC/1/i(100,1099)," +
"http://www.opengis.net/def/axis/OGC/1/j(100,1099)");
assertNotNull(targetCoverage);
sourceCoverage=(GridCoverage2D) this.getCatalog().getCoverageByName("BlueMarble").getGridCoverageReader(null, null).read(null);
// checks
// assertEquals(sourceCoverage.getCoordinateReferenceSystem(), targetCoverage.getCoordinateReferenceSystem());
// assertEnvelopeEquals(sourceCoverage, targetCoverage);
assertEquals(1000, targetCoverage.getGridGeometry().getGridRange().getSpan(0));
assertEquals(1000, targetCoverage.getGridGeometry().getGridRange().getSpan(1));
assertEquals(100, targetCoverage.getGridGeometry().getGridRange().getLow(0));
assertEquals(100, targetCoverage.getGridGeometry().getGridRange().getLow(1));
assertEquals(1099, targetCoverage.getGridGeometry().getGridRange().getHigh(0));
assertEquals(1099, targetCoverage.getGridGeometry().getGridRange().getHigh(1));
} finally {
try{
readerTarget.dispose();
} catch (Exception e) {
LOGGER.log(Level.WARNING,e.getLocalizedMessage(),e);
}
try{
scheduleForCleaning(targetCoverage);