final String responseCRS = request.getResponseCRS();
// - first check if the responseCRS is present on the Coverage
// ResponseCRSs list
if (!meta.getResponseSRS().contains(responseCRS)) {
throw new WcsException("This Coverage does not support the requested Response-CRS.");
}
// - then create the Coordinate Reference System
final CoordinateReferenceSystem targetCRS = CRS.decode(responseCRS);
// This is the CRS of the requested Envelope
final String requestCRS = request.getCRS();
// - first check if the requestCRS is present on the Coverage
// RequestCRSs list
if (!meta.getResponseSRS().contains(requestCRS)) {
throw new WcsException("This Coverage does not support the requested CRS.");
}
// - then create the Coordinate Reference System
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.getEnvelope();
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);
/**
* Reading Coverage on Requested Envelope
*/
Rectangle destinationSize = null;
if ((request.getGridLow() != null) && (request.getGridHigh() != null)) {
final int[] lowers = new int[] {
request.getGridLow()[0].intValue(), request.getGridLow()[1].intValue()
};
final int[] highers = new int[] {
request.getGridHigh()[0].intValue(), request.getGridHigh()[1].intValue()
};
destinationSize = new Rectangle(lowers[0], lowers[1], highers[0], highers[1]);
} else {
/*destinationSize = coverageReader.getOriginalGridRange().toRectangle();*/
throw new WcsException("Neither Grid Size nor Grid Resolution have been specified.");
}
/**
* Checking for supported Interpolation Methods
*/
Interpolation interpolation = Interpolation.getInstance(Interpolation.INTERP_NEAREST);
final String interpolationType = request.getInterpolation();
if (interpolationType != null) {
boolean interpolationSupported = false;
Iterator internal = meta.getInterpolationMethods().iterator();
while (internal.hasNext()) {
if (interpolationType.equalsIgnoreCase((String) internal.next())) {
interpolationSupported = true;
}
}
if (!interpolationSupported) {
throw new WcsException(
"The requested Interpolation method is not supported by this Coverage.");
} else {
if (interpolationType.equalsIgnoreCase("bilinear")) {
interpolation = Interpolation.getInstance(Interpolation.INTERP_BILINEAR);
} else if (interpolationType.equalsIgnoreCase("bicubic")) {