//
// ///////////////////////////////////////////////////////////////////
final GridCoverage2D croppedGridCoverage;
// intersect the envelopes
final GeneralEnvelope intersectionEnvelope = new GeneralEnvelope(destinationEnvelopeInSourceCRS);
intersectionEnvelope.setCoordinateReferenceSystem(sourceCRS);
intersectionEnvelope.intersect((GeneralEnvelope) sourceEnvelope);
// dow we have something to show?
if (intersectionEnvelope.isEmpty()) {
throw new WcsException("The Intersection is null. Check the requested BBOX!");
}
if (!intersectionEnvelope.equals((GeneralEnvelope) sourceEnvelope)) {
// get the cropped grid geometry
// final GridGeometry2D cropGridGeometry = getCroppedGridGeometry(
// intersectionEnvelope, gridCoverage);
/* Operations.DEFAULT.crop(coverage, intersectionEnvelope) */
final ParameterValueGroup param = (ParameterValueGroup) cropParams.clone();
param.parameter("Source").setValue(coverage);
param.parameter("Envelope").setValue(intersectionEnvelope);
param.parameter("ConserveEnvelope").setValue(conserveEnvelope);
croppedGridCoverage = (GridCoverage2D) cropFactory.doOperation(param, hints);
} else {
croppedGridCoverage = (GridCoverage2D) coverage;
}
// prefetch to be faster afterwards.
// This step is important since at this stage we might be loading tiles
// from disk
croppedGridCoverage.prefetch(intersectionEnvelope.toRectangle2D());
return croppedGridCoverage;
}