// grab the format, the reader using the default params
final AbstractGridCoverage2DReader reader = (AbstractGridCoverage2DReader) meta.getGridCoverageReader(null, WCSUtils.getReaderHints(wcs));
// handle spatial domain subset, if needed
final GeneralEnvelope originalEnvelope = reader.getOriginalEnvelope();
final BoundingBoxType bbox = request.getDomainSubset().getBoundingBox();
final CoordinateReferenceSystem nativeCRS = originalEnvelope.getCoordinateReferenceSystem();
final GeneralEnvelope requestedEnvelopeInSourceCRS;
final GeneralEnvelope requestedEnvelope;
MathTransform bboxToNativeTx=null;
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);
}
requestedEnvelope = new GeneralEnvelope(lowerCorner, upperCorner);
// grab the native crs
// if no crs has beens specified, the native one is assumed
if (bbox.getCrs() == null) {
requestedEnvelope.setCoordinateReferenceSystem(nativeCRS);
requestedEnvelopeInSourceCRS = requestedEnvelope;
} else {
// otherwise we need to transform
final CoordinateReferenceSystem bboxCRS = CRS.decode(bbox.getCrs());
requestedEnvelope.setCoordinateReferenceSystem(bboxCRS);
bboxToNativeTx = CRS.findMathTransform(bboxCRS, nativeCRS,true);
if(!bboxToNativeTx.isIdentity()){
requestedEnvelopeInSourceCRS = CRS.transform(bboxToNativeTx,requestedEnvelope);
requestedEnvelopeInSourceCRS.setCoordinateReferenceSystem(nativeCRS);