Search in sources :

Example 6 with Matrix3

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

the class NADCONTest method testNADCON.

/**
 * Implementation of {@link #testLoader()} and {@link #testNADCON(Path, Path)}.
 *
 * @param  xmin  westmost longitude.
 * @param  xmax  eastmost longitude.
 * @param  ymin  southmost latitude.
 * @param  ymax  northmost latitude.
 */
private static void testNADCON(final Path latitudeShifts, final Path longitudeShifts, final double xmin, final double xmax, final double ymin, final double ymax) throws IOException, FactoryException, TransformException {
    final DatumShiftGridFile<Angle, Angle> grid = NADCON.getOrLoad(latitudeShifts, longitudeShifts);
    assertInstanceOf("Should not be compressed.", DatumShiftGridFile.Float.class, grid);
    assertEquals("coordinateUnit", Units.DEGREE, grid.getCoordinateUnit());
    assertEquals("translationUnit", Units.DEGREE, grid.getTranslationUnit());
    assertEquals("translationDimensions", 2, grid.getTranslationDimensions());
    assertTrue("isCellValueRatio", grid.isCellValueRatio());
    assertTrue("cellPrecision", grid.getCellPrecision() > 0);
    /*
         * Verify the envelope and the conversion between geographic coordinates and grid indices.
         * The cells are expected to have the same size (0.25°) in longitudes and latitudes.
         */
    final double cellSize = 0.25;
    final Envelope envelope = grid.getDomainOfValidity();
    assertEquals("xmin", xmin - cellSize / 2, envelope.getMinimum(0), STRICT);
    assertEquals("xmax", xmax + cellSize / 2, envelope.getMaximum(0), STRICT);
    assertEquals("ymin", ymin - cellSize / 2, envelope.getMinimum(1), STRICT);
    assertEquals("ymax", ymax + cellSize / 2, envelope.getMaximum(1), STRICT);
    assertMatrixEquals("coordinateToGrid", new Matrix3(cellSize, 0, xmin, 0, cellSize, ymin, 0, 0, 1), grid.getCoordinateToGrid().inverse().getMatrix(), STRICT);
    /*
         * Test the Meades Ranch station. If we were using the complete Conus files, we would obtain
         * after conversion the grid indices listed on the left side. But since we are using a sub-set
         * of the grid, we rather obtain the grid indices on the right side.
         *
         *   gridX ≈ 129.83277 in official file,   ≈ 4.83277 in the test file.
         *   gridY ≈  76.89632 in official file,   ≈ 6.89632 in the test file.
         */
    final double[] position = samplePoint(1);
    final double[] expected = samplePoint(2);
    final double[] indices = new double[position.length];
    final double[] vector = new double[2];
    grid.getCoordinateToGrid().transform(position, 0, indices, 0, 1);
    grid.interpolateInCell(indices[0], indices[1], vector);
    vector[0] *= cellSize * DatumShiftGridLoader.DEGREES_TO_SECONDS;
    vector[1] *= cellSize * DatumShiftGridLoader.DEGREES_TO_SECONDS;
    assertArrayEquals("interpolateInCell", expected, vector, 0.5E-5);
    // Same test than above, but let DatumShiftGrid do the conversions for us.
    expected[0] /= DatumShiftGridLoader.DEGREES_TO_SECONDS;
    expected[1] /= DatumShiftGridLoader.DEGREES_TO_SECONDS;
    assertArrayEquals("interpolateAt", expected, grid.interpolateAt(position), ANGULAR_TOLERANCE);
    assertSame("Grid should be cached.", grid, NADCON.getOrLoad(latitudeShifts, longitudeShifts));
}
Also used : Angle(javax.measure.quantity.Angle) Envelope(org.opengis.geometry.Envelope) Matrix3(org.apache.sis.referencing.operation.matrix.Matrix3)

Example 7 with Matrix3

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

the class MathTransformsTest method testCompound.

/**
 * Tests {@link MathTransforms#compound(MathTransform...)}.
 * This test uses linear transforms because they are easy to test, but the
 * {@code MathTransforms.compound(…)} method should work with any transforms.
 */
@Test
public void testCompound() {
    final MathTransform t1 = MathTransforms.linear(new Matrix2(// Random numbers (no real meaning)
    3, // Random numbers (no real meaning)
    -1, 0, 1));
    final MathTransform t2 = MathTransforms.linear(new Matrix4(0, 8, 0, 9, 5, 0, 0, -7, 0, 0, 2, 0, 0, 0, 0, 1));
    final MathTransform t3 = MathTransforms.linear(new Matrix3(0, -5, -3, 7, 0, -9, 0, 0, 1));
    final MathTransform r = MathTransforms.compound(t1, t2, t3);
    assertMatrixEquals("compound", Matrices.create(7, 7, new double[] { 3, 0, 0, 0, 0, 0, -1, 0, 0, 8, 0, 0, 0, 9, 0, 5, 0, 0, 0, 0, -7, 0, 0, 0, 2, 0, 0, 0, 0, 0, 0, 0, 0, -5, -3, 0, 0, 0, 0, 7, 0, -9, 0, 0, 0, 0, 0, 0, 1 }), MathTransforms.getMatrix(r), STRICT);
}
Also used : MathTransform(org.opengis.referencing.operation.MathTransform) Matrix2(org.apache.sis.referencing.operation.matrix.Matrix2) Matrix4(org.apache.sis.referencing.operation.matrix.Matrix4) Matrix3(org.apache.sis.referencing.operation.matrix.Matrix3) Test(org.junit.Test)

