/** * Creates the conversion instance to associate with this {@code AbstractDerivedCRS}. * * <p><b>WARNING:</b> this method is invoked at construction time and will invoke indirectly * (through {@link DefaultConversion}) the {@link #getCoordinateSystem()} method on {@code this}. * Consequently this method shall be invoked only after the construction of this {@code AbstractDerivedCRS} * instance is advanced enough for allowing the {@code getCoordinateSystem()} method to execute. * Subclasses may consider to make the {@code getCoordinateSystem()} method final for better guarantees.</p> */ private C createConversionFromBase(final Map<String,?> properties, final SingleCRS baseCRS, final Conversion conversion) { MathTransformFactory factory = null; if (properties != null) { factory = (MathTransformFactory) properties.get(ReferencingServices.MT_FACTORY); } if (factory == null) { factory = DefaultFactories.forBuildin(MathTransformFactory.class); } try { return DefaultConversion.castOrCopy(conversion).specialize(getConversionType(), baseCRS, this, factory); } catch (FactoryException e) { throw new IllegalArgumentException(Errors.getResources(properties).getString( Errors.Keys.IllegalArgumentValue_2, "conversion", conversion.getName()), e); } }
/** * Creates the conversion instance to associate with this {@code AbstractDerivedCRS}. * * <p><b>WARNING:</b> this method is invoked at construction time and will invoke indirectly * (through {@link DefaultConversion}) the {@link #getCoordinateSystem()} method on {@code this}. * Consequently this method shall be invoked only after the construction of this {@code AbstractDerivedCRS} * instance is advanced enough for allowing the {@code getCoordinateSystem()} method to execute. * Subclasses may consider to make the {@code getCoordinateSystem()} method final for better guarantees.</p> */ private C createConversionFromBase(final Map<String,?> properties, final SingleCRS baseCRS, final Conversion conversion) { MathTransformFactory factory = null; if (properties != null) { factory = (MathTransformFactory) properties.get(ReferencingServices.MT_FACTORY); } if (factory == null) { factory = DefaultFactories.forBuildin(MathTransformFactory.class); } try { return DefaultConversion.castOrCopy(conversion).specialize(getConversionType(), baseCRS, this, factory); } catch (FactoryException e) { throw new IllegalArgumentException(Errors.getResources(properties).getString( Errors.Keys.IllegalArgumentValue_2, "conversion", conversion.getName()), e); } }
/** * Ensures that {@link DefaultConversion#specialize DefaultConversion.specialize(…)} verifies the datum. * * @throws FactoryException if an error occurred while creating the conversion. */ @Test public void testDatumCheck() throws FactoryException { final MathTransformFactory factory = DefaultFactories.forBuildin(MathTransformFactory.class); final DefaultConversion op = createLongitudeRotation(true); try { op.specialize(Conversion.class, HardCodedCRS.WGS84, HardCodedCRS.NTF_NORMALIZED_AXES, factory); fail("Should not have accepted to change the geodetic datum."); } catch (IllegalArgumentException e) { final String message = e.getMessage(); assertTrue(message, message.contains("sourceCRS")); assertTrue(message, message.contains("Nouvelle Triangulation Française")); } try { op.specialize(Conversion.class, HardCodedCRS.NTF_NORMALIZED_AXES, HardCodedCRS.WGS84, factory); fail("Should not have accepted to change the geodetic datum."); } catch (IllegalArgumentException e) { final String message = e.getMessage(); assertTrue(message, message.contains("targetCRS")); assertTrue(message, message.contains("Nouvelle Triangulation Française")); } }
assertSame(op, op.specialize(Conversion.class, op.getSourceCRS(), op.getTargetCRS(), factory)); op = op.specialize(DefaultConversion.class, op.getSourceCRS(), changeCS(op.getTargetCRS(), HardCodedCS.GEODETIC_φλ), factory); assertMatrixEquals("Longitude rotation of a two-dimensional CRS", Matrices.create(3, 4, new double[] {
0, 0, 0, 1), MathTransforms.getMatrix(op.getMathTransform()), STRICT); op = op.specialize( DefaultConversion.class, // In normal use, this would be 'Conversion.class'.
final DefaultConversion completed = definingConversion.specialize( DefaultConversion.class, // In normal use, this would be 'Conversion.class'. changeCS(reference.getSourceCRS(), HardCodedCS.GEODETIC_φλ),