Search in sources :

Example 11 with Matrix4

use of org.apache.sis.referencing.operation.matrix.Matrix4 in project sis by apache.

the class DefaultTransformationTest method createGeocentricTranslation.

/**
 * Creates a “Tokyo to JGD2000 (GSI)” transformation.
 */
static DefaultTransformation createGeocentricTranslation() {
    /*
         * The following code fills the parameter values AND creates itself the MathTransform instance
         * (indirectly, through the matrix). The later step is normally not our business, since we are
         * supposed to only fill the parameter values and let MathTransformFactory creates the transform
         * from the parameters. But we don't do the normal steps here because this class is a unit test:
         * we want to test DefaultTransformation in isolation of MathTransformFactory.
         */
    final Matrix4 translation = new Matrix4();
    final OperationMethod method = DefaultOperationMethodTest.create("Geocentric translations", "1031", "EPSG guidance note #7-2", 3, DefaultParameterDescriptorTest.createEPSG("X-axis translation", (short) 8605), DefaultParameterDescriptorTest.createEPSG("Y-axis translation", (short) 8606), DefaultParameterDescriptorTest.createEPSG("Z-axis translation", (short) 8607));
    final ParameterValueGroup pg = method.getParameters().createValue();
    pg.parameter("X-axis translation").setValue(translation.m02 = -146.414);
    pg.parameter("Y-axis translation").setValue(translation.m12 = 507.337);
    pg.parameter("Z-axis translation").setValue(translation.m22 = 680.507);
    /*
         * In theory we should not need to provide the parameters explicitly to the constructor since
         * we are supposed to be able to find them from the MathTransform. But in this simple test we
         * did not bothered to define a specialized MathTransform class for our case. So we will help
         * a little bit DefaultTransformation by telling it the parameters that we used.
         */
    final Map<String, Object> properties = new HashMap<>(4);
    properties.put(DefaultTransformation.NAME_KEY, "Tokyo to JGD2000 (GSI)");
    properties.put(ReferencingServices.PARAMETERS_KEY, pg);
    return new DefaultTransformation(properties, // SourceCRS
    createCRS(null, HardCodedDatum.TOKYO), // TargetCRS
    createCRS("JGD2000", HardCodedDatum.JGD2000), // InterpolationCRS
    null, method, MathTransforms.linear(translation));
}
Also used : ParameterValueGroup(org.opengis.parameter.ParameterValueGroup) HashMap(java.util.HashMap) Matrix4(org.apache.sis.referencing.operation.matrix.Matrix4) OperationMethod(org.opengis.referencing.operation.OperationMethod)

Example 12 with Matrix4

use of org.apache.sis.referencing.operation.matrix.Matrix4 in project sis by apache.

the class BursaWolfParametersTest method testGetPositionVectorTransformation.

/**
 * Tests {@link BursaWolfParameters#getPositionVectorTransformation(Date)}.
 * This test transform a point from WGS72 to WGS84, and conversely,
 * as documented in the example section of EPSG operation method 9606.
 *
 * @throws NoninvertibleMatrixException Should never happen.
 */
@Test
public void testGetPositionVectorTransformation() throws NoninvertibleMatrixException {
    final BursaWolfParameters bursaWolf = createWGS72_to_WGS84();
    final MatrixSIS toWGS84 = getPositionVectorTransformation(bursaWolf);
    final MatrixSIS toWGS72 = toWGS84.inverse();
    final MatrixSIS source = Matrices.create(4, 1, new double[] { 3657660.66, 255768.55, 5201382.11, 1 });
    final MatrixSIS target = Matrices.create(4, 1, new double[] { 3657660.78, 255778.43, 5201387.75, 1 });
    assertMatrixEquals("toWGS84", target, toWGS84.multiply(source), 0.01);
    assertMatrixEquals("toWGS72", source, toWGS72.multiply(target), 0.01);
    /*
         * Tests the optimized path for translation-only parameters.
         * Matrices having only translation terms are much easier to predict.
         */
    assertMatrixEquals("Translation only", new Matrix4(1, 0, 0, -168, 0, 1, 0, -60, 0, 0, 1, 320, 0, 0, 0, 1), getPositionVectorTransformation(createNTF_to_WGS84()), 0);
}
Also used : MatrixSIS(org.apache.sis.referencing.operation.matrix.MatrixSIS) Matrix4(org.apache.sis.referencing.operation.matrix.Matrix4) Test(org.junit.Test)

Example 13 with Matrix4

use of org.apache.sis.referencing.operation.matrix.Matrix4 in project sis by apache.

the class BursaWolfParametersTest method getPositionVectorTransformation.

/**
 * Invokes {@link BursaWolfParameters#getPositionVectorTransformation(Date)}
 * and compares with our own matrix calculated using double arithmetic.
 */
private static MatrixSIS getPositionVectorTransformation(final BursaWolfParameters p) {
    final double S = 1 + p.dS / BursaWolfParameters.PPM;
    final double RS = TO_RADIANS * S;
    final Matrix4 expected = new Matrix4(S, -p.rZ * RS, +p.rY * RS, p.tX, +p.rZ * RS, S, -p.rX * RS, p.tY, -p.rY * RS, +p.rX * RS, S, p.tZ, 0, 0, 0, 1);
    final MatrixSIS matrix = MatrixSIS.castOrCopy(p.getPositionVectorTransformation(null));
    assertMatrixEquals("getPositionVectorTransformation", expected, matrix, p.isTranslation() ? 0 : 1E-14);
    return matrix;
}
Also used : Matrix4(org.apache.sis.referencing.operation.matrix.Matrix4) MatrixSIS(org.apache.sis.referencing.operation.matrix.MatrixSIS)

Aggregations

Matrix4 (org.apache.sis.referencing.operation.matrix.Matrix4)13 Test (org.junit.Test)7 MathTransform (org.opengis.referencing.operation.MathTransform)4 MatrixSIS (org.apache.sis.referencing.operation.matrix.MatrixSIS)3 DefaultParameterDescriptorTest (org.apache.sis.parameter.DefaultParameterDescriptorTest)2 DependsOnMethod (org.apache.sis.test.DependsOnMethod)2 HashMap (java.util.HashMap)1 DoubleDouble (org.apache.sis.internal.util.DoubleDouble)1 Parameters (org.apache.sis.parameter.Parameters)1 Matrix2 (org.apache.sis.referencing.operation.matrix.Matrix2)1 Matrix3 (org.apache.sis.referencing.operation.matrix.Matrix3)1 ParameterValueGroup (org.opengis.parameter.ParameterValueGroup)1 CartesianCS (org.opengis.referencing.cs.CartesianCS)1 CoordinateSystem (org.opengis.referencing.cs.CoordinateSystem)1 EllipsoidalCS (org.opengis.referencing.cs.EllipsoidalCS)1 SphericalCS (org.opengis.referencing.cs.SphericalCS)1 Conversion (org.opengis.referencing.operation.Conversion)1 MathTransformFactory (org.opengis.referencing.operation.MathTransformFactory)1 Matrix (org.opengis.referencing.operation.Matrix)1 OperationMethod (org.opengis.referencing.operation.OperationMethod)1