Search in sources :

Example 1 with CoordinateOperation

use of org.opengis.referencing.operation.CoordinateOperation in project sis by apache.

the class EPSGFactoryTest method testCreateFromCoordinateReferenceSystemCodes.

/**
 * Tests {@link EPSGDataAccess#createFromCoordinateReferenceSystemCodes(String, String)}.
 * This method verifies the presence of 3 {@link Transformation} instances between the same source and target CRS.
 *
 * @throws FactoryException if an error occurred while querying the factory.
 */
@Test
@DependsOnMethod("testTransformation")
public void testCreateFromCoordinateReferenceSystemCodes() throws FactoryException {
    final EPSGFactory factory = TestFactorySource.factory;
    assumeNotNull(factory);
    /*
         * ED50 (4230)  to  WGS 84 (4326)  using
         * Geocentric translations (9603).
         * Accuracy = 2.5
         */
    final CoordinateOperation operation1 = factory.createCoordinateOperation("1087");
    final CoordinateReferenceSystem sourceCRS = operation1.getSourceCRS();
    final CoordinateReferenceSystem targetCRS = operation1.getTargetCRS();
    final MathTransform transform = operation1.getMathTransform();
    assertInstanceOf("EPSG::1087", Transformation.class, operation1);
    assertEpsgNameAndIdentifierEqual("ED50 to WGS 84 (37)", 1087, operation1);
    assertEpsgNameAndIdentifierEqual("ED50", 4230, sourceCRS);
    assertEpsgNameAndIdentifierEqual("WGS 84", 4326, targetCRS);
    assertFalse("transform.isIdentity()", operation1.getMathTransform().isIdentity());
    assertEquals(2.5, AbstractCoordinateOperation.castOrCopy(operation1).getLinearAccuracy(), STRICT);
    /*
         * ED50 (4230)  to  WGS 84 (4326)  using
         * Position Vector 7-param. transformation (9606).
         * Accuracy = 1.5
         */
    final CoordinateOperation operation2 = factory.createCoordinateOperation("1631");
    assertEpsgNameAndIdentifierEqual("ED50 to WGS 84 (27)", 1631, operation2);
    assertInstanceOf("EPSG::1631", Transformation.class, operation2);
    assertSame("sourceCRS", sourceCRS, operation2.getSourceCRS());
    assertSame("targetCRS", targetCRS, operation2.getTargetCRS());
    assertFalse("transform.isIdentity()", operation2.getMathTransform().isIdentity());
    assertFalse("Should be a more accurate transformation.", transform.equals(operation2.getMathTransform()));
    assertEquals(1.5, AbstractCoordinateOperation.castOrCopy(operation2).getLinearAccuracy(), STRICT);
    /*
         * ED50 (4230)  to  WGS 84 (4326)  using
         * Coordinate Frame rotation (9607).
         * Accuracy = 1.0
         */
    final CoordinateOperation operation3 = factory.createCoordinateOperation("1989");
    assertInstanceOf("EPSG::1989", Transformation.class, operation3);
    assertEpsgNameAndIdentifierEqual("ED50 to WGS 84 (34)", 1989, operation3);
    assertSame("sourceCRS", sourceCRS, operation3.getSourceCRS());
    assertSame("targetCRS", targetCRS, operation3.getTargetCRS());
    assertFalse("transform.isIdentity()", operation3.getMathTransform().isIdentity());
    assertFalse("Should be a more accurate transformation.", transform.equals(operation3.getMathTransform()));
    assertEquals(1.0, AbstractCoordinateOperation.castOrCopy(operation3).getLinearAccuracy(), STRICT);
    /*
         * Creates from CRS codes. There is 40 such operations in EPSG version 6.7.
         * The preferred one (according the "supersession" table) is EPSG:1612.
         */
    final Set<CoordinateOperation> all = factory.createFromCoordinateReferenceSystemCodes("4230", "4326");
    assertTrue("Number of coordinate operations.", all.size() >= 3);
    assertTrue("contains(“EPSG::1087”)", all.contains(operation1));
    assertTrue("contains(“EPSG::1631”)", all.contains(operation2));
    assertTrue("contains(“EPSG::1989”)", all.contains(operation3));
    int count = 0;
    for (final CoordinateOperation tr : all) {
        assertSame("sourceCRS", sourceCRS, tr.getSourceCRS());
        assertSame("targetCRS", targetCRS, tr.getTargetCRS());
        if (count == 0) {
            // Preferred transformation (see above comment).
            assertEpsgNameAndIdentifierEqual("ED50 to WGS 84 (23)", 1612, tr);
        }
        count++;
    }
    // Size may have been modified after above loop.
    assertEquals(count, all.size());
    // Too installation-dependent for testing them.
    loggings.clear();
}
Also used : MathTransform(org.opengis.referencing.operation.MathTransform) AbstractCoordinateOperation(org.apache.sis.referencing.operation.AbstractCoordinateOperation) CoordinateOperation(org.opengis.referencing.operation.CoordinateOperation) Test(org.junit.Test) DependsOnMethod(org.apache.sis.test.DependsOnMethod)

