Search in sources :

Example 1 with Matrix

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

the class TensorValuesTest method testWKT2.

/**
 * Tests {@link TensorParameters#ALPHANUM} formatting.
 * <ul>
 *   <li>Group name shall be {@code "Affine parametric transformation"}.</li>
 *   <li>No {@code "num_row"} or {@code "num_col"} parameters if their value is equals to 3.</li>
 *   <li>Parameter names shall be of the form {@code "A0"}.</li>
 *   <li>Identifiers present, but only for A0-A2 and B0-B2.</li>
 * </ul>
 */
@Test
public void testWKT2() {
    final Matrix matrix = Matrices.createIdentity(3);
    matrix.setElement(0, 2, 4);
    matrix.setElement(1, 0, -2);
    matrix.setElement(2, 2, 7);
    final ParameterValueGroup group = TensorParameters.ALPHANUM.createValueGroup(singletonMap(TensorValues.NAME_KEY, Affine.NAME), matrix);
    validate(group);
    assertWktEquals("PARAMETERGROUP[“Affine parametric transformation”,\n" + "  PARAMETER[“A2”, 4.0, ID[“EPSG”, 8625]],\n" + "  PARAMETER[“B0”, -2.0, ID[“EPSG”, 8639]],\n" + "  PARAMETER[“C2”, 7.0]]", group);
}
Also used : Matrix(org.opengis.referencing.operation.Matrix) ParameterValueGroup(org.opengis.parameter.ParameterValueGroup) Test(org.junit.Test)

Example 2 with Matrix

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

the class TensorValuesTest method testWKT1.

/**
 * Tests {@link TensorParameters#WKT1} formatting.
 * <ul>
 *   <li>Group name shall be {@code "Affine"}.</li>
 *   <li>Parameters {@code "num_row"} and {@code "num_col"} are mandatory.</li>
 *   <li>Parameter names shall be of the form {@code "elt_0_0"}.</li>
 *   <li>No identifier.</li>
 * </ul>
 */
@Test
public void testWKT1() {
    final Matrix matrix = Matrices.createIdentity(3);
    matrix.setElement(0, 2, 4);
    matrix.setElement(1, 0, -2);
    matrix.setElement(2, 2, 7);
    final ParameterValueGroup group = TensorParameters.WKT1.createValueGroup(singletonMap(TensorValues.NAME_KEY, Constants.AFFINE), matrix);
    validate(group);
    assertWktEquals("PARAMETERGROUP[“Affine”,\n" + // Shall be shown even if equals to the default value.
    "  PARAMETER[“num_row”, 3],\n" + "  PARAMETER[“num_col”, 3],\n" + "  PARAMETER[“elt_0_2”, 4.0],\n" + "  PARAMETER[“elt_1_0”, -2.0],\n" + "  PARAMETER[“elt_2_2”, 7.0]]", group);
}
Also used : Matrix(org.opengis.referencing.operation.Matrix) ParameterValueGroup(org.opengis.parameter.ParameterValueGroup) Test(org.junit.Test)

Example 3 with Matrix

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

the class GeodeticObjectParserTest method testMathTransform.

/**
 * Tests the {@link MathTransform} between North-Orientated and South-Orientated cases.
 *
 * @throws ParseException if the parsing failed.
 * @throws NoninvertibleTransformException if computation of the conversion from North-Orientated
 *         to South-Orientated failed.
 */
@Test
@DependsOnMethod("testProjectedCRS")
public void testMathTransform() throws ParseException, NoninvertibleTransformException {
    /*
         * Test "Transverse Mercator" (not south-oriented) with an axis oriented toward south.
         * The 'south' transform is actually the usual Transverse Mercator projection, despite
         * having axis oriented toward South.  Consequently the "False Northing" parameter has
         * the same meaning for those two CRS. Since we assigned the same False Northing value,
         * those two CRS have their "False origin" at the same location. This is why conversion
         * from 'south' to 'north' introduce no translation, only a reversal of y axis.
         */
    ProjectedCRS north = parseTransverseMercator(false, false, 1000);
    assertEquals(AxisDirection.WEST, north.getCoordinateSystem().getAxis(0).getDirection());
    assertEquals(AxisDirection.NORTH, north.getCoordinateSystem().getAxis(1).getDirection());
    ProjectedCRS south = parseTransverseMercator(false, true, 1000);
    assertEquals(AxisDirection.WEST, south.getCoordinateSystem().getAxis(0).getDirection());
    assertEquals(AxisDirection.SOUTH, south.getCoordinateSystem().getAxis(1).getDirection());
    Matrix matrix = conversion(north, south);
    assertEquals("West direction should be unchanged. ", +1, matrix.getElement(0, 0), STRICT);
    assertEquals("North-South direction should be reverted.", -1, matrix.getElement(1, 1), STRICT);
    assertEquals("No easting expected.", 0, matrix.getElement(0, 2), STRICT);
    assertEquals("No northing expected.", 0, matrix.getElement(1, 2), STRICT);
    assertDiagonalEquals(new double[] { +1, -1, 1 }, true, matrix, STRICT);
    /*
         * Test "Transverse Mercator South Orientated". In this projection, the "False Northing" parameter
         * is actually a "False Southing". It may sound surprising, but "South Orientated" projections are
         * defined that way.  For converting from our CRS having a False Northing of 1000 to a CRS without
         * False Northing or Southing, we must subtract 1000 from the axis which is oriented toward North.
         * This means adding 1000 if the axis is rather oriented toward South. Then we add another 1000 m
         * (the value specified in the line just below) toward South.
         */
    // "False Southing" of 1000 metres.
    south = parseTransverseMercator(true, true, 1000);
    assertEquals(AxisDirection.WEST, south.getCoordinateSystem().getAxis(0).getDirection());
    assertEquals(AxisDirection.SOUTH, south.getCoordinateSystem().getAxis(1).getDirection());
    matrix = conversion(north, south);
    assertEquals("West direction should be unchanged. ", +1, matrix.getElement(0, 0), STRICT);
    assertEquals("North-South direction should be reverted.", -1, matrix.getElement(1, 1), STRICT);
    assertEquals("No easting expected.", 0, matrix.getElement(0, 2), STRICT);
    assertEquals("Northing expected.", 2000, matrix.getElement(1, 2), STRICT);
}
Also used : Matrix(org.opengis.referencing.operation.Matrix) Test(org.junit.Test) DependsOnMethod(org.apache.sis.test.DependsOnMethod)

