Java Code Examples for org.opengis.referencing.operation.MathTransform#inverse()

The following examples show how to use org.opengis.referencing.operation.MathTransform#inverse() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: AbstractMathTransform.java    From sis with Apache License 2.0 6 votes vote down vote up
/**
 * Returns {@code true} if {@code tr1} is the inverse of {@code tr2}.
 * If this method is unsure, it conservatively returns {@code false}.
 * The transform that may be inverted is {@code tr1}.
 *
 * @param  tr1  the transform to inverse.
 * @param  tr2  the transform that may be the inverse of {@code tr1}.
 * @return whether this transform is the inverse of the given transform. If unsure, {@code false}.
 */
static boolean isInverseEquals(MathTransform tr1, final MathTransform tr2) {
    if (tr1.getSourceDimensions() != tr2.getTargetDimensions() ||
        tr1.getTargetDimensions() != tr2.getSourceDimensions())
    {
        return false;
    }
    try {
        tr1 = tr1.inverse();
    } catch (NoninvertibleTransformException e) {
        return false;
    }
    if (tr1 instanceof LenientComparable) {
        return ((LenientComparable) tr1).equals(tr2, ComparisonMode.APPROXIMATE);
    }
    if (tr2 instanceof LenientComparable) {
        return ((LenientComparable) tr2).equals(tr1, ComparisonMode.APPROXIMATE);
    }
    return tr1.equals(tr2);
}
 
Example 2
Source File: GeocentricToGeographic.java    From sis with Apache License 2.0 5 votes vote down vote up
/**
 * Creates a transform from the specified group of parameter values.
 *
 * @param  factory  the factory to use for creating the transform.
 * @param  values   the parameter values that define the transform to create.
 * @return the conversion from geocentric to geographic coordinates.
 * @throws FactoryException if an error occurred while creating a transform.
 */
@Override
public MathTransform createMathTransform(final MathTransformFactory factory, final ParameterValueGroup values)
        throws FactoryException
{
    MathTransform tr = GeographicToGeocentric.create(factory, Parameters.castOrWrap(values));
    try {
        tr = tr.inverse();
    } catch (NoninvertibleTransformException e) {
        throw new FactoryException(e);                  // Should never happen with SIS implementation.
    }
    return tr;
}
 
Example 3
Source File: FranceGeocentricInterpolation.java    From sis with Apache License 2.0 5 votes vote down vote up
/**
 * Creates a transform from the specified group of parameter values.
 * This method creates the transform from <em>target</em> to <em>source</em>
 * (which is the direction that use the interpolation grid directly without iteration),
 * then inverts the transform.
 *
 * @param  factory  the factory to use if this constructor needs to create other math transforms.
 * @param  values   the group of parameter values.
 * @return the created math transform.
 * @throws ParameterNotFoundException if a required parameter was not found.
 * @throws FactoryException if an error occurred while loading the grid.
 */
@Override
public MathTransform createMathTransform(final MathTransformFactory factory, final ParameterValueGroup values)
        throws ParameterNotFoundException, FactoryException
{
    boolean withHeights = false;
    final Parameters pg = Parameters.castOrWrap(values);
    final Integer dim = pg.getValue(Molodensky.DIMENSION);
    if (dim != null) switch (dim) {
        case 2:  break;
        case 3:  withHeights = true; break;
        default: throw new InvalidParameterValueException(Errors.format(
                        Errors.Keys.IllegalArgumentValue_2, "dim", dim), "dim", dim);
    }
    final Path file = pg.getMandatoryValue(FILE);
    final DatumShiftGridFile<Angle,Length> grid = getOrLoad(file,
            isRecognized(file) ? new double[] {TX, TY, TZ} : null, PRECISION);
    MathTransform tr = createGeodeticTransformation(factory,
            createEllipsoid(pg, Molodensky.TGT_SEMI_MAJOR,
                                Molodensky.TGT_SEMI_MINOR, CommonCRS.ETRS89.ellipsoid()),   // GRS 1980 ellipsoid
            createEllipsoid(pg, Molodensky.SRC_SEMI_MAJOR,
                                Molodensky.SRC_SEMI_MINOR, null),                           // Clarke 1880 (IGN) ellipsoid
            withHeights, grid);
    try {
        tr = tr.inverse();
    } catch (NoninvertibleTransformException e) {
        throw new FactoryException(e);                  // Should never happen.
    }
    return tr;
}
 
