Java Code Examples for org.opengis.referencing.operation.Matrix#isIdentity()
The following examples show how to use
org.opengis.referencing.operation.Matrix#isIdentity() .
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: DefaultConversion.java From sis with Apache License 2.0 | 6 votes |
/** * Concatenates to the given transform the operation needed for swapping and scaling the axes. * The two coordinate systems must implement the same GeoAPI coordinate system interface. * For example if {@code sourceCRS} uses a {@code CartesianCS}, then {@code targetCRS} must use * a {@code CartesianCS} too. * * @param transform the transform to which to concatenate axis changes. * @param sourceCRS the first CRS of the pair for which to check for axes changes. * @param targetCRS the second CRS of the pair for which to check for axes changes. * @param interpDim the number of dimensions of the interpolation CRS, or 0 if none. * @param isSource {@code true} for pre-concatenating the changes, or {@code false} for post-concatenating. * @param factory the factory to use for performing axis changes. */ private static MathTransform swapAndScaleAxes(MathTransform transform, final CoordinateReferenceSystem sourceCRS, final CoordinateReferenceSystem targetCRS, final int interpDim, final boolean isSource, final MathTransformFactory factory) throws FactoryException { if (sourceCRS != null && targetCRS != null && sourceCRS != targetCRS) try { Matrix m = CoordinateSystems.swapAndScaleAxes(sourceCRS.getCoordinateSystem(), targetCRS.getCoordinateSystem()); if (!m.isIdentity()) { if (interpDim != 0) { m = Matrices.createPassThrough(interpDim, m, 0); } final MathTransform s = factory.createAffineTransform(m); transform = factory.createConcatenatedTransform(isSource ? s : transform, isSource ? transform : s); } } catch (IncommensurableException e) { throw new IllegalArgumentException(Errors.format(Errors.Keys.IllegalArgumentValue_2, (isSource ? "sourceCRS" : "targetCRS"), (isSource ? sourceCRS : targetCRS).getName()), e); } return transform; }
Example 2
Source File: MathTransforms.java From sis with Apache License 2.0 | 5 votes |
/** * Creates an arbitrary linear transform from the specified matrix. Usually the matrix * {@linkplain org.apache.sis.referencing.operation.matrix.MatrixSIS#isAffine() is affine}, * but this is not mandatory. Non-affine matrix will define a projective transform. * * <p>If the transform input dimension is {@code M}, and output dimension is {@code N}, * then the given matrix shall have size {@code [N+1][M+1]}. * The +1 in the matrix dimensions allows the matrix to do a shift, as well as a rotation. * The {@code [M][j]} element of the matrix will be the <var>j</var>'th coordinate of the moved origin.</p> * * @param matrix the matrix used to define the linear transform. * @return the linear (usually affine) transform. * * @see #getMatrix(MathTransform) * @see DefaultMathTransformFactory#createAffineTransform(Matrix) */ public static LinearTransform linear(final Matrix matrix) { ArgumentChecks.ensureNonNull("matrix", matrix); final int sourceDimension = matrix.getNumCol() - 1; final int targetDimension = matrix.getNumRow() - 1; if (sourceDimension == targetDimension) { if (matrix.isIdentity()) { return identity(sourceDimension); } if (Matrices.isAffine(matrix)) { switch (sourceDimension) { case 1: { return linear(matrix.getElement(0,0), matrix.getElement(0,1)); } case 2: { if (matrix instanceof ExtendedPrecisionMatrix) { return new AffineTransform2D(((ExtendedPrecisionMatrix) matrix).getExtendedElements()); } else { return new AffineTransform2D( matrix.getElement(0,0), matrix.getElement(1,0), matrix.getElement(0,1), matrix.getElement(1,1), matrix.getElement(0,2), matrix.getElement(1,2)); } } } } else if (sourceDimension == 2) { return new ProjectiveTransform2D(matrix); } } final LinearTransform candidate = CopyTransform.create(matrix); if (candidate != null) { return candidate; } return new ProjectiveTransform(matrix).optimize(); }
Example 3
Source File: NonSquareMatrix.java From sis with Apache License 2.0 | 5 votes |
/** * {@inheritDoc} * * <p>This method delegates the work to {@code inverse().multiply(matrix)} in order to leverage * the special handling done by {@code inverse()} for non-square matrices.</p> */ @Override public MatrixSIS solve(final Matrix matrix) throws MismatchedMatrixSizeException, NoninvertibleMatrixException { MatrixSIS result = inverse(); if (!matrix.isIdentity()) { result = result.multiply(matrix); } return result; }