.getGridCoverageReader(null, HINTS);
final ParameterValueGroup params = reader.getFormat().getReadParameters();
// handle spatial domain subset, if needed
final GeneralEnvelope originalEnvelope = reader.getOriginalEnvelope();
final BoundingBoxType bbox = request.getDomainSubset().getBoundingBox();
final CoordinateReferenceSystem nativeCRS = originalEnvelope
.getCoordinateReferenceSystem();
final GeneralEnvelope destinationEnvelopeInSourceCRS;
final GeneralEnvelope destinationEnvelope;
if (bbox != null) {
// first off, parse the envelope corners
double[] lowerCorner = new double[bbox.getLowerCorner().size()];
double[] upperCorner = new double[bbox.getUpperCorner().size()];
for (int i = 0; i < lowerCorner.length; i++) {
lowerCorner[i] = (Double) bbox.getLowerCorner().get(i);
upperCorner[i] = (Double) bbox.getUpperCorner().get(i);
}
destinationEnvelope = new GeneralEnvelope(lowerCorner, upperCorner);
// grab the native crs
// if no crs has beens specified, the native one is assumed
if (bbox.getCrs() == null) {
destinationEnvelope.setCoordinateReferenceSystem(nativeCRS);
destinationEnvelopeInSourceCRS = destinationEnvelope;
} else {
// otherwise we need to transform
final CoordinateReferenceSystem bboxCRS = CRS.decode(bbox.getCrs());
destinationEnvelope.setCoordinateReferenceSystem(bboxCRS);
final MathTransform bboxToNativeTx = CRS.findMathTransform(bboxCRS, nativeCRS,
true);
destinationEnvelopeInSourceCRS = CRS.transform(bboxToNativeTx,
destinationEnvelope);