if (!CRS.equalsIgnoreMetadata(requestCRS, rasterManager.spatialDomainManager.coverageCRS2D))
try {
destinationToSourceTransform = CRS.findMathTransform(requestCRS,
rasterManager.spatialDomainManager.coverageCRS2D, true);
} catch (FactoryException e) {
throw new DataSourceException("Unable to inspect request CRS", e);
}
// now transform the requested envelope to sourceFile crs
if (destinationToSourceTransform != null && destinationToSourceTransform.isIdentity()) {
destinationToSourceTransform = null;// the CRS is basically the same
} else if (destinationToSourceTransform instanceof AffineTransform) {
needsReprojection = true;
//
// k, the transformation between the various CRS is not null or the
// Identity, let's see if it is an affine transform, which case we
// can incorporate it into the requested grid to world
//
// we should not have any problems with regards to BBOX reprojection
// update the requested grid to world transformation by pre concatenating the destination to sourceFile transform
AffineTransform mutableTransform = (AffineTransform) requestedGridToWorld.clone();
mutableTransform.preConcatenate((AffineTransform) destinationToSourceTransform);
// update the requested envelope
try {
final MathTransform tempTransform = PixelTranslation.translate(
ProjectiveTransform.create(mutableTransform), PixelInCell.CELL_CENTER,
PixelInCell.CELL_CORNER);
requestedBBox = new ReferencedEnvelope(CRS.transform(tempTransform,
new GeneralEnvelope(requestedRasterArea)));
} catch (MismatchedDimensionException e) {
throw new DataSourceException("Unable to inspect request CRS", e);
} catch (TransformException e) {
throw new DataSourceException("Unable to inspect request CRS", e);
}
// now clean up all the traces of the transformations
destinationToSourceTransform = null;
}