if(readGG != null) {
// Crop will fail if we try to crop outside of the coverage area
ReferencedEnvelope renderingEnvelope = new ReferencedEnvelope(readGG.getEnvelope());
CoordinateReferenceSystem coverageCRS = coverage.getCoordinateReferenceSystem2D();
if(!CRS.equalsIgnoreMetadata(renderingEnvelope.getCoordinateReferenceSystem(), coverageCRS)) {
renderingEnvelope = renderingEnvelope.transform(coverageCRS, true);
}
if(coverage.getEnvelope2D().intersects(renderingEnvelope)) {
// the resulting coverage might be larger than the readGG envelope, shall we crop it?
final ParameterValueGroup param = CROP.getParameters();
param.parameter("Source").setValue(coverage);