Search in sources :

Example 11 with Parameters

use of org.apache.sis.parameter.Parameters in project sis by apache.

the class GeocentricAffine method asDatumShift.

/**
 * Given a transformation chain, conditionally replaces the affine transform elements by an alternative object
 * showing the Bursa-Wolf parameters. The replacement is applied if and only if the affine transform is a scale,
 * translation or rotation in the geocentric domain.
 *
 * <p>This method is invoked only by {@code ConcatenatedTransform.getPseudoSteps()} for the need of WKT formatting.
 * The purpose of this method is very similar to the purpose of {@code AbstractMathTransform.beforeFormat(List, int,
 * boolean)} except that we need to perform the {@code forDatumShift(…)} work only after {@code beforeFormat(…)}
 * finished its work for all {@code ContextualParameters}, including the {@code EllipsoidToCentricTransform}'s one.</p>
 *
 * @param  transforms  the full chain of concatenated transforms.
 */
public static void asDatumShift(final List<Object> transforms) {
    for (int i = transforms.size() - 2; --i >= 0; ) {
        if (isOperation(GeographicToGeocentric.NAME, transforms.get(i)) && isOperation(GeocentricToGeographic.NAME, transforms.get(i + 2))) {
            final Object step = transforms.get(i + 1);
            if (step instanceof LinearTransform) {
                final BursaWolfParameters parameters = new BursaWolfParameters(null, null);
                try {
                    parameters.setPositionVectorTransformation(((LinearTransform) step).getMatrix(), BURSAWOLF_TOLERANCE);
                } catch (IllegalArgumentException e) {
                    /*
                         * Should not occur, except sometime on inverse transform of relatively complex datum shifts
                         * (more than just translation terms). We can fallback on formatting the full matrix.
                         */
                    log(Loggers.WKT, "asDatumShift", e);
                    continue;
                }
                final boolean isTranslation = parameters.isTranslation();
                final Parameters values = createParameters(isTranslation ? GeocentricTranslation.PARAMETERS : PositionVector7Param.PARAMETERS, parameters, isTranslation);
                transforms.set(i + 1, new FormattableObject() {

                    @Override
                    protected String formatTo(final Formatter formatter) {
                        WKTUtilities.appendParamMT(values, formatter);
                        return WKTKeywords.Param_MT;
                    }
                });
            }
        }
    }
}
Also used : Parameters(org.apache.sis.parameter.Parameters) BursaWolfParameters(org.apache.sis.referencing.datum.BursaWolfParameters) Formatter(org.apache.sis.io.wkt.Formatter) FormattableObject(org.apache.sis.io.wkt.FormattableObject) BursaWolfParameters(org.apache.sis.referencing.datum.BursaWolfParameters) LinearTransform(org.apache.sis.referencing.operation.transform.LinearTransform) FormattableObject(org.apache.sis.io.wkt.FormattableObject)

Example 12 with Parameters

use of org.apache.sis.parameter.Parameters in project sis by apache.

the class GeocentricAffine method createMathTransform.

/**
 * Creates a math transform from the specified group of parameter values.
 * The default implementation creates an affine transform, but some subclasses
 * will wrap that 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
@SuppressWarnings("fallthrough")
public MathTransform createMathTransform(final MathTransformFactory factory, final ParameterValueGroup values) throws FactoryException {
    final BursaWolfParameters parameters = new BursaWolfParameters(null, null);
    final Parameters pv = Parameters.castOrWrap(values);
    boolean reverseRotation = false;
    switch(getType()) {
        default:
            throw new AssertionError();
        // Fall through
        case FRAME_ROTATION:
            reverseRotation = true;
        case SEVEN_PARAM:
            parameters.rX = pv.doubleValue(RX);
            parameters.rY = pv.doubleValue(RY);
            parameters.rZ = pv.doubleValue(RZ);
            parameters.dS = pv.doubleValue(DS);
        case // Fall through
        TRANSLATION:
            // Fall through
            parameters.tX = pv.doubleValue(TX);
            parameters.tY = pv.doubleValue(TY);
            parameters.tZ = pv.doubleValue(TZ);
    }
    if (reverseRotation) {
        parameters.reverseRotation();
    }
    return MathTransforms.linear(parameters.getPositionVectorTransformation(null));
}
Also used : Parameters(org.apache.sis.parameter.Parameters) BursaWolfParameters(org.apache.sis.referencing.datum.BursaWolfParameters) BursaWolfParameters(org.apache.sis.referencing.datum.BursaWolfParameters)

Example 13 with Parameters

use of org.apache.sis.parameter.Parameters in project sis by apache.

the class GeocentricAffineBetweenGeographic method createMathTransform.

/**
 * 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) {
        // Should never happen with SIS implementation.
        throw new FactoryException(e);
    }
    /*
         * The  Geocentric → Affine → Geographic  chain.
         */
    return factory.createConcatenatedTransform(toGeocentric, factory.createConcatenatedTransform(affine, toGeographic));
}
Also used : NoninvertibleTransformException(org.opengis.referencing.operation.NoninvertibleTransformException) Parameters(org.apache.sis.parameter.Parameters) MathTransform(org.opengis.referencing.operation.MathTransform) FactoryException(org.opengis.util.FactoryException)