Example 8 with Matrix3

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

the class PassThroughTransformTest method testLinear.

/**
 * Tests the pass-through transform using an affine transform.
 * The "pass-through" of such transforms are optimized using matrix arithmetic.
 *
 * @throws TransformException should never happen.
 */
@Test
public void testLinear() throws TransformException {
    final Matrix matrix = new Matrix3(4, 0, 0, 0, 3, 0, 0, 0, 1);
    runTest(MathTransforms.linear(matrix), LinearTransform.class);
}
Also used : Matrix(org.opengis.referencing.operation.Matrix) Matrix3(org.apache.sis.referencing.operation.matrix.Matrix3) Test(org.junit.Test)

Example 9 with Matrix3

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

the class MathTransformParserTest method testConcatMT.

/**
 * Tests parsing of a {@code CONCAT_MT[…]} element.
 * This test uses affine transforms for the inner {@code PARAM_MT[…]} elements,
 * which is useless since we could as well concatenate the matrices in-place.
 * But this approach is easier to test.
 *
 * @throws ParseException if an error occurred during the parsing.
 */
@Test
@DependsOnMethod("testInverseMT")
public void testConcatMT() throws ParseException {
    final MathTransform tr = parse("CONCAT_MT[" + "PARAM_MT[\"Affine\"," + "PARAMETER[\"num_row\",3]," + "PARAMETER[\"num_col\",3]," + "PARAMETER[\"elt_0_0\",2]," + "PARAMETER[\"elt_1_1\",4]]," + "INVERSE_MT[" + "PARAM_MT[\"Affine\"," + "PARAMETER[\"num_row\",3]," + "PARAMETER[\"num_col\",3]," + "PARAMETER[\"elt_0_2\",5]," + "PARAMETER[\"elt_1_2\",3]]]]");
    assertMatrixEquals("Affine", new Matrix3(2, 0, -5, 0, 4, -3, 0, 0, 1), MathTransforms.getMatrix(tr), STRICT);
}
Also used : MathTransform(org.opengis.referencing.operation.MathTransform) Matrix3(org.apache.sis.referencing.operation.matrix.Matrix3) Test(org.junit.Test) DependsOnMethod(org.apache.sis.test.DependsOnMethod)

Example 10 with Matrix3

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

the class MathTransformParserTest method testInverseMT.

/**
 * Tests parsing of a {@code INVERSE_MT[…]} element.
 * This test uses an affine transform for the inner {@code PARAM_MT[…]} element,
 * which is useless since we could as well inverse the matrix in-place. But this
 * approach is easier to test.
 *
 * @throws ParseException if an error occurred during the parsing.
 */
@Test
@DependsOnMethod("testParamMT")
public void testInverseMT() throws ParseException {
    final MathTransform tr = parse("INVERSE_MT[" + "PARAM_MT[\"Affine\"," + "PARAMETER[\"num_row\",3]," + "PARAMETER[\"num_col\",3]," + "PARAMETER[\"elt_0_0\",2]," + "PARAMETER[\"elt_1_1\",4]," + "PARAMETER[\"elt_0_2\",5]," + "PARAMETER[\"elt_1_2\",3]]]");
    assertMatrixEquals("Affine", new Matrix3(0.5, 0, -2.50, 0, 0.25, -0.75, 0, 0, 1), MathTransforms.getMatrix(tr), STRICT);
}
Also used : MathTransform(org.opengis.referencing.operation.MathTransform) Matrix3(org.apache.sis.referencing.operation.matrix.Matrix3) Test(org.junit.Test) DependsOnMethod(org.apache.sis.test.DependsOnMethod)

Aggregations

Matrix3 (org.apache.sis.referencing.operation.matrix.Matrix3)13 Test (org.junit.Test)10 MathTransform (org.opengis.referencing.operation.MathTransform)6 DependsOnMethod (org.apache.sis.test.DependsOnMethod)4 ParameterValueGroup (org.opengis.parameter.ParameterValueGroup)3 Matrix (org.opengis.referencing.operation.Matrix)3 Angle (javax.measure.quantity.Angle)2 Matrix2 (org.apache.sis.referencing.operation.matrix.Matrix2)2 Envelope (org.opengis.geometry.Envelope)2 ParameterValue (org.opengis.parameter.ParameterValue)2 CC_OperationParameterGroupTest (org.apache.sis.internal.jaxb.referencing.CC_OperationParameterGroupTest)1 DefaultParameterDescriptorGroupTest (org.apache.sis.parameter.DefaultParameterDescriptorGroupTest)1 DefaultConversion (org.apache.sis.referencing.operation.DefaultConversion)1 DefaultConversionTest (org.apache.sis.referencing.operation.DefaultConversionTest)1 Matrix4 (org.apache.sis.referencing.operation.matrix.Matrix4)1 GeneralParameterDescriptor (org.opengis.parameter.GeneralParameterDescriptor)1 GeneralParameterValue (org.opengis.parameter.GeneralParameterValue)1 ParameterDescriptor (org.opengis.parameter.ParameterDescriptor)1 CoordinateReferenceSystem (org.opengis.referencing.crs.CoordinateReferenceSystem)1 Conversion (org.opengis.referencing.operation.Conversion)1