Example 4
Source File: GeocentricAffineBetweenGeographic.java    From sis with Apache License 2.0 5 votes vote down vote up
/**
 * Creates a math transform from the specified group of parameter values.
 * This method wraps the affine operation into Geographic/Geocentric conversions.
 *
 * @param  factory  the factory to use for creating concatenated transforms.
 * @param  values   the group of parameter values.
 * @return the created math transform.
 * @throws FactoryException if a transform can not be created.
 */
@Override
public MathTransform createMathTransform(final MathTransformFactory factory, final ParameterValueGroup values)
        throws FactoryException
{
    final Parameters pv = Parameters.castOrWrap(values);
    final MathTransform affine = super.createMathTransform(factory, pv);
    /*
     * Create a "Geographic to Geocentric" conversion with ellipsoid axis length units converted to metres
     * (the unit implied by SRC_SEMI_MAJOR) because it is the unit of Bursa-Wolf parameters that we created above.
     */
    MathTransform toGeocentric = EllipsoidToCentricTransform.createGeodeticConversion(factory,
            pv.doubleValue(SRC_SEMI_MAJOR),
            pv.doubleValue(SRC_SEMI_MINOR),
            Units.METRE, getSourceDimensions() >= 3,
            EllipsoidToCentricTransform.TargetType.CARTESIAN);
    /*
     * Create a "Geocentric to Geographic" conversion with ellipsoid axis length units converted to metres
     * because this is the unit of the Geocentric CRS used above.
     */
    MathTransform toGeographic = EllipsoidToCentricTransform.createGeodeticConversion(factory,
            pv.doubleValue(TGT_SEMI_MAJOR),
            pv.doubleValue(TGT_SEMI_MINOR),
            Units.METRE, getTargetDimensions() >= 3,
            EllipsoidToCentricTransform.TargetType.CARTESIAN);
    try {
        toGeographic = toGeographic.inverse();
    } catch (NoninvertibleTransformException e) {
        throw new FactoryException(e);                  // Should never happen with SIS implementation.
    }
    /*
     * The  Geocentric → Affine → Geographic  chain.
     */
    return factory.createConcatenatedTransform(toGeocentric,
           factory.createConcatenatedTransform(affine, toGeographic));
}
 
Example 5
Source File: MathTransformParser.java    From sis with Apache License 2.0 5 votes vote down vote up
/**
 * Parses an {@code "INVERSE_MT"} element. This element has the following pattern:
 *
 * {@preformat text
 *     INVERSE_MT[<math transform>]
 * }
 *
 * @param  parent  the parent element.
 * @return the {@code "INVERSE_MT"} element as an {@link MathTransform} object.
 * @throws ParseException if the {@code "INVERSE_MT"} element can not be parsed.
 */
private MathTransform parseInverseMT(final Element parent) throws ParseException {
    final Element element = parent.pullElement(FIRST, WKTKeywords.Inverse_MT);
    if (element == null) {
        return null;
    }
    MathTransform transform = parseMathTransform(element, true);
    try {
        transform = transform.inverse();
    } catch (NoninvertibleTransformException exception) {
        throw element.parseFailed(exception);
    }
    element.close(ignoredElements);
    return transform;
}
 
Example 6
Source File: VerticalOffset.java    From sis with Apache License 2.0 3 votes vote down vote up
/**
 * Invoked by {@link org.apache.sis.referencing.operation.transform.DefaultMathTransformFactory} after
 * the transform has been created but before it is concatenated with operations performing axis changes.
 * This method performs the parameter sign adjustment as documented in the class javadoc if and only if
 * this method detects that the target axis is oriented toward down. This orientation is detected by a
 * negative sign for the <var>m₀₀</var> coefficient in the given 2×2 affine transform matrix.
 *
 * <div class="note"><b>Implementation note:</b>
 * for now we define this method as a static one because it is the only special case handled by
 * {@code DefaultMathTransformFactory}. But if there is more special cases in a future SIS version,
 * then we should make this method non-static and declare an overrideable {@code postCreate} method
 * in {@link AbstractProvider} instead.</div>
 *
 * @param  parameterized  the transform created by {@code createMathTransform(…)}.
 * @param  after  the matrix for the operation to be concatenated after {@code parameterized}.
 * @return the transform to use instead of {@code parameterized}.
 * @throws FactoryException if an error occurred while creating the new transform.
 */
public static MathTransform postCreate(MathTransform parameterized, final Matrix after) throws FactoryException {
    if (after.getElement(0,0) < 0) try {
        parameterized = parameterized.inverse();
    } catch (NoninvertibleTransformException e) {
        throw new FactoryException(e);                  // Should never happe since matrix element is not zero.
    }
    return parameterized;
}