}
public static void checkCompatibleCoverages(GridCoverage2D coverageA, GridCoverage2D coverageB) throws ProcessException {
if (coverageA == null || coverageB == null){
String coveragesNull = coverageA == null ? (coverageB == null ? "coverageA and coverageB" : "coverageA") : "coverageB";
throw new ProcessException(Errors.format(ErrorKeys.NULL_ARGUMENT_$1, coveragesNull));
}
//
// checking same CRS
//
CoordinateReferenceSystem crsA = coverageA.getCoordinateReferenceSystem();
CoordinateReferenceSystem crsB = coverageB.getCoordinateReferenceSystem();
if (!CRS.equalsIgnoreMetadata(crsA, crsB)){
MathTransform mathTransform = null;
try {
mathTransform = CRS.findMathTransform(crsA, crsB);
} catch (FactoryException e) {
throw new ProcessException("Exceptions occurred while looking for a mathTransform between the 2 coverage's CRSs", e );
}
if (mathTransform != null && !mathTransform.isIdentity()){
throw new ProcessException(MISMATCHING_CRS_MESSAGE);
}
}
//
// checking same Envelope and grid range
//
Envelope envA = coverageA.getEnvelope();
Envelope envB = coverageB.getEnvelope();
if (!envA.equals(envB)) {
throw new ProcessException(MISMATCHING_ENVELOPE_MESSAGE);
}
GridEnvelope gridRangeA = coverageA.getGridGeometry().getGridRange();
GridEnvelope gridRangeB = coverageA.getGridGeometry().getGridRange();
if (gridRangeA.getSpan(0) != gridRangeB.getSpan(0)
|| gridRangeA.getSpan(1) != gridRangeB.getSpan(1)) {
throw new ProcessException(MISMATCHING_GRID_MESSAGE);
}
}