Examples of XMatrix


Examples of org.geotools.referencing.operation.matrix.XMatrix

     * because of a {@link SingularMatrixException}), then the exception is wrapped into a
     * {@link NoninvertibleTransformException}.
     */
    static Matrix invert(final Matrix matrix) throws NoninvertibleTransformException {
        try {
            final XMatrix m = toXMatrix(matrix);
            m.invert();
            return m;
        } catch (SingularMatrixException exception) {
            NoninvertibleTransformException e = new NoninvertibleTransformException(
                        Errors.format(ErrorKeys.NONINVERTIBLE_TRANSFORM));
            e.initCause(exception);
View Full Code Here

Examples of org.geotools.referencing.operation.matrix.XMatrix

         *     standard CRS with source datum  -->
         *     standard CRS with target datum  -->
         *     target CRS
         */
        final CartesianCS STANDARD = DefaultCartesianCS.GEOCENTRIC;
        final XMatrix matrix;
        ReferenceIdentifier identifier = DATUM_SHIFT;
        try {
            Matrix datumShift = DefaultGeodeticDatum.getAffineTransform(
                                    TemporaryDatum.unwrap(sourceDatum),
                                    TemporaryDatum.unwrap(targetDatum));
            if (datumShift == null) {
                if (lenientDatumShift) {
                    datumShift = new Matrix4(); // Identity transform.
                    identifier = ELLIPSOID_SHIFT;
                } else {
                    throw new OperationNotFoundException(Errors.format(
                                ErrorKeys.BURSA_WOLF_PARAMETERS_REQUIRED));
                }
            }
            final Matrix normalizeSource = swapAndScaleAxis(sourceCS, STANDARD);
            final Matrix normalizeTarget = swapAndScaleAxis(STANDARD, targetCS);
            /*
             * Since all steps are matrix, we can multiply them into a single matrix operation.
             * Note: XMatrix.multiply(XMatrix) is equivalents to AffineTransform.concatenate(...):
             *       First transform by the supplied transform and then transform the result
             *       by the original transform.
             *
             * We compute: matrix = normalizeTarget * datumShift * normalizeSource
             */
            matrix = new Matrix4(normalizeTarget);
            matrix.multiply(datumShift);
            matrix.multiply(normalizeSource);
        } catch (SingularMatrixException cause) {
            throw new OperationNotFoundException(getErrorMessage(sourceDatum, targetDatum), cause);
        }
        return createFromAffineTransform(identifier, sourceCRS, targetCRS, matrix);
    }
View Full Code Here

Examples of org.geotools.referencing.operation.matrix.XMatrix

        assert count == targets.size() : count;
        while (count!=0 && steps[--count].getMathTransform().isIdentity());
        final ReferencingFactoryContainer factories = getFactoryContainer();
        CoordinateOperation operation = null;
        CoordinateReferenceSystem sourceStepCRS = sourceCRS;
        final XMatrix select = MatrixFactory.create(dimensions+1, indices.length+1);
        select.setZero();
        select.setElement(dimensions, indices.length, 1);
        for (int j=0; j<dimensions; j++) {
            select.setElement(j, indices[j], 1);
        }
        if (!select.isIdentity()) {
            if (ordered.length == 1) {
                sourceStepCRS = ordered[0];
            } else {
                sourceStepCRS = factories.getCRSFactory().createCompoundCRS(
                                    getTemporaryName(sourceCRS), ordered);
View Full Code Here

Examples of org.geotools.referencing.operation.matrix.XMatrix

     */
    public static Matrix createSelectMatrix(final int sourceDim, final int[] toKeep)
            throws IndexOutOfBoundsException
    {
        final int targetDim = toKeep.length;
        final XMatrix matrix = MatrixFactory.create(targetDim+1, sourceDim+1);
        matrix.setZero();
        for (int j=0; j<targetDim; j++) {
            matrix.setElement(j, toKeep[j], 1);
        }
        matrix.setElement(targetDim, sourceDim, 1);
        return matrix;
    }
View Full Code Here

Examples of org.geotools.referencing.operation.matrix.XMatrix

    public synchronized MathTransform inverse() throws NoninvertibleTransformException {
        if (inverse == null) {
            if (isIdentity()) {
                inverse = this;
            } else {
                final XMatrix matrix = getGeneralMatrix();
                try {
                    matrix.invert();
                } catch (SingularMatrixException exception) {
                    throw new NoninvertibleTransformException(Errors.format(
                              ErrorKeys.NONINVERTIBLE_TRANSFORM), exception);
                } catch (MismatchedSizeException exception) {
                    // This exception is thrown if the matrix is not square.
View Full Code Here

Examples of org.geotools.referencing.operation.matrix.XMatrix

     * @return The derivative at the specified point (never {@code null}).
     * @throws TransformException if the derivative can't be evaluated at the specified point.
     */
    @Override
    public Matrix derivative(final Point2D point) throws TransformException {
        final XMatrix matrix1 = toXMatrix(transform1.derivative(point));
        final XMatrix matrix2 = toXMatrix(transform2.derivative(transform1.transform(point,null)));
        matrix2.multiply(matrix1);
        return matrix2;
    }
View Full Code Here

Examples of org.geotools.referencing.operation.matrix.XMatrix

        if (tr2.isIdentity()) return tr1;
        /*
         * If both transforms use matrix, then we can create
         * a single transform using the concatenated matrix.
         */
        final XMatrix matrix1 = getMatrix(tr1);
        if (matrix1 != null) {
            final XMatrix matrix2 = getMatrix(tr2);
            if (matrix2 != null) {
                // Compute "matrix = matrix2 * matrix1". Reuse an existing matrix object
                // if possible, which is always the case when both matrix are square.
                final int numRow = matrix2.getNumRow();
                final int numCol = matrix1.getNumCol();
                final XMatrix matrix;
                if (numCol == matrix2.getNumCol()) {
                    matrix = matrix2;
                    matrix2.multiply(matrix1);
                } else {
                    final GeneralMatrix m = new GeneralMatrix(numRow, numCol);
                    m.mul(toGMatrix(matrix2), toGMatrix(matrix1));
                    matrix = m;
                }
                if (matrix.isIdentity(EPSILON)) {
                    matrix.setIdentity();
                }
                // May not be really affine, but work anyway...
                // This call will detect and optimize the special
                // case where an 'AffineTransform' can be used.
                return ProjectiveTransform.create(matrix);
View Full Code Here

Examples of org.geotools.referencing.operation.matrix.XMatrix

        final Matrix matrix2 = transform2.derivative(transform1.transform(point, null));
        // Compute "matrix = matrix2 * matrix1". Reuse an existing matrix object
        // if possible, which is always the case when both matrix are square.
        final int numRow = matrix2.getNumRow();
        final int numCol = matrix1.getNumCol();
        final XMatrix matrix;
        if (numCol == matrix2.getNumCol()) {
            matrix = toXMatrix(matrix2);
            matrix.multiply(matrix1);
        } else {
            final GeneralMatrix m = new GeneralMatrix(numRow, numCol);
            m.mul(toGMatrix(matrix2), toGMatrix(matrix1));
            matrix = m;
        }
View Full Code Here

Examples of org.geotools.referencing.operation.matrix.XMatrix

         * the 'projectedScale' transform. The matrix dimensions are selected accordingly using
         * a robust code when possible, but the result should be a 3x3 matrix most of the time.
         */
        final int  sourceDim = (transform != null) ? transform.getTargetDimensions() : 2;
        final int  targetDim = (projectedScale != null) ? projectedScale.getNumCol()-1 : sourceDim;
        final XMatrix matrix = MatrixFactory.create(targetDim + 1, sourceDim + 1);
        /*
         * Search for "scale factor", "false easting" and "false northing" parameters.
         * All parameters found are removed from the list. Note: we assume that linear
         * units in the "normalized projection" are metres, as specified in the legacy
         * OGC 01-009 specification, and that unit conversions (if needed) are applied
         * by 'projectedScale'. However there is no way I can see to ensure that since
         * it is really a matter of how the map projection is implemented (for example
         * the unit conversion factor could be merged with the "scale_factor" -- not a
         * clean approach and I do not recommand, but some could do in order to save a
         * few multiplications).
         *
         * We need "false easting" and "false northing" offsets in either user's unit or
         * in metres, depending if the unit conversions are applied in 'transform' or in
         * 'projectedScale' respectively. We assume the later, which stands for Geotools
         * implementation and is closer to OGC 01-009 spirit. But we will log a warning
         * in case of doubt.
         */
        Unit<?> unit = null;
        String warning = null;
        for (final Iterator<GeneralParameterValue> it=parameters.iterator(); it.hasNext();) {
            final GeneralParameterValue parameter = it.next();
            if (parameter instanceof ParameterValue) {
                final ParameterValue<?> value = (ParameterValue) parameter;
                final ParameterDescriptor<?> descriptor = value.getDescriptor();
                if (Number.class.isAssignableFrom(descriptor.getValueClass())) {
                    if (nameMatches(descriptor, "scale_factor")) {
                        final double scale = value.doubleValue();
                        for (int i=Math.min(sourceDim, targetDim); --i>=0;) {
                            matrix.setElement(i,i, matrix.getElement(i,i) * scale);
                        }
                    } else {
                        final int d;
                        if (nameMatches(descriptor, "false_easting")) {
                            d = 0;
                        } else if (nameMatches(descriptor, "false_northing")) {
                            d = 1;
                        } else {
                            continue;
                        }
                        final double offset = value.doubleValue(SI.METER);
                        if (!Double.isNaN(offset) && offset != value.doubleValue()) {
                            // See the above comment about units. The above check could have been
                            // replaced by "if (!SI.METER.equals(unit))", but the above avoid the
                            // warning in the very common case where 'offset == 0'.
                            unit = value.getUnit();
                            warning = descriptor.getName().getCode();
                        }
                        matrix.setElement(d, sourceDim, matrix.getElement(d, sourceDim) + offset);
                    }
                    it.remove();
                }
            }
        }
View Full Code Here

Examples of org.geotools.referencing.operation.matrix.XMatrix

     */
    private XMatrix applyProjectedScale(final XMatrix normalizedToProjection) {
        if (projectedScale == null) {
            return normalizedToProjection;
        }
        final XMatrix scale = MatrixFactory.create(projectedScale);
        scale.multiply(normalizedToProjection);
        return scale;
    }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.