originalEnvelope.getLowerCorner().getOrdinate(1)},
new double[] { originalEnvelope.getMedian().getOrdinate(0),
originalEnvelope.getMedian().getOrdinate(1)});
reducedEnvelope.setCoordinateReferenceSystem(reader.getCrs());
final ParameterValue gg = (ParameterValue) ((AbstractGridFormat) reader
.getFormat()).READ_GRIDGEOMETRY2D.createValue();
gg.setValue(new GridGeometry2D(new GridEnvelope2D(new Rectangle(0, 0,
(int) (range.width / 2.0),
(int) (range.height / 2.0))), reducedEnvelope));
gc = (GridCoverage2D) reader.read(new GeneralParameterValue[] { gg });
Assert.assertNotNull(gc);
// NOTE: in some cases might be too restrictive
Assert.assertTrue(reducedEnvelope.equals(gc.getEnvelope(), XAffineTransform
.getScale(((AffineTransform) ((GridGeometry2D) gc
.getGridGeometry()).getGridToCRS2D())) / 2, true));
// this should be fine since we give 1 pixel tolerance
Assert.assertEquals(originalW / 2.0 , gc.getRenderedImage()
.getWidth(), 1);
Assert.assertEquals(originalH / 2.0 , gc.getRenderedImage()
.getHeight(), 1);
forceDataLoading(gc);
// /////////////////////////////////////////////////////////////////////
//
// Read ignoring overviews with subsampling and crop, using Jai,
// and customized tilesize
//
// /////////////////////////////////////////////////////////////////////
final ParameterValue policy = (ParameterValue) ((AbstractGridFormat) reader
.getFormat()).OVERVIEW_POLICY.createValue();
policy.setValue(OverviewPolicy.IGNORE);
// //
//
// Customizing Tile Size
//
// //
final ParameterValue tilesize = (ParameterValue) ((BaseGDALGridFormat) reader
.getFormat()).SUGGESTED_TILE_SIZE.createValue();
tilesize.setValue("512,512");
// //
//
// Setting read type: use JAI ImageRead
//
// //
final ParameterValue useJaiRead = (ParameterValue) ((BaseGDALGridFormat) reader
.getFormat()).USE_JAI_IMAGEREAD.createValue();
useJaiRead.setValue(true);
gc = (GridCoverage2D) reader.read(new GeneralParameterValue[] { gg,
policy, tilesize, useJaiRead });
Assert.assertNotNull(gc);