Example 2 with CoordinateOperation

use of org.opengis.referencing.operation.CoordinateOperation in project sis by apache.

the class EPSGFactoryTest method testTransformation.

/**
 * Tests "BD72 to WGS 84 (1)" (EPSG:1609) transformation. This one has an unusual unit for the
 * "Scale difference" parameter (EPSG:8611). The value is 0.999999 and the unit is "unity" (EPSG:9201)
 * instead of the usual "parts per million" (EPSG:9202).
 *
 * @throws FactoryException if an error occurred while querying the factory.
 */
@Test
@DependsOnMethod("testSimpleTransformation")
public void testTransformation() throws FactoryException {
    final EPSGFactory factory = TestFactorySource.factory;
    assumeNotNull(factory);
    final CoordinateOperation operation = factory.createCoordinateOperation("1609");
    assertEpsgNameAndIdentifierEqual("BD72 to WGS 84 (1)", 1609, operation);
    assertEquals(1.0, ((AbstractCoordinateOperation) operation).getLinearAccuracy(), STRICT);
    assertSame("Operation shall be cached", operation, factory.createCoordinateOperation("1609"));
}
Also used : AbstractCoordinateOperation(org.apache.sis.referencing.operation.AbstractCoordinateOperation) CoordinateOperation(org.opengis.referencing.operation.CoordinateOperation) Test(org.junit.Test) DependsOnMethod(org.apache.sis.test.DependsOnMethod)

Example 3 with CoordinateOperation

use of org.opengis.referencing.operation.CoordinateOperation in project sis by apache.

the class CoordinateOperationFinderTest method testSpatioTemporalToDerived.

/**
 * Tests conversion from spatio-temporal CRS to a derived CRS.
 *
 * @throws FactoryException if the operation can not be created.
 * @throws TransformException if an error occurred while converting the test points.
 */
@Test
@DependsOnMethod("testProjected4D_to_2D")
public void testSpatioTemporalToDerived() throws FactoryException, TransformException {
    final Map<String, Object> properties = new HashMap<>();
    properties.put(DerivedCRS.NAME_KEY, "Display");
    properties.put("conversion.name", "Display to WGS84");
    final GeographicCRS WGS84 = CommonCRS.WGS84.normalizedGeographic();
    final CompoundCRS sourceCRS = compound("Test3D", WGS84, CommonCRS.Temporal.UNIX.crs());
    final DerivedCRS targetCRS = DefaultDerivedCRS.create(properties, WGS84, null, factory.getOperationMethod("Affine"), MathTransforms.linear(Matrices.create(3, 3, new double[] { 12, 0, 480, 0, -12, 790, 0, 0, 1 })), HardCodedCS.DISPLAY);
    final CoordinateOperation operation = finder.createOperation(sourceCRS, targetCRS);
    assertSame("sourceCRS", sourceCRS, operation.getSourceCRS());
    assertSame("targetCRS", targetCRS, operation.getTargetCRS());
    transform = operation.getMathTransform();
    assertInstanceOf("transform", LinearTransform.class, transform);
    assertEquals("sourceDimensions", 3, transform.getSourceDimensions());
    assertEquals("targetDimensions", 2, transform.getTargetDimensions());
    Assert.assertMatrixEquals("transform.matrix", Matrices.create(3, 4, new double[] { 12, 0, 0, 480, 0, -12, 0, 790, 0, 0, 0, 1 }), ((LinearTransform) transform).getMatrix(), STRICT);
    validate();
}
Also used : HashMap(java.util.HashMap) CompoundCRS(org.opengis.referencing.crs.CompoundCRS) DefaultCompoundCRS(org.apache.sis.referencing.crs.DefaultCompoundCRS) DerivedCRS(org.opengis.referencing.crs.DerivedCRS) DefaultDerivedCRS(org.apache.sis.referencing.crs.DefaultDerivedCRS) CoordinateOperation(org.opengis.referencing.operation.CoordinateOperation) GeographicCRS(org.opengis.referencing.crs.GeographicCRS) Test(org.junit.Test) DependsOnMethod(org.apache.sis.test.DependsOnMethod)

Example 4 with CoordinateOperation

use of org.opengis.referencing.operation.CoordinateOperation in project sis by apache.

the class CoordinateOperationFinderTest method testGeographic3D_to_2D.

/**
 * Tests the conversion from a three-dimensional geographic CRS to a two-dimensional geographic CRS.
 * The vertical dimension is simply dropped.
 *
 * @throws FactoryException if the operation can not be created.
 * @throws TransformException if an error occurred while converting the test points.
 */
