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));
}
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);
}
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);
}
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);
}
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);
}
Aggregations