/** * Test the pass through transform using an affine transform. The "passthrough" of such * transform are optimized in a special way. */ @Test public void testLinear() throws FactoryException, TransformException { runTest( mtFactory.createAffineTransform( new GeneralMatrix(AffineTransform.getScaleInstance(4, 2)))); }
final Matrix matrix) throws FactoryException { final MathTransform transform = mtFactory.createAffineTransform(matrix); final Map<String, ?> properties = getProperties(name); final Class<? extends Operation> type =
/** Delegate to {@link MathTransformFactory#createAffineTransform(Matrix)}. */ @Override MathTransform linear(Matrix matrix) throws FactoryException { return factory.createAffineTransform(matrix); }
MathTransform filtered = factory.createAffineTransform(matrix); if (transform != null) { filtered = factory.createConcatenatedTransform(transform, filtered);
return factory.createAffineTransform(MatrixFactory.create(dimInput + 1)); return factory.createAffineTransform(MatrixFactory.create(dimInput + 1)); return factory.createAffineTransform(new GeneralMatrix(rows));
/** * Returns a linear transform created using the given factory. * This method is used only when the user specify explicitly a factory to use. * * @param factory the factory to use. * @param withScale {@code true} for using {@link #scale}, or {@code false} for replacing the scale by zero. */ private MathTransform createAffineTransform(final MathTransformFactory factory, final boolean withScale) throws FactoryException { return factory.createAffineTransform(new Matrix2(withScale ? scale : 0, offset, 0, 1)); }
ReferencingFactoryFinder.getMathTransformFactory(null); MathTransform affineMT = factory.createAffineTransform( new org.geotools.referencing.operation.matrix.AffineTransform2D( tx));
mtFactory.createConcatenatedTransform( mtFactory.createConcatenatedTransform( mtFactory.createAffineTransform(prepend), mt), mtFactory.createAffineTransform(append)); projection = new DefiningConversion(
/** Tests the transformation of a single coordinate. */ @Test public void testTransformCoordinate() throws FactoryException, TransformException { Coordinate coord = new Coordinate(10, 10); AffineTransform at = AffineTransform.getScaleInstance(0.5, 1); MathTransform2D t = (MathTransform2D) ReferencingFactoryFinder.getMathTransformFactory(null) .createAffineTransform(new GeneralMatrix(at)); coord = JTS.transform(coord, coord, t); assertEquals(new Coordinate(5, 10), coord); coord = JTS.transform(coord, coord, t.inverse()); assertEquals(new Coordinate(10, 10), coord); CoordinateReferenceSystem crs = ReferencingFactoryFinder.getCRSFactory(null).createFromWKT(UTM_ZONE_10N); t = (MathTransform2D) ReferencingFactoryFinder.getCoordinateOperationFactory(null) .createOperation(DefaultGeographicCRS.WGS84, crs) .getMathTransform(); coord = new Coordinate(-123, 55); coord = JTS.transform(coord, coord, t); coord = JTS.transform(coord, coord, t.inverse()); assertEquals(-123, coord.x, EPS); assertEquals(55, coord.y, EPS); }
/** * 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 { return factory.createAffineTransform(Matrices.createDiagonal(getTargetDimensions() + 1, getSourceDimensions() + 1)); } }
/** * 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 { return factory.createAffineTransform(Matrices.createDiagonal(getTargetDimensions() + 1, getSourceDimensions() + 1)); } }
/** * Runs a test using the given matrix. This method checks only for internal consistency, * i.e. we don't have an external implementation that we can use for comparing the results. */ private void runTest(final int numRow, final int numCol, final double... elements) throws FactoryException, TransformException { assumeNotNull(mtFactory); if (matrix == null) { matrix = new SimpleMatrix(numRow, numCol, elements); } if (transform == null) { transform = mtFactory.createAffineTransform(matrix); assertNotNull(transform); } verifyInternalConsistency(Arrays.hashCode(elements)); }
/** * Creates a coordinate operation from a matrix, which usually describes an affine transform. * A default {@link OperationMethod} object is given to this transform. In the special case * where the {@code name} identifier is {@link #DATUM_SHIFT} or {@link #ELLIPSOID_CHANGE}, * the operation will be a {@link Transformation} instance instead of {@link Conversion}. * * @param name the identifier for the operation to be created. * @param sourceCRS the source coordinate reference system. * @param targetCRS the target coordinate reference system. * @param matrix the matrix which describe an affine transform operation. * @return the conversion or transformation. * @throws FactoryException if the operation can not be created. */ private CoordinateOperation createFromAffineTransform(final Identifier name, final CoordinateReferenceSystem sourceCRS, final CoordinateReferenceSystem targetCRS, final Matrix matrix) throws FactoryException { final MathTransform transform = factorySIS.getMathTransformFactory().createAffineTransform(matrix); return createFromMathTransform(properties(name), sourceCRS, targetCRS, transform, null, null, null); }
/** * Creates a coordinate operation from a matrix, which usually describes an affine transform. * A default {@link OperationMethod} object is given to this transform. In the special case * where the {@code name} identifier is {@link #DATUM_SHIFT} or {@link #ELLIPSOID_CHANGE}, * the operation will be a {@link Transformation} instance instead of {@link Conversion}. * * @param name the identifier for the operation to be created. * @param sourceCRS the source coordinate reference system. * @param targetCRS the target coordinate reference system. * @param matrix the matrix which describe an affine transform operation. * @return the conversion or transformation. * @throws FactoryException if the operation can not be created. */ private CoordinateOperation createFromAffineTransform(final Identifier name, final CoordinateReferenceSystem sourceCRS, final CoordinateReferenceSystem targetCRS, final Matrix matrix) throws FactoryException { final MathTransform transform = factorySIS.getMathTransformFactory().createAffineTransform(matrix); return createFromMathTransform(properties(name), sourceCRS, targetCRS, transform, null, null, null); }
/** * Invoked when {@link #tryConcatenate(boolean, MathTransform, MathTransformFactory)} detected a * (inverse) → (affine) → (this) transforms sequence. */ @Override final MathTransform tryConcatenate(boolean projectedSpace, Matrix affine, MathTransformFactory factory) throws FactoryException { /* * Verify that the latitude row is an identity conversion except for the sign which is allowed to change * (but no scale and no translation are allowed). Ignore the longitude row because it just pass through * this Mercator projection with no impact on any calculation. */ if (affine.getElement(1,0) == 0 && affine.getElement(1, DIMENSION) == 0 && Math.abs(affine.getElement(1,1)) == 1) { if (factory != null) { return factory.createAffineTransform(affine); } else { return MathTransforms.linear(affine); } } return super.tryConcatenate(projectedSpace, affine, factory); } }
/** * Invoked when {@link #tryConcatenate(boolean, MathTransform, MathTransformFactory)} detected a * (inverse) → (affine) → (this) transforms sequence. */ @Override final MathTransform tryConcatenate(boolean projectedSpace, Matrix affine, MathTransformFactory factory) throws FactoryException { /* * Verify that the latitude row is an identity conversion except for the sign which is allowed to change * (but no scale and no translation are allowed). Ignore the longitude row because it just pass through * this Mercator projection with no impact on any calculation. */ if (affine.getElement(1,0) == 0 && affine.getElement(1, DIMENSION) == 0 && Math.abs(affine.getElement(1,1)) == 1) { if (factory != null) { return factory.createAffineTransform(affine); } else { return MathTransforms.linear(affine); } } return super.tryConcatenate(projectedSpace, affine, factory); } }
(MathTransform2D) ReferencingFactoryFinder.getMathTransformFactory(null) .createAffineTransform(new GeneralMatrix(at)); envelope = JTS.transform(envelope, t); assertEquals(new Envelope(0, 5, 0, 10), envelope);
/** * 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); } }
/** * 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); } }
/** * 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); }