Example 14 with Parameters

use of org.apache.sis.parameter.Parameters 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 15 with Parameters

use of org.apache.sis.parameter.Parameters in project sis by apache.

the class MolodenskyFormula method getParameterValues.

/**
 * Returns a copy of internal parameter values of this transform.
 * The returned group contains parameters for the source ellipsoid semi-axis lengths
 * and the differences between source and target ellipsoid parameters.
 *
 * <div class="note"><b>Note:</b>
 * this method is mostly for {@linkplain org.apache.sis.io.wkt.Convention#INTERNAL debugging purposes}
 * since the isolation of non-linear parameters in this class is highly implementation dependent.
 * Most GIS applications will instead be interested in the {@linkplain #getContextualParameters()
 * contextual parameters}.</div>
 *
 * @return a copy of the internal parameter values for this transform.
 */
@Debug
@Override
public ParameterValueGroup getParameterValues() {
    final Unit<?> unit = context.getOrCreate(Molodensky.SRC_SEMI_MAJOR).getUnit();
    final double semiMinor = context.getOrCreate(Molodensky.SRC_SEMI_MINOR).doubleValue(unit);
    final Parameters pg = Parameters.castOrWrap(getParameterDescriptors().createValue());
    pg.getOrCreate(Molodensky.SRC_SEMI_MAJOR).setValue(semiMajor, unit);
    pg.getOrCreate(Molodensky.SRC_SEMI_MINOR).setValue(semiMinor, unit);
    completeParameters(pg, semiMinor, unit, Double.NaN);
    return pg;
}
Also used : Parameters(org.apache.sis.parameter.Parameters) Debug(org.apache.sis.util.Debug)

Aggregations

Parameters (org.apache.sis.parameter.Parameters)26 MathTransform (org.opengis.referencing.operation.MathTransform)5 BursaWolfParameters (org.apache.sis.referencing.datum.BursaWolfParameters)4 MathTransformFactoryMock (org.apache.sis.referencing.operation.transform.MathTransformFactoryMock)4 NoninvertibleTransformException (org.opengis.referencing.operation.NoninvertibleTransformException)3 FactoryException (org.opengis.util.FactoryException)3 MatrixSIS (org.apache.sis.referencing.operation.matrix.MatrixSIS)2 ContextualParameters (org.apache.sis.referencing.operation.transform.ContextualParameters)2 StorageConnector (org.apache.sis.storage.StorageConnector)2 Debug (org.apache.sis.util.Debug)2 ParameterValueGroup (org.opengis.parameter.ParameterValueGroup)2 AffineTransform (java.awt.geom.AffineTransform)1 Path (java.nio.file.Path)1 StandardOpenOption (java.nio.file.StandardOpenOption)1 Angle (javax.measure.quantity.Angle)1 Length (javax.measure.quantity.Length)1 ParameterizedAffine (org.apache.sis.internal.referencing.j2d.ParameterizedAffine)1 Equirectangular (org.apache.sis.internal.referencing.provider.Equirectangular)1 LambertConformal1SP (org.apache.sis.internal.referencing.provider.LambertConformal1SP)1 PolarStereographicNorth (org.apache.sis.internal.referencing.provider.PolarStereographicNorth)1