Search in sources :

Example 11 with Matrix3

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

the class LongitudeRotationTest method testCreateMathTransform.

/**
 * Tests {@code LongitudeRotation.createMathTransform(…)}.
 */
@Test
public void testCreateMathTransform() {
    final LongitudeRotation provider = new LongitudeRotation();
    ParameterValueGroup p = provider.getParameters().createValue();
    // Paris meridian
    p.parameter("Longitude offset").setValue(2.5969213, Units.GRAD);
    final MathTransform mt = provider.createMathTransform(null, p);
    /*
         * Verify the full matrix. Note that the longitude offset is expected to be in degrees.
         * This conversion from grad to degrees is specific to Apache SIS and may be revised in
         * future version. See org.apache.sis.referencing.operation package javadoc.
         */
    assertInstanceOf("Shall be an affine transform.", LinearTransform.class, mt);
    assertMatrixEquals("Expected a longitude rotation", new Matrix3(1, 0, 2.33722917, 0, 1, 0, 0, 0, 1), ((LinearTransform) mt).getMatrix(), 1E-16);
}
Also used : MathTransform(org.opengis.referencing.operation.MathTransform) ParameterValueGroup(org.opengis.parameter.ParameterValueGroup) Matrix3(org.apache.sis.referencing.operation.matrix.Matrix3) Test(org.junit.Test)

Example 12 with Matrix3

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

the class NTv2Test method testRGF93.

/**
 * Implementation of {@link #testLoader()} and {@link #testRGF93(Path)}.
 *
 * @param  xmin  negative of value of {@code "W_LONG"} record.
 * @param  xmax  negative of value of {@code "E_LONG"} record.
 * @param  ymin  value of the {@code "S_LAT"} record.
 * @param  ymax  value of the {@code "N_LAT"} record.
 */
private static void testRGF93(final Path file, final double xmin, final double xmax, final double ymin, final double ymax) throws IOException, FactoryException, TransformException {
    final double cellSize = 360;
    final DatumShiftGridFile<Angle, Angle> grid = NTv2.getOrLoad(file);
    assertInstanceOf("Should not be compressed.", DatumShiftGridFile.Float.class, grid);
    assertEquals("coordinateUnit", Units.ARC_SECOND, grid.getCoordinateUnit());
    assertEquals("translationUnit", Units.ARC_SECOND, grid.getTranslationUnit());
    assertEquals("translationDimensions", 2, grid.getTranslationDimensions());
    assertTrue("isCellValueRatio", grid.isCellValueRatio());
    assertEquals("cellPrecision", (ACCURACY / 10) / cellSize, grid.getCellPrecision(), 0.5E-6 / cellSize);
    /*
         * Verify the envelope and the conversion between geographic coordinates and grid indices.
         * The cells are expected to have the same size (360″ or 0.1°) in longitudes and latitudes.
         */
    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, xmax, 0, +cellSize, ymin, 0, 0, 1), grid.getCoordinateToGrid().inverse().getMatrix(), STRICT);
    /*
         * Test the same point than FranceGeocentricInterpolationTest, which is itself derived from the
         * NTG_88 guidance note.  If we were using the official NTF_R93.gsb file, 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 ≈ 75.7432814 in official file,   ≈ 3.7432814 in the test file.
         *   gridY ≈ 78.4451225 in official file,   ≈ 4.4451225 in the test file.
         */
    final double[] position = FranceGeocentricInterpolationTest.samplePoint(1);
    final double[] expected = FranceGeocentricInterpolationTest.samplePoint(3);
    final double[] indices = new double[position.length];
    final double[] vector = new double[2];
    for (int i = 0; i < expected.length; i++) {
        position[i] *= DatumShiftGridLoader.DEGREES_TO_SECONDS;
        expected[i] *= DatumShiftGridLoader.DEGREES_TO_SECONDS;
        // We will test the interpolated shifts rather than final coordinates.
        expected[i] -= position[i];
    }
    grid.getCoordinateToGrid().transform(position, 0, indices, 0, 1);
    grid.interpolateInCell(indices[0], indices[1], vector);
    // Was positive toward west.
    vector[0] *= -cellSize;
    vector[1] *= +cellSize;
    assertArrayEquals("interpolateInCell", expected, vector, FranceGeocentricInterpolationTest.ANGULAR_TOLERANCE * DatumShiftGridLoader.DEGREES_TO_SECONDS);
    // Same test than above, but let DatumShiftGrid do the conversions for us.
    assertArrayEquals("interpolateAt", expected, grid.interpolateAt(position), FranceGeocentricInterpolationTest.ANGULAR_TOLERANCE * DatumShiftGridLoader.DEGREES_TO_SECONDS);
    assertSame("Grid should be cached.", grid, NTv2.getOrLoad(file));
}
Also used : Angle(javax.measure.quantity.Angle) Envelope(org.opengis.geometry.Envelope) Matrix3(org.apache.sis.referencing.operation.matrix.Matrix3)

Example 13 with Matrix3

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

the class DefaultConversionTest method verifyProperties.

/**
 * Asserts that at least some of the properties of the given {@code op} instance have the expected values
 * for an instance created by {@link #createLongitudeRotation(GeographicCRS, GeographicCRS, TemporalCRS)}.
 */
@SuppressWarnings("SuspiciousToArrayCall")
private static void verifyProperties(final DefaultConversion op, final boolean swapSourceAxes) {
    assertEquals("name", "Paris to Greenwich", op.getName().getCode());
    assertEquals("sourceCRS", "NTF (Paris)", op.getSourceCRS().getName().getCode());
    assertEquals("targetCRS", "Back to Greenwich", op.getTargetCRS().getName().getCode());
    assertEquals("method", "Longitude rotation", op.getMethod().getName().getCode());
    assertEquals("parameters", "Longitude rotation", op.getParameterDescriptors().getName().getCode());
    final ParameterValueGroup parameters = op.getParameterValues();
    final ParameterValue<?>[] values = parameters.values().toArray(new ParameterValue<?>[1]);
    assertEquals("parameters", "Longitude rotation", parameters.getDescriptor().getName().getCode());
    assertEquals("parameters[0]", "Longitude offset", values[0].getDescriptor().getName().getCode());
    assertEquals("parameters[0]", OFFSET, values[0].doubleValue(), STRICT);
    assertEquals(1, values.length);
    final Matrix3 expected = new Matrix3();
    expected.m02 = OFFSET;
    if (swapSourceAxes) {
        expected.m00 = expected.m11 = 0;
        expected.m01 = expected.m10 = 1;
    }
    assertMatrixEquals("Longitude rotation of a two-dimensional CRS", expected, MathTransforms.getMatrix(op.getMathTransform()), STRICT);
}
Also used : ParameterValue(org.opengis.parameter.ParameterValue) ParameterValueGroup(org.opengis.parameter.ParameterValueGroup) Matrix3(org.apache.sis.referencing.operation.matrix.Matrix3)

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