final CoordinateReferenceSystem sourceCRS = operation.getSourceCRS(); final CoordinateReferenceSystem targetCRS = operation.getTargetCRS(); final Map<String, Object> properties =
public void testOperationSourceTarget() throws Exception { // flip one way CoordinateReferenceSystem source = CRS.decode("EPSG:32638", true); // lon/lat CoordinateReferenceSystem target = CRS.decode("EPSG:4326", false); // lat/lon CoordinateOperationFactory coordinateOperationFactory = CRS.getCoordinateOperationFactory(true); CoordinateOperation co = coordinateOperationFactory.createOperation(source, target); assertEquals(source, co.getSourceCRS()); assertEquals(target, co.getTargetCRS()); // flip the other source = CRS.decode("EPSG:32638", false); // lat/lon target = CRS.decode("EPSG:4326", true); // lon/lat co = coordinateOperationFactory.createOperation(source, target); assertEquals(source, co.getSourceCRS()); assertEquals(target, co.getTargetCRS()); }
/** * Replaces (if needed) the specified coordinate operation. The default implementation checks if * there is a source or target {@linkplain #replace(CoordinateReferenceSystem) CRS replacement}. * If there is at least one of those, then this method returns a new coordinate operation using * the new CRS. * * @param operation The coordinate operation to replace. * @return A new operation, or {@code operation} if no change were needed. * @throws FactoryException if an error occured while creating the new operation object. */ // @Override protected CoordinateOperation replace(final CoordinateOperation operation) throws FactoryException { final CoordinateReferenceSystem oldSrcCRS = operation.getSourceCRS(); final CoordinateReferenceSystem oldTgtCRS = operation.getTargetCRS(); final CoordinateReferenceSystem sourceCRS = (oldSrcCRS != null) ? replace(oldSrcCRS) : null; final CoordinateReferenceSystem targetCRS = (oldTgtCRS != null) ? replace(oldTgtCRS) : null; if (Utilities.equals(oldSrcCRS, sourceCRS) && Utilities.equals(oldTgtCRS, targetCRS)) { return operation; } if (opFactory == null) { opFactory = getCoordinateOperationFactory(); } CoordinateOperation modified; modified = opFactory.createOperation(sourceCRS, targetCRS); modified = (CoordinateOperation) pool.unique(modified); return modified; }
/** * A datum identical to the specified datum except for the prime meridian, which is replaced by * Greenwich. This datum is processed in a special way by {@link #equalsIgnorePrimeMeridian}. */ private static final class TemporaryDatum extends DefaultGeodeticDatum { /** For cros-version compatibility. */ private static final long serialVersionUID = -8964199103509187219L; /** The wrapped datum. */ private final GeodeticDatum datum; /** Wrap the specified datum. */ public TemporaryDatum(final GeodeticDatum datum) { super(getTemporaryName(datum), datum.getEllipsoid(), DefaultPrimeMeridian.GREENWICH); this.datum = datum; } /** Unwrap the datum. */ public static GeodeticDatum unwrap(GeodeticDatum datum) { while (datum instanceof TemporaryDatum) { datum = ((TemporaryDatum) datum).datum; } return datum; } /** Compares this datum with the specified object for equality. */ @Override public boolean equals( final AbstractIdentifiedObject object, final boolean compareMetadata) { if (super.equals(object, compareMetadata)) {
/** Tests transformation involving 3D Geographic CRS. */ @Test public void testGeographic3D_ZFirst() throws Exception { final CoordinateReferenceSystem sourceCRS = crsFactory.createFromWKT(Z_NAD27); final CoordinateReferenceSystem targetCRS = crsFactory.createFromWKT(WGS84_Z); final CoordinateOperation op = opFactory.createOperation(sourceCRS, targetCRS); final MathTransform mt = op.getMathTransform(); assertNotSame(sourceCRS, op.getSourceCRS()); assertNotSame(targetCRS, op.getTargetCRS()); assertTrue(op instanceof Transformation); assertTrue(sourceCRS instanceof CompoundCRS); assertTrue(op.getSourceCRS() instanceof GeographicCRS); // 2D + 1D ---> 3D assertTrue(targetCRS instanceof CompoundCRS); assertTrue(op.getTargetCRS() instanceof GeographicCRS); // 2D + 1D ---> 3D assertFalse(sourceCRS.equals(targetCRS)); assertFalse(op.getSourceCRS().equals(op.getTargetCRS())); assertFalse(mt.isIdentity()); assertInterfaced(mt); // Note: Expected values below were computed with Geotools (not an external library). // However, it was tested with both Molodenski and Geocentric transformations. assertTransformEquals3_3( mt, 0, 0, 0, 0.001654978796746043, 0.0012755944235822696, 66.4042236590758); assertTransformEquals3_3( mt, -20, 5, 8, 5.001262964005206, 8.001271737831601, 80.2792978901416); }
assertSame(sourceCRS, operation.getSourceCRS()); assertSame(targetCRS, operation.getTargetCRS()); assertSame(targetCRS, operation.getSourceCRS()); assertSame(sourceCRS, operation.getTargetCRS());
/** Tests transformation involving 3D Geographic CRS. */ @Test public void testGeographic3D() throws Exception { final CoordinateReferenceSystem sourceCRS = crsFactory.createFromWKT(NAD27_Z); final CoordinateReferenceSystem targetCRS = crsFactory.createFromWKT(WGS84_Z); final CoordinateOperation op = opFactory.createOperation(sourceCRS, targetCRS); final MathTransform mt = op.getMathTransform(); assertNotSame(sourceCRS, op.getSourceCRS()); assertNotSame(targetCRS, op.getTargetCRS()); assertTrue(op instanceof Transformation); assertTrue(sourceCRS instanceof CompoundCRS); assertTrue(op.getSourceCRS() instanceof GeographicCRS); // 2D + 1D ---> 3D assertTrue(targetCRS instanceof CompoundCRS); assertTrue(op.getTargetCRS() instanceof GeographicCRS); // 2D + 1D ---> 3D assertFalse(sourceCRS.equals(targetCRS)); assertFalse(op.getSourceCRS().equals(op.getTargetCRS())); assertFalse(mt.isIdentity()); assertInterfaced(mt); // Note: Expected values below were computed with Geotools (not an external library). // However, it was tested with both Molodenski and Geocentric transformations. assertTransformEquals3_3( mt, 0, 0, 0, 0.001654978796746043, 0.0012755944235822696, 66.4042236590758); assertTransformEquals3_3( mt, 5, 8, 20, 5.0012629560319874, 8.001271729856333, 120.27929787151515); assertTransformEquals3_3( mt, 5, 8, -20, 5.001262964005206, 8.001271737831601, 80.2792978901416); assertTransformEquals3_3( mt, -5, -8, -20, -4.99799698932651, -7.998735783965731, 9.007854541763663); }
assertTrue(operation.getSourceCRS() instanceof ProjectedCRS); assertTrue(operation.getTargetCRS() instanceof GeocentricCRS); assertTrue(operation.getTargetCRS().getCoordinateSystem() instanceof CartesianCS);
/** Should fails unless GEOT-352 has been fixed. */ @Test(expected = OperationNotFoundException.class) public void testHtoH() throws Exception { final CoordinateReferenceSystem sourceCRS = crsFactory.createFromWKT(NAD27_H); final CoordinateReferenceSystem targetCRS = crsFactory.createFromWKT(WGS84_H); final CoordinateOperation op = opFactory.createOperation(sourceCRS, targetCRS); final MathTransform mt = op.getMathTransform(); assertNotSame(sourceCRS, op.getSourceCRS()); assertNotSame(targetCRS, op.getTargetCRS()); assertFalse(mt.isIdentity()); assertInterfaced(mt); }
/** Should fails unless GEOT-352 has been fixed. */ @Test(expected = OperationNotFoundException.class) public void testHtoZ() throws Exception { final CoordinateReferenceSystem sourceCRS = crsFactory.createFromWKT(NAD27_H); final CoordinateReferenceSystem targetCRS = crsFactory.createFromWKT(NAD27_Z); final CoordinateOperation op = opFactory.createOperation(sourceCRS, targetCRS); final MathTransform mt = op.getMathTransform(); assertNotSame(sourceCRS, op.getSourceCRS()); assertNotSame(targetCRS, op.getTargetCRS()); assertFalse(mt.isIdentity()); assertInterfaced(mt); }
/** Should fails unless GEOT-352 has been fixed. */ @Test(expected = OperationNotFoundException.class) public void test2DtoH() throws Exception { final CoordinateReferenceSystem sourceCRS = crsFactory.createFromWKT(WKT.NAD27); final CoordinateReferenceSystem targetCRS = crsFactory.createFromWKT(WGS84_H); final CoordinateOperation op = opFactory.createOperation(sourceCRS, targetCRS); final MathTransform mt = op.getMathTransform(); if (usingDefaultFactory) { assertSame(sourceCRS, op.getSourceCRS()); assertNotSame(targetCRS, op.getTargetCRS()); } assertFalse(mt.isIdentity()); assertInterfaced(mt); }
/** Tests transformation between vertical CRS. */ @Test public void testZIdentity() throws Exception { final CoordinateReferenceSystem sourceCRS = crsFactory.createFromWKT(WKT.Z); final CoordinateReferenceSystem targetCRS = crsFactory.createFromWKT(WKT.Z); final CoordinateOperation op = opFactory.createOperation(sourceCRS, targetCRS); final MathTransform mt = op.getMathTransform(); if (usingDefaultFactory) { assertSame(sourceCRS, op.getSourceCRS()); assertSame(targetCRS, op.getTargetCRS()); } assertTrue(op instanceof Conversion); assertTrue(mt.isIdentity()); assertInterfaced(mt); }
/** Tests transformation between vertical CRS. */ @Test public void testHeightIdentity() throws Exception { final CoordinateReferenceSystem sourceCRS = crsFactory.createFromWKT(WKT.HEIGHT); final CoordinateReferenceSystem targetCRS = crsFactory.createFromWKT(WKT.HEIGHT); final CoordinateOperation op = opFactory.createOperation(sourceCRS, targetCRS); final MathTransform mt = op.getMathTransform(); if (usingDefaultFactory) { assertSame(sourceCRS, op.getSourceCRS()); assertSame(targetCRS, op.getTargetCRS()); } assertTrue(op instanceof Conversion); assertTrue(mt.isIdentity()); assertInterfaced(mt); }
/** Tests transformation from 3D to vertical CRS. */ @Test public void test3D_to_Z() throws Exception { final CoordinateReferenceSystem sourceCRS = crsFactory.createFromWKT(NAD27_Z); final CoordinateReferenceSystem targetCRS = crsFactory.createFromWKT(WKT.Z); final CoordinateOperation op = opFactory.createOperation(sourceCRS, targetCRS); final MathTransform mt = op.getMathTransform(); if (usingDefaultFactory) { assertSame(sourceCRS, op.getSourceCRS()); assertSame(targetCRS, op.getTargetCRS()); } assertFalse(mt.isIdentity()); assertInterfaced(mt); assertTransformEquals3_1(mt, 0, 0, 0, 0); assertTransformEquals3_1(mt, 5, 8, 20, 20); assertTransformEquals3_1(mt, -5, -8, 20, 20); }
/** Tests transformation from a 3D Geographic CRS to a single height. */ @Test public void test3D_to_H() throws Exception { final CoordinateReferenceSystem sourceCRS = crsFactory.createFromWKT(NAD27_H); final CoordinateReferenceSystem targetCRS = crsFactory.createFromWKT(WKT.HEIGHT); final CoordinateOperation op = opFactory.createOperation(sourceCRS, targetCRS); final MathTransform mt = op.getMathTransform(); if (usingDefaultFactory) { assertSame(sourceCRS, op.getSourceCRS()); assertSame(targetCRS, op.getTargetCRS()); } assertFalse(mt.isIdentity()); assertInterfaced(mt); assertTransformEquals3_1(mt, 0, 0, 0, 0); assertTransformEquals3_1(mt, 5, 8, 20, 20); assertTransformEquals3_1(mt, -5, -8, 20, 20); }
assertSame(sourceCRS, operation.getSourceCRS()); assertSame(targetCRS, operation.getTargetCRS());
/** Tests transformation from 2D to 3D with Z above the ellipsoid. */ @Test public void test2D_to_3D() throws Exception { final CoordinateReferenceSystem sourceCRS = crsFactory.createFromWKT(WKT.NAD27); final CoordinateReferenceSystem targetCRS = crsFactory.createFromWKT(WGS84_Z); final CoordinateOperation op = opFactory.createOperation(sourceCRS, targetCRS); final MathTransform mt = op.getMathTransform(); if (usingDefaultFactory) { assertSame(sourceCRS, op.getSourceCRS()); assertNotSame(targetCRS, op.getTargetCRS()); } assertFalse(mt.isIdentity()); assertInterfaced(mt); // Note: Expected values below were computed with Geotools (not an external library). // However, it was tested with both Molodenski and Geocentric transformations. assertTransformEquals2_3( mt, 0, 0, 0.001654978796746043, 0.0012755944235822696, 66.4042236590758); assertTransformEquals2_3( mt, 5, 8, 5.001262960018587, 8.001271733843957, 100.27929787896574); }
/** Tests transformation from 3D to 2D Geographic CRS. */ @Test public void test3D_to_2D() throws Exception { final CoordinateReferenceSystem sourceCRS = crsFactory.createFromWKT(NAD27_Z); final CoordinateReferenceSystem targetCRS = crsFactory.createFromWKT(WKT.WGS84_DMHS); final CoordinateOperation op = opFactory.createOperation(sourceCRS, targetCRS); final MathTransform mt = op.getMathTransform(); if (usingDefaultFactory) { assertNotSame(sourceCRS, op.getSourceCRS()); assertSame(targetCRS, op.getTargetCRS()); } assertFalse(mt.isIdentity()); assertInterfaced(mt); // Note: Expected values below were computed with Geotools (not an external library). // However, it was tested with both Molodenski and Geocentric transformations. assertTransformEquals3_2(mt, 0, 0, 0, 0.001654978796746043, 0.0012755944235822696); assertTransformEquals3_2(mt, 5, 8, 20, 5.0012629560319874, 8.001271729856333); assertTransformEquals3_2(mt, 5, 8, -20, 5.001262964005206, 8.001271737831601); }
/** Tests transformation from 4D to 2D projected. */ @Test public void test4D_to_2D() throws Exception { final CoordinateReferenceSystem targetCRS = crsFactory.createFromWKT(WKT.MERCATOR); CoordinateReferenceSystem sourceCRS = targetCRS; sourceCRS = new DefaultCompoundCRS( "Mercator 3D", sourceCRS, DefaultVerticalCRS.ELLIPSOIDAL_HEIGHT); sourceCRS = new DefaultCompoundCRS( "Mercator 4D", sourceCRS, DefaultTemporalCRS.MODIFIED_JULIAN); final CoordinateOperation op = opFactory.createOperation(sourceCRS, targetCRS); final MathTransform mt = op.getMathTransform(); if (usingDefaultFactory) { assertSame(sourceCRS, op.getSourceCRS()); assertSame(targetCRS, op.getTargetCRS()); } assertFalse(mt.isIdentity()); assertTrue( "The somewhat complex MathTransform chain should have been simplified " + "to a single affine transform.", mt instanceof LinearTransform); assertTrue( "The operation should be a simple axis change, not a complex" + "chain of ConcatenatedOperations.", op instanceof Conversion); }
/** Tests a CRS involving DMHS units. */ @Test public void testDMHS() throws Exception { final CoordinateReferenceSystem sourceCRS = crsFactory.createFromWKT(WKT.NAD27); final CoordinateReferenceSystem targetCRS = crsFactory.createFromWKT(WKT.WGS84_DMHS); final CoordinateOperation op = opFactory.createOperation(sourceCRS, targetCRS); final MathTransform mt = op.getMathTransform(); assertTrue(op instanceof Transformation); if (usingDefaultFactory) { assertSame(sourceCRS, op.getSourceCRS()); assertSame(targetCRS, op.getTargetCRS()); } assertFalse(mt.isIdentity()); assertInterfaced(mt); if (usingDefaultFactory) { // Note: Expected values below were computed with Geotools (not an external library). // However, it was tested with both Molodenski and Geocentric transformations. assertTransformEquals2_2(mt, 0.0, 0.0, 0.001654978796746043, 0.0012755944235822696); assertTransformEquals2_2(mt, 5.0, 8.0, 5.001262960018587, 8.001271733843957); } }