*/
@Test
public void testDatumShift() throws Exception {
final CoordinateReferenceSystem sourceCRS = crsFactory.createFromWKT(WKT.GEOGRAPHIC_NTF);
final CoordinateReferenceSystem targetCRS = crsFactory.createFromWKT(WKT.WGS84);
final CoordinateOperation operation = opFactory.createOperation(sourceCRS, targetCRS);
if (usingDefaultFactory) {
assertSame (sourceCRS, operation.getSourceCRS());
assertSame (targetCRS, operation.getTargetCRS());
assertTrue (operation.getCoordinateOperationAccuracy().contains(PositionalAccuracyImpl.DATUM_SHIFT_APPLIED));
assertFalse(operation.getCoordinateOperationAccuracy().contains(PositionalAccuracyImpl.DATUM_SHIFT_OMITTED));
}
final MathTransform transform = operation.getMathTransform();
assertInterfaced(transform);
assertTransformEquals2_2(transform, 0, 0, 2.3367521703619816, 0.0028940088671177986);
assertTransformEquals2_2(transform, 20, -10, -6.663517606186469, 18.00134508026729);
// Note: Expected values above were computed with Geotools (not an external library).
// However, it was tested with both Molodenski and Geocentric transformations.
/*
* Remove the TOWGS84 element and test again. An exception should be throws,
* since no Bursa-Wolf parameters were available.
*/
final CoordinateReferenceSystem amputedCRS;
if (true) {
String wkt = sourceCRS.toWKT();
final int start = wkt.indexOf("TOWGS84"); assertTrue(start >= 0);
final int end = wkt.indexOf(']', start); assertTrue(end >= 0);
final int comma = wkt.indexOf(',', end); assertTrue(comma >= 0);
wkt = wkt.substring(0, start) + wkt.substring(comma+1);
amputedCRS = crsFactory.createFromWKT(wkt);
} else {
amputedCRS = sourceCRS;
}
try {
assertNotNull(opFactory.createOperation(amputedCRS, targetCRS));
fail("Operation without Bursa-Wolf parameters should not have been allowed.");
} catch (OperationNotFoundException excption) {
// This is the expected exception.
}
/*
* Try again with hints, asking for a lenient factory.
*/
CoordinateOperationFactory lenientFactory;
Hints hints = new Hints(Hints.LENIENT_DATUM_SHIFT, Boolean.FALSE);
lenientFactory = ReferencingFactoryFinder.getCoordinateOperationFactory(hints);
assertSame(opFactory, lenientFactory);
hints.put(Hints.LENIENT_DATUM_SHIFT, Boolean.TRUE);
lenientFactory = ReferencingFactoryFinder.getCoordinateOperationFactory(hints);
assertNotSame(opFactory, lenientFactory);
final CoordinateOperation lenient = lenientFactory.createOperation(amputedCRS, targetCRS);
assertSame(amputedCRS, lenient.getSourceCRS());
assertSame( targetCRS, lenient.getTargetCRS());
assertFalse(lenient.getCoordinateOperationAccuracy().contains(PositionalAccuracyImpl.DATUM_SHIFT_APPLIED));
assertTrue (lenient.getCoordinateOperationAccuracy().contains(PositionalAccuracyImpl.DATUM_SHIFT_OMITTED));
final MathTransform lenientTr = lenient.getMathTransform();
assertInterfaced(lenientTr);
assertTransformEquals2_2(lenientTr, 0, 0, 2.33722917, 0.0);
assertTransformEquals2_2(lenientTr, 20, -10, -6.66277083, 17.99814879585781);
// assertTransformEquals2_2(lenientTr, 20, -10, -6.66277083, 17.998143675921714);
// Note 1: Expected values above were computed with Geotools (not an external library).