@Test
@DependsOnMethod("testIdentityTransform")
public void testGeographic3D_to_2D() throws FactoryException, TransformException {
    final GeographicCRS sourceCRS = CommonCRS.WGS84.geographic3D();
    final GeographicCRS targetCRS = CommonCRS.WGS84.geographic();
    final CoordinateOperation operation = finder.createOperation(sourceCRS, targetCRS);
    assertSame("sourceCRS", sourceCRS, operation.getSourceCRS());
    assertSame("targetCRS", targetCRS, operation.getTargetCRS());
    assertEquals("name", "Axis changes", operation.getName().getCode());
    assertInstanceOf("operation", Conversion.class, operation);
    final ParameterValueGroup parameters = ((SingleOperation) operation).getParameterValues();
    assertEquals("parameters.descriptor", "Geographic3D to 2D conversion", parameters.getDescriptor().getName().getCode());
    assertTrue("parameters.isEmpty", parameters.values().isEmpty());
    transform = operation.getMathTransform();
    assertInstanceOf("transform", LinearTransform.class, transform);
    assertEquals("sourceDimensions", 3, transform.getSourceDimensions());
    assertEquals("targetDimensions", 2, transform.getTargetDimensions());
    Assert.assertMatrixEquals("transform.matrix", Matrices.create(3, 4, new double[] { 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1 }), ((LinearTransform) transform).getMatrix(), STRICT);
    isInverseTransformSupported = false;
    verifyTransform(new double[] { 30, 10, 20, 20, 30, -10 }, new double[] { 30, 10, 20, 30 });
    validate();
}
Also used : ParameterValueGroup(org.opengis.parameter.ParameterValueGroup) CoordinateOperation(org.opengis.referencing.operation.CoordinateOperation) GeographicCRS(org.opengis.referencing.crs.GeographicCRS) SingleOperation(org.opengis.referencing.operation.SingleOperation) Test(org.junit.Test) DependsOnMethod(org.apache.sis.test.DependsOnMethod)

Example 5 with CoordinateOperation

use of org.opengis.referencing.operation.CoordinateOperation in project sis by apache.

the class CoordinateOperationFinderTest method testPositionVectorTransformation.

/**
 * Tests a datum shift applied as a position vector transformation in geocentric domain.
 * This test does not use the the EPSG geodetic dataset.
 *
 * @throws ParseException if a CRS used in this test can not be parsed.
 * @throws FactoryException if the operation can not be created.
 * @throws TransformException if an error occurred while converting the test points.
 *
 * @see DefaultCoordinateOperationFactoryTest#testPositionVectorTransformation()
 * @see <a href="https://issues.apache.org/jira/browse/SIS-364">SIS-364</a>
 *
 * @since 0.8
 */
@Test
@DependsOnMethod("testGeographicToProjected")
public void testPositionVectorTransformation() throws ParseException, FactoryException, TransformException {
    final CoordinateReferenceSystem sourceCRS = CommonCRS.WGS84.geographic();
    final CoordinateReferenceSystem targetCRS = parse(AGD66());
    final CoordinateOperation operation = finder.createOperation(sourceCRS, targetCRS);
    transform = operation.getMathTransform();
    tolerance = LINEAR_TOLERANCE;
    λDimension = new int[] { 0 };
    verifyTransform(expectedAGD66(true), expectedAGD66(false));
    validate();
}
Also used : CoordinateOperation(org.opengis.referencing.operation.CoordinateOperation) CoordinateReferenceSystem(org.opengis.referencing.crs.CoordinateReferenceSystem) Test(org.junit.Test) DependsOnMethod(org.apache.sis.test.DependsOnMethod)

Aggregations

CoordinateOperation (org.opengis.referencing.operation.CoordinateOperation)45 Test (org.junit.Test)32 CoordinateReferenceSystem (org.opengis.referencing.crs.CoordinateReferenceSystem)24 DependsOnMethod (org.apache.sis.test.DependsOnMethod)21 CompoundCRS (org.opengis.referencing.crs.CompoundCRS)6 GeographicCRS (org.opengis.referencing.crs.GeographicCRS)6 SingleOperation (org.opengis.referencing.operation.SingleOperation)6 AbstractCoordinateOperation (org.apache.sis.referencing.operation.AbstractCoordinateOperation)5 DefaultCompoundCRS (org.apache.sis.referencing.crs.DefaultCompoundCRS)4 ParameterValueGroup (org.opengis.parameter.ParameterValueGroup)4 ConcatenatedOperation (org.opengis.referencing.operation.ConcatenatedOperation)4 MathTransform (org.opengis.referencing.operation.MathTransform)3 Extent (org.opengis.metadata.extent.Extent)2 ReferenceSystem (org.opengis.referencing.ReferenceSystem)2 OperationMethod (org.opengis.referencing.operation.OperationMethod)2 TransformException (org.opengis.referencing.operation.TransformException)2 Transformation (org.opengis.referencing.operation.Transformation)2 FactoryException (org.opengis.util.FactoryException)2 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1