Example 4 with Matrix

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

the class TensorParametersTest method testMatrixConversion.

/**
 * Tests {@link TensorParameters#createValueGroup(Map, Matrix)} and its converse
 * {@link TensorParameters#toMatrix(ParameterValueGroup)}.
 */
@Test
@DependsOnMethod("testGetAllDescriptors")
public void testMatrixConversion() {
    final int size = StrictMath.min(6, TensorParameters.CACHE_SIZE);
    final Random random = TestUtilities.createRandomNumberGenerator();
    for (int numRow = 2; numRow <= size; numRow++) {
        for (int numCol = 2; numCol <= size; numCol++) {
            final Matrix matrix = Matrices.createZero(numRow, numCol);
            for (int j = 0; j < numRow; j++) {
                for (int i = 0; i < numCol; i++) {
                    matrix.setElement(j, i, 200 * random.nextDouble() - 100);
                }
            }
            final ParameterValueGroup group = param.createValueGroup(singletonMap(ParameterDescriptor.NAME_KEY, "Test"), matrix);
            assertEquals(NUM_ROW, numRow, group.parameter(NUM_ROW).intValue());
            assertEquals(NUM_COL, numCol, group.parameter(NUM_COL).intValue());
            assertEquals("elements", matrix, param.toMatrix(group));
            assertEquals("elements", matrix, param.toMatrix(new ParameterValueGroupWrapper(group)));
        }
    }
}
Also used : Matrix(org.opengis.referencing.operation.Matrix) Random(java.util.Random) ParameterValueGroup(org.opengis.parameter.ParameterValueGroup) Test(org.junit.Test) DependsOnMethod(org.apache.sis.test.DependsOnMethod)

Example 5 with Matrix

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

the class CoordinateSystemsTest method testSwapAndScaleAxes2D.

/**
 * Tests {@link CoordinateSystems#swapAndScaleAxes(CoordinateSystem, CoordinateSystem)} for (λ,φ) ↔ (φ,λ).
 * This very common conversion is of critical importance to Apache SIS.
 *
 * @throws IncommensurableException if a conversion between incompatible units was attempted.
 */
@Test
public void testSwapAndScaleAxes2D() throws IncommensurableException {
    final CoordinateSystem λφ = new DefaultEllipsoidalCS(singletonMap(NAME_KEY, "(λ,φ)"), HardCodedAxes.GEODETIC_LONGITUDE, HardCodedAxes.GEODETIC_LATITUDE);
    final CoordinateSystem φλ = new DefaultEllipsoidalCS(singletonMap(NAME_KEY, "(φ,λ)"), HardCodedAxes.GEODETIC_LATITUDE, HardCodedAxes.GEODETIC_LONGITUDE);
    final Matrix expected = Matrices.create(3, 3, new double[] { 0, 1, 0, 1, 0, 0, 0, 0, 1 });
    assertTrue(swapAndScaleAxes(λφ, λφ).isIdentity());
    assertTrue(swapAndScaleAxes(φλ, φλ).isIdentity());
    assertMatrixEquals("(λ,φ) → (φ,λ)", expected, swapAndScaleAxes(λφ, φλ), STRICT);
    assertMatrixEquals("(φ,λ) → (λ,φ)", expected, swapAndScaleAxes(φλ, λφ), STRICT);
}
Also used : Matrix(org.opengis.referencing.operation.Matrix) CoordinateSystem(org.opengis.referencing.cs.CoordinateSystem) Test(org.junit.Test)

Aggregations

Matrix (org.opengis.referencing.operation.Matrix)63 Test (org.junit.Test)20 DependsOnMethod (org.apache.sis.test.DependsOnMethod)11 MathTransform (org.opengis.referencing.operation.MathTransform)8 HashMap (java.util.HashMap)6 ParameterValueGroup (org.opengis.parameter.ParameterValueGroup)6 NoninvertibleTransformException (org.opengis.referencing.operation.NoninvertibleTransformException)5 TransformException (org.opengis.referencing.operation.TransformException)5 FormattableObject (org.apache.sis.io.wkt.FormattableObject)4 DirectPosition1D (org.apache.sis.geometry.DirectPosition1D)3 ExtendedPrecisionMatrix (org.apache.sis.internal.referencing.ExtendedPrecisionMatrix)3 Matrix3 (org.apache.sis.referencing.operation.matrix.Matrix3)3 CoordinateSystem (org.opengis.referencing.cs.CoordinateSystem)3 FactoryException (org.opengis.util.FactoryException)3 DirectPosition2D (org.apache.sis.geometry.DirectPosition2D)2 DirectPositionView (org.apache.sis.internal.referencing.DirectPositionView)2 Parameterized (org.apache.sis.parameter.Parameterized)2 MatrixSIS (org.apache.sis.referencing.operation.matrix.MatrixSIS)2 GeneralParameterValue (org.opengis.parameter.GeneralParameterValue)2 ParameterValue (org.opengis.parameter.ParameterValue)2