本文整理了Java中org.opengis.referencing.operation.Matrix.isIdentity()
方法的一些代码示例,展示了Matrix.isIdentity()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Matrix.isIdentity()
方法的具体详情如下:
包路径:org.opengis.referencing.operation.Matrix
类名称:Matrix
方法名:isIdentity
[英]Returns true if this matrix is an identity matrix.
[中]如果此矩阵是单位矩阵,则返回true。
代码示例来源:origin: apache/sis
/**
* Returns {@code true} if the wrapped matrix is the identity matrix.
*/
@Override
public boolean isIdentity() {
return matrix.isIdentity();
}
代码示例来源:origin: org.apache.sis.core/sis-referencing
/**
* Returns {@code true} if the wrapped matrix is the identity matrix.
*/
@Override
public boolean isIdentity() {
return matrix.isIdentity();
}
代码示例来源:origin: geotools/geotools
/**
* Creates a transform for the specified matrix. The matrix should be affine, but it is not be
* verified.
*
* @param matrix The affine transform as a matrix.
* @return The transform for the given matrix.
*/
public static LinearTransform create(final Matrix matrix) {
final int dimension = matrix.getNumRow() - 1;
if (dimension == matrix.getNumCol() - 1) {
if (matrix.isIdentity()) {
return IdentityTransform.create(dimension);
}
final GeneralMatrix m = toGMatrix(matrix);
if (m.isAffine()) {
switch (dimension) {
case 1:
return LinearTransform1D.create(m.getElement(0, 0), m.getElement(0, 1));
case 2:
return create(m.toAffineTransform2D());
}
}
}
switch (dimension) {
case 2:
return new ProjectiveTransform2D(matrix);
default:
return new ProjectiveTransform(matrix);
}
}
代码示例来源:origin: geotools/geotools
DefaultCoordinateSystemAxis.GEODETIC_LATITUDE,
DefaultCoordinateSystemAxis.GEODETIC_LONGITUDE);
assertTrue(AbstractCS.swapAndScaleAxis(cs1, cs1).isIdentity());
assertTrue(AbstractCS.swapAndScaleAxis(cs2, cs2).isIdentity());
compareMatrix(
cs1,
代码示例来源:origin: apache/sis
/**
* {@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;
}
代码示例来源:origin: org.apache.sis.core/sis-referencing
/**
* {@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;
}
代码示例来源:origin: geotools/geotools
final Matrix append = toStandard(sourceCRS, true);
Conversion projection = sourceCRS.getConversionFromBase();
if (!prepend.isIdentity() || !append.isIdentity()) {
final MathTransformFactory mtFactory = getMathTransformFactory();
MathTransform mt = projection.getMathTransform();
代码示例来源:origin: org.apache.sis.core/sis-referencing
if (after != null) {
final Matrix merged = Matrices.multiply(after, (Matrix) step);
if (merged.isIdentity()) {
transforms.subList(i, i+2).clear();
after = null;
代码示例来源:origin: geotools/geotools
Matrix matrix = ((LinearTransform) transform).getMatrix();
assertDiagonal(matrix);
assertFalse(matrix.isIdentity());
assertEquals("West direction should be unchanged. ", +1, matrix.getElement(0, 0), EPS);
assertEquals("North-South direction should be reverted.", -1, matrix.getElement(1, 1), EPS);
matrix = ((LinearTransform) transform).getMatrix();
assertDiagonal(matrix);
assertFalse(matrix.isIdentity());
assertEquals("West direction should be unchanged. ", +1, matrix.getElement(0, 0), EPS);
assertEquals("North-South direction should be reverted.", -1, matrix.getElement(1, 1), EPS);
assertTrue(transform instanceof LinearTransform);
matrix = ((LinearTransform) transform).getMatrix();
assertFalse(matrix.isIdentity());
assertEquals("West direction should be unchanged. ", +1, matrix.getElement(0, 0), EPS);
assertEquals("North-South direction should be reverted.", -1, matrix.getElement(1, 1), EPS);
代码示例来源:origin: org.apache.sis.core/sis-referencing
Matrix m = CoordinateSystems.swapAndScaleAxes(sourceCRS.getCoordinateSystem(),
targetCRS.getCoordinateSystem());
if (!m.isIdentity()) {
if (interpDim != 0) {
m = Matrices.createPassThrough(interpDim, m, 0);
代码示例来源:origin: apache/sis
/**
* Tests if the given transform is the identity transform.
* If the current transform is linear, then this method will also verifies {@link Matrix#isIdentity()}.
*
* @param transform the transform to test.
*
* @since 0.6
*/
public static void assertIsIdentity(final MathTransform transform) {
assertTrue("isIdentity()", transform.isIdentity());
if (transform instanceof LinearTransform) {
assertTrue("getMatrix().isIdentity()", ((LinearTransform) transform).getMatrix().isIdentity());
}
}
代码示例来源:origin: apache/sis
Matrix m = CoordinateSystems.swapAndScaleAxes(sourceCRS.getCoordinateSystem(),
targetCRS.getCoordinateSystem());
if (!m.isIdentity()) {
if (interpDim != 0) {
m = Matrices.createPassThrough(interpDim, m, 0);
代码示例来源:origin: apache/sis
/**
* Tests if the given transform is <strong>not</strong> the identity transform.
* If the current transform is linear, then this method will also verifies {@link Matrix#isIdentity()}.
*
* @param transform the transform to test.
*
* @since 0.6
*/
public static void assertIsNotIdentity(final MathTransform transform) {
assertFalse("isIdentity()", transform.isIdentity());
if (transform instanceof LinearTransform) {
assertFalse("getMatrix().isIdentity()", ((LinearTransform) transform).getMatrix().isIdentity());
}
}
}
代码示例来源:origin: apache/sis
/**
* Returns an affine transform between two coordinate systems.
* Only units and axes order are taken in account by this method.
*
* @param sourceCRS the source coordinate reference system.
* @param targetCRS the target coordinate reference system.
* @param mtFactory the math transform factory to use.
* @return the transform from the given source to the given target CRS, or {@code null} if none is needed.
* @throws IllegalArgumentException if the coordinate systems are not of the same type or axes do not match.
* @throws IncommensurableException if the units are not compatible or a unit conversion is non-linear.
* @throws FactoryException if an error occurred while creating a math transform.
*/
private static MathTransform swapAndScaleAxes(final CoordinateReferenceSystem sourceCRS,
final CoordinateReferenceSystem targetCRS,
final MathTransformFactory mtFactory)
throws IllegalArgumentException, IncommensurableException, FactoryException
{
/*
* Assertion: source and target CRS must be equals, ignoring change in axis order or units.
* The first line is for disabling this check if the number of dimensions are not the same
* (e.g. as in the "geographic 3D to geographic 2D" conversion) because ALLOW_VARIANT mode
* still requires a matching number of dimensions.
*/
assert ReferencingUtilities.getDimension(sourceCRS) != ReferencingUtilities.getDimension(targetCRS)
|| Utilities.deepEquals(sourceCRS, targetCRS, ComparisonMode.ALLOW_VARIANT);
final Matrix m = CoordinateSystems.swapAndScaleAxes(sourceCRS.getCoordinateSystem(), targetCRS.getCoordinateSystem());
return (m.isIdentity()) ? null : mtFactory.createAffineTransform(m);
}
代码示例来源:origin: org.apache.sis.core/sis-referencing
/**
* Returns an affine transform between two coordinate systems.
* Only units and axes order are taken in account by this method.
*
* @param sourceCRS the source coordinate reference system.
* @param targetCRS the target coordinate reference system.
* @param mtFactory the math transform factory to use.
* @return the transform from the given source to the given target CRS, or {@code null} if none is needed.
* @throws IllegalArgumentException if the coordinate systems are not of the same type or axes do not match.
* @throws IncommensurableException if the units are not compatible or a unit conversion is non-linear.
* @throws FactoryException if an error occurred while creating a math transform.
*/
private static MathTransform swapAndScaleAxes(final CoordinateReferenceSystem sourceCRS,
final CoordinateReferenceSystem targetCRS,
final MathTransformFactory mtFactory)
throws IllegalArgumentException, IncommensurableException, FactoryException
{
/*
* Assertion: source and target CRS must be equals, ignoring change in axis order or units.
* The first line is for disabling this check if the number of dimensions are not the same
* (e.g. as in the "geographic 3D to geographic 2D" conversion) because ALLOW_VARIANT mode
* still requires a matching number of dimensions.
*/
assert ReferencingUtilities.getDimension(sourceCRS) != ReferencingUtilities.getDimension(targetCRS)
|| Utilities.deepEquals(sourceCRS, targetCRS, ComparisonMode.ALLOW_VARIANT);
final Matrix m = CoordinateSystems.swapAndScaleAxes(sourceCRS.getCoordinateSystem(), targetCRS.getCoordinateSystem());
return (m.isIdentity()) ? null : mtFactory.createAffineTransform(m);
}
代码示例来源:origin: apache/sis
/**
* Tests {@link CoordinateSystems#swapAndScaleAxes(CoordinateSystem, CoordinateSystem)} for (λ,φ) ↔ (φ,λ).
* This very common conversion is of critical importance to Apache SIS.
*
* @throws IncommensurableException if a conversion between incompatible units was attempted.
*/
@Test
public void testSwapAndScaleAxes2D() throws IncommensurableException {
final CoordinateSystem λφ = new DefaultEllipsoidalCS(singletonMap(NAME_KEY, "(λ,φ)"),
HardCodedAxes.GEODETIC_LONGITUDE,
HardCodedAxes.GEODETIC_LATITUDE);
final CoordinateSystem φλ = new DefaultEllipsoidalCS(singletonMap(NAME_KEY, "(φ,λ)"),
HardCodedAxes.GEODETIC_LATITUDE,
HardCodedAxes.GEODETIC_LONGITUDE);
final Matrix expected = Matrices.create(3, 3, new double[] {
0, 1, 0,
1, 0, 0,
0, 0, 1});
assertTrue(swapAndScaleAxes(λφ, λφ).isIdentity());
assertTrue(swapAndScaleAxes(φλ, φλ).isIdentity());
assertMatrixEquals("(λ,φ) → (φ,λ)", expected, swapAndScaleAxes(λφ, φλ), STRICT);
assertMatrixEquals("(φ,λ) → (λ,φ)", expected, swapAndScaleAxes(φλ, λφ), STRICT);
}
代码示例来源:origin: apache/sis
/**
* Tests {@link CoordinateSystems#swapAndScaleAxes(CoordinateSystem, CoordinateSystem)} for (λ,φ,h) ↔ (φ,λ,h).
* This very common conversion is of critical importance to Apache SIS.
*
* @throws IncommensurableException if a conversion between incompatible units was attempted.
*/
@Test
@DependsOnMethod("testSwapAndScaleAxes2D")
public void testSwapAndScaleAxes3D() throws IncommensurableException {
final CoordinateSystem λφh = new DefaultEllipsoidalCS(singletonMap(NAME_KEY, "(λ,φ,h)"),
HardCodedAxes.GEODETIC_LONGITUDE,
HardCodedAxes.GEODETIC_LATITUDE,
HardCodedAxes.ELLIPSOIDAL_HEIGHT);
final CoordinateSystem φλh = new DefaultEllipsoidalCS(singletonMap(NAME_KEY, "(φ,λ,h)"),
HardCodedAxes.GEODETIC_LATITUDE,
HardCodedAxes.GEODETIC_LONGITUDE,
HardCodedAxes.ELLIPSOIDAL_HEIGHT);
final Matrix expected = Matrices.create(4, 4, new double[] {
0, 1, 0, 0,
1, 0, 0, 0,
0, 0, 1, 0,
0, 0, 0, 1});
assertTrue(swapAndScaleAxes(λφh, λφh).isIdentity());
assertTrue(swapAndScaleAxes(φλh, φλh).isIdentity());
assertMatrixEquals("(λ,φ,h) → (φ,λ,h)", expected, swapAndScaleAxes(λφh, φλh), STRICT);
assertMatrixEquals("(φ,λ,h) → (λ,φ,h)", expected, swapAndScaleAxes(φλh, λφh), STRICT);
}
代码示例来源:origin: apache/sis
/**
* Tests {@link CoordinateSystems#swapAndScaleAxes(CoordinateSystem, CoordinateSystem)}
* with a more arbitrary case, which include unit conversions.
*
* @throws IncommensurableException if a conversion between incompatible units was attempted.
*/
@Test
@DependsOnMethod("testSwapAndScaleAxes3D")
public void testSwapAndScaleAxes() throws IncommensurableException {
final CoordinateSystem hxy = new DefaultCartesianCS(singletonMap(NAME_KEY, "(h,x,y)"),
HardCodedAxes.HEIGHT_cm,
HardCodedAxes.EASTING,
HardCodedAxes.NORTHING);
final CoordinateSystem yxh = new DefaultCartesianCS(singletonMap(NAME_KEY, "(y,x,h)"),
HardCodedAxes.SOUTHING,
HardCodedAxes.EASTING,
HardCodedAxes.DEPTH);
assertTrue(swapAndScaleAxes(hxy, hxy).isIdentity());
assertTrue(swapAndScaleAxes(yxh, yxh).isIdentity());
assertMatrixEquals("(h,x,y) → (y,x,h)", Matrices.create(4, 4, new double[] {
0, 0, -1, 0,
0, 1, 0, 0,
-0.01, 0, 0, 0,
0, 0, 0, 1}), swapAndScaleAxes(hxy, yxh), STRICT);
assertMatrixEquals("(y,x,h) → (h,x,y)", Matrices.create(4, 4, new double[] {
0, 0, -100, 0,
0, 1, 0, 0,
-1, 0, 0, 0,
0, 0, 0, 1}), swapAndScaleAxes(yxh, hxy), STRICT);
}
代码示例来源:origin: apache/sis
/**
* Verifies some global properties.
*/
@Test
public void verifyGlobalProperties() {
assertEquals("translationDimensions", 2, grid.getTranslationDimensions());
assertTrue("coordinateToGrid.isIdentity", grid.getCoordinateToGrid().isIdentity());
assertTrue("gridToTarget.isIdentity", grid.gridToTarget().isIdentity());
}
代码示例来源:origin: org.apache.sis.core/sis-referencing
final int targetDimension = matrix.getNumRow() - 1;
if (sourceDimension == targetDimension) {
if (matrix.isIdentity()) {
return identity(sourceDimension);
内容来源于网络,如有侵权,请联系作者删除!