@Test
public void testGeographic3D_to_2D() throws FactoryException {
CoordinateReferenceSystem sourceCRS = CRS.forCode("EPSG:4327");
CoordinateReferenceSystem targetCRS = CommonCRS.WGS84.geographic();
MathTransform tr;
try {
CRS.findOperation(sourceCRS, targetCRS, null).getMathTransform();
fail("No conversion from EPSG:4327 to EPSG:4326 should be allowed because the units " +
"conversion from DMS to degrees is not linear. Note that this exception may be " +
"removed in a future version if we implement non-linear unit conversions.");
} catch (OperationNotFoundException e) {
assertTrue("The operation should have failed because of a unit conversion error.",
e.getCause() instanceof IncommensurableException);
}
sourceCRS = CommonCRS.WGS84.geographic3D();
tr = CRS.findOperation(sourceCRS, targetCRS, null).getMathTransform();
assertEquals(3, tr.getSourceDimensions());
assertEquals(2, tr.getTargetDimensions());
assertDiagonalMatrix(tr, true, 1, 1, 0);
}