GridCoverageFactory factory = new GridCoverageFactory();
ReferencedEnvelope ref = new ReferencedEnvelope(bounds.getMinX(), bounds.getMaxX(),
bounds.getMinY(), bounds.getMaxY(), crs);
GridCoverage2D coverage = (GridCoverage2D) factory.create(
"GridCoverage", tile.getBufferedImage(), ref); //$NON-NLS-1$
Envelope2D coveragebounds = coverage.getEnvelope2D();
// bounds of tile
Envelope tilebBounds = new Envelope(coveragebounds.getMinX(), coveragebounds.getMaxX(),
coveragebounds.getMinY(), coveragebounds.getMaxY());
// convert bounds to necessary viewport projection
CoordinateReferenceSystem tileCrs = getContext().getCRS();
if (!coverage.getCoordinateReferenceSystem().equals(tileCrs)) {
MathTransform transform = CRS.findMathTransform(