Search in sources :

Example 1 with MatrixSIS

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

the class ScaleTransformTest method testExtendedPrecision.

/**
 * Verifies that {@link ScaleTransform} stores the error terms when they exist.
 */
@Test
@DependsOnMethod("testConstantDimension")
public void testExtendedPrecision() {
    final Number O = 0;
    final Number l = 1;
    final DoubleDouble r = DoubleDouble.createDegreesToRadians();
    final MatrixSIS matrix = Matrices.create(4, 4, new Number[] { r, O, O, O, O, r, O, O, O, O, l, O, O, O, O, l });
    final double[] elements = ((ExtendedPrecisionMatrix) matrix).getExtendedElements();
    assertTrue(r.value > r.error);
    // Paranoiac checks for making sure that next assertion will test something.
    assertFalse(r.error == 0);
    assertArrayEquals(new double[] { // Paranoiac check for making sure that getExtendedElements() is not broken.
    r.value, 0, 0, 0, 0, r.value, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, r.error, 0, 0, 0, 0, r.error, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, elements, 0);
    final ScaleTransform tr = new ScaleTransform(4, 4, elements);
    assertEquals("sourceDimensions", 3, tr.getSourceDimensions());
    assertEquals("targetDimensions", 3, tr.getTargetDimensions());
    Assert.assertMatrixEquals("matrix", matrix, tr.getMatrix(), 0.0);
    assertArrayEquals("elements", elements, tr.getExtendedElements(), 0.0);
    transform = tr;
    validate();
}
Also used : ExtendedPrecisionMatrix(org.apache.sis.internal.referencing.ExtendedPrecisionMatrix) MatrixSIS(org.apache.sis.referencing.operation.matrix.MatrixSIS) DoubleDouble(org.apache.sis.internal.util.DoubleDouble) Test(org.junit.Test) DependsOnMethod(org.apache.sis.test.DependsOnMethod)

Example 2 with MatrixSIS

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

the class Equirectangular method createMathTransform.

/**
 * Creates an Equirectangular projection from the specified group of parameter values. This method is an
 * adaptation of {@link org.apache.sis.referencing.operation.projection.NormalizedProjection} constructor,
 * reproduced in this method because we will create an affine transform instead than the usual projection
 * classes.
 *
 * @param  factory     the factory to use if this constructor needs to create other math transforms.
 * @param  parameters  the parameter values that define the transform to create.
 * @return the map projection created from the given parameter values.
 * @throws FactoryException if an error occurred while creating the math transform.
 */
@Override
public MathTransform createMathTransform(final MathTransformFactory factory, final ParameterValueGroup parameters) throws FactoryException {
    final Parameters p = Parameters.castOrWrap(parameters);
    final ContextualParameters context = new ContextualParameters(this);
    double a = getAndStore(p, context, MapProjection.SEMI_MAJOR);
    double b = getAndStore(p, context, MapProjection.SEMI_MINOR);
    double λ0 = getAndStore(p, context, LONGITUDE_OF_ORIGIN);
    double φ0 = getAndStore(p, context, LATITUDE_OF_ORIGIN);
    double φ1 = getAndStore(p, context, STANDARD_PARALLEL);
    double fe = getAndStore(p, context, FALSE_EASTING);
    double fn = getAndStore(p, context, FALSE_NORTHING);
    /*
         * Perform following transformation, in that order. Note that following
         * AffineTransform convention, the Java code appears in reverse order:
         *
         *   1) Subtract φ0 to the latitude.
         *   2) Subtract λ0 to the longitude.
         *   3) Convert degrees to radians.
         *   4) Scale longitude by cos(φ1).
         */
    φ1 = toRadians(φ1);
    final MatrixSIS normalize = context.getMatrix(ContextualParameters.MatrixRole.NORMALIZATION);
    normalize.convertBefore(0, cos(φ1), null);
    context.normalizeGeographicInputs(λ0).convertBefore(1, null, -φ0);
    /*
         * At this point, we usually invoke 'denormalize.convertAfter(…, a, …)' where 'a' (the semi-major axis length)
         * is taken as the Earth radius (R). However quoting EPSG: "If the figure of the earth used is an ellipsoid
         * rather than a sphere then R should be calculated as the radius of the conformal sphere at the projection
         * origin at latitude φ1 using the formula for RC given in section 1.2, table 3".
         */
    if (a != b) {
        final double rs = b / a;
        final double sinφ1 = sin(φ1);
        a = b / (1 - (1 - rs * rs) * (sinφ1 * sinφ1));
    }
    final DoubleDouble k = new DoubleDouble(a);
    final MatrixSIS denormalize = context.getMatrix(ContextualParameters.MatrixRole.DENORMALIZATION);
    denormalize.convertAfter(0, k, new DoubleDouble(fe));
    denormalize.convertAfter(1, k, new DoubleDouble(fn));
    /*
         * Creates the ConcatenatedTransform, letting the factory returns the cached instance
         * if the caller already invoked this method previously (which usually do not happen).
         */
    MathTransform mt = context.completeTransform(factory, MathTransforms.identity(2));
    if (mt instanceof AffineTransform) {
        // Always true in Apache SIS implementation.
        mt = new ParameterizedAffine((AffineTransform) mt, context, true);
    }
    return mt;
}
Also used : Parameters(org.apache.sis.parameter.Parameters) ContextualParameters(org.apache.sis.referencing.operation.transform.ContextualParameters) ContextualParameters(org.apache.sis.referencing.operation.transform.ContextualParameters) MathTransform(org.opengis.referencing.operation.MathTransform) AffineTransform(java.awt.geom.AffineTransform) ParameterizedAffine(org.apache.sis.internal.referencing.j2d.ParameterizedAffine) MatrixSIS(org.apache.sis.referencing.operation.matrix.MatrixSIS) DoubleDouble(org.apache.sis.internal.util.DoubleDouble)

Example 3 with MatrixSIS

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

the class Geographic2Dto3D method createMathTransform.

/**
 * Returns the transform.
 *
 * @param  factory  the factory for creating affine transforms.
 * @param  values   the parameter values.
 * @return the math transform for the given parameter values.
 * @throws FactoryException if an error occurred while creating the transform.
 */
@Override
public MathTransform createMathTransform(MathTransformFactory factory, ParameterValueGroup values) throws FactoryException {
    final Parameters pv = Parameters.castOrWrap(values);
    final MatrixSIS m = Matrices.createDiagonal(4, 3);
    m.setElement(2, 2, pv.doubleValue(HEIGHT));
    m.setElement(3, 2, 1);
    return factory.createAffineTransform(m);
}
Also used : Parameters(org.apache.sis.parameter.Parameters) MatrixSIS(org.apache.sis.referencing.operation.matrix.MatrixSIS)

Example 4 with MatrixSIS

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

the class AxisOrderReversal method createMathTransform.

/**
 * Returns the transform.
 *
 * @param  factory  ignored (can be null).
 * @param  values   ignored.
 * @return the math transform.
 */
@Override
public synchronized MathTransform createMathTransform(MathTransformFactory factory, ParameterValueGroup values) {
    if (transform == null) {
        final MatrixSIS m = Matrices.createZero(getTargetDimensions() + 1, getSourceDimensions() + 1);
        m.setElement(0, 1, 1);
        m.setElement(1, 0, 1);
        transform = MathTransforms.linear(m);
    }
    return transform;
}
Also used : MatrixSIS(org.apache.sis.referencing.operation.matrix.MatrixSIS)

Example 5 with MatrixSIS

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

the class ContextualParameters method normalizeGeographicInputs.

/**
 * Prepends a normalization step converting input ordinates in the two first dimensions from degrees to radians.
 * The normalization can optionally subtract the given λ₀ value (in degrees) from the longitude.
 *
 * <p>Invoking this method is equivalent to {@linkplain java.awt.geom.AffineTransform#concatenate concatenating}
 * the normalization matrix with the following matrix. This will have the effect of applying the conversion
 * described above before any other operation:</p>
 *
 * <center>{@include formulas.html#NormalizeGeographic}</center>
 *
 * @param  λ0  longitude of the central meridian, in degrees.
 * @return the normalization affine transform as a matrix.
 *         Callers can change that matrix directly if they want to apply additional normalization operations.
 * @throws IllegalStateException if this {@code ContextualParameter} has been made unmodifiable.
 */
public synchronized MatrixSIS normalizeGeographicInputs(final double λ0) {
    ensureModifiable();
    /*
         * In theory the check for (λ0 != 0) is useless. However Java has a notion of negative zero, and we want
         * to avoid negative zeros because we do not want them to appear in WKT formatting of matrix elements.
         */
    final DoubleDouble toRadians = DoubleDouble.createDegreesToRadians();
    DoubleDouble offset = null;
    if (λ0 != 0) {
        offset = new DoubleDouble(-λ0);
        offset.multiply(toRadians);
    }
    // Must be the same instance, not a copy.
    final MatrixSIS normalize = (MatrixSIS) this.normalize;
    normalize.convertBefore(0, toRadians, offset);
    normalize.convertBefore(1, toRadians, null);
    return normalize;
}
Also used : MatrixSIS(org.apache.sis.referencing.operation.matrix.MatrixSIS) DoubleDouble(org.apache.sis.internal.util.DoubleDouble)

Aggregations

MatrixSIS (org.apache.sis.referencing.operation.matrix.MatrixSIS)20 DoubleDouble (org.apache.sis.internal.util.DoubleDouble)5 Test (org.junit.Test)4 Matrix4 (org.apache.sis.referencing.operation.matrix.Matrix4)3 DependsOnMethod (org.apache.sis.test.DependsOnMethod)3 MathTransform (org.opengis.referencing.operation.MathTransform)3 FactoryException (org.opengis.util.FactoryException)3 ExtendedPrecisionMatrix (org.apache.sis.internal.referencing.ExtendedPrecisionMatrix)2 Parameters (org.apache.sis.parameter.Parameters)2 CoordinateSystem (org.opengis.referencing.cs.CoordinateSystem)2 Matrix (org.opengis.referencing.operation.Matrix)2 AffineTransform (java.awt.geom.AffineTransform)1 Date (java.util.Date)1 IncommensurableException (javax.measure.IncommensurableException)1 DirectPosition2D (org.apache.sis.geometry.DirectPosition2D)1 ParameterizedAffine (org.apache.sis.internal.referencing.j2d.ParameterizedAffine)1 FormattableObject (org.apache.sis.io.wkt.FormattableObject)1 Line (org.apache.sis.math.Line)1 Plane (org.apache.sis.math.Plane)1 InvalidGeodeticParameterException (org.apache.sis.referencing.factory.InvalidGeodeticParameterException)1