final CoordinateReferenceSystem sourceCRS = CRS.decode(requestCRS);
// This is the CRS of the Coverage Envelope
final CoordinateReferenceSystem cvCRS = ((GeneralEnvelope) coverageReader
.getOriginalEnvelope()).getCoordinateReferenceSystem();
final MathTransform GCCRSTodeviceCRSTransformdeviceCRSToGCCRSTransform = CRS
.findMathTransform(cvCRS, sourceCRS, true);
final MathTransform GCCRSTodeviceCRSTransform = CRS.findMathTransform(cvCRS, targetCRS, true);
final MathTransform deviceCRSToGCCRSTransform = GCCRSTodeviceCRSTransformdeviceCRSToGCCRSTransform
.inverse();
com.vividsolutions.jts.geom.Envelope envelope = request.getBbox();
GeneralEnvelope destinationEnvelope;
final boolean lonFirst = sourceCRS.getCoordinateSystem().getAxis(0).getDirection().absolute()
.equals(AxisDirection.EAST);
// the envelope we are provided with is lon,lat always
if (!lonFirst) {
destinationEnvelope = new GeneralEnvelope(new double[] {
envelope.getMinY(), envelope.getMinX()
}, new double[] { envelope.getMaxY(), envelope.getMaxX() });
} else {
destinationEnvelope = new GeneralEnvelope(new double[] {
envelope.getMinX(), envelope.getMinY()
}, new double[] { envelope.getMaxX(), envelope.getMaxY() });
}
destinationEnvelope.setCoordinateReferenceSystem(sourceCRS);
// this is the destination envelope in the coverage crs
final GeneralEnvelope destinationEnvelopeInSourceCRS = (!deviceCRSToGCCRSTransform
.isIdentity()) ? CRS.transform(deviceCRSToGCCRSTransform, destinationEnvelope)
: new GeneralEnvelope(destinationEnvelope);
destinationEnvelopeInSourceCRS.setCoordinateReferenceSystem(cvCRS);
/**