conversion = new DefaultConversion(properties, method, null, parameters); } catch (IllegalArgumentException exception) { throw new InvalidGeodeticParameterException(exception.getLocalizedMessage(), exception);
/** * Returns the source CRS, which must be geographic or {@code null}. */ @Override public final GeographicCRS getSourceCRS() { return (GeographicCRS) super.getSourceCRS(); }
/** * Returns the target CRS, which must be projected or {@code null}. */ @Override public final ProjectedCRS getTargetCRS() { return (ProjectedCRS) super.getTargetCRS(); } }
/** * 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); } }
public void testDefiningConversion() throws FactoryException { final DefaultConversion reference = createLongitudeRotation(true); final DefaultConversion definingConversion = new DefaultConversion( IdentifiedObjects.getProperties(reference), reference.getMethod(), reference.getMathTransform(), reference.getParameterValues()); assertNull("sourceCRS", definingConversion.getSourceCRS()); assertNull("targetCRS", definingConversion.getTargetCRS()); assertFalse(definingConversion.equals(reference)); assertFalse(reference.equals(definingConversion)); final DefaultConversion completed = definingConversion.specialize( DefaultConversion.class, // In normal use, this would be 'Conversion.class'. changeCS(reference.getSourceCRS(), HardCodedCS.GEODETIC_φλ), reference.getTargetCRS(), DefaultFactories.forBuildin(MathTransformFactory.class));
public void testConversionUnmarshalling() throws JAXBException { final DefaultConversion c = unmarshalFile(DefaultConversion.class, "Conversion.xml"); assertEquals("name", "World Mercator", c.getName().getCode()); assertEquals("identifier", "3395", getSingleton(c.getIdentifiers()).getCode()); assertEquals("scope", "Very small scale mapping.", String.valueOf(c.getScope())); assertNull ("operationVersion", c.getOperationVersion()); final GeographicBoundingBox e = (GeographicBoundingBox) getSingleton(c.getDomainOfValidity().getGeographicElements()); assertEquals("eastBoundLongitude", +180, e.getEastBoundLongitude(), STRICT); assertEquals("westBoundLongitude", -180, e.getWestBoundLongitude(), STRICT); assertNull("sourceCRS", c.getSourceCRS()); assertNull("targetCRS", c.getTargetCRS()); assertNull("interpolationCRS", c.getInterpolationCRS()); assertNull("mathTransform", c.getMathTransform()); final OperationMethod method = c.getMethod(); assertNotNull("method", method); verifyMethod(method); final ParameterValueGroup parameters = c.getParameterValues(); assertNotNull("parameters", parameters); final Iterator<GeneralParameterValue> it = parameters.values().iterator();
/** * Asserts that at least some of the properties of the given {@code op} instance have the expected values * for an instance created by {@link #createLongitudeRotation(GeographicCRS, GeographicCRS, TemporalCRS)}. */ @SuppressWarnings("SuspiciousToArrayCall") private static void verifyProperties(final DefaultConversion op, final boolean swapSourceAxes) { assertEquals("name", "Paris to Greenwich", op.getName().getCode()); assertEquals("sourceCRS", "NTF (Paris)", op.getSourceCRS().getName().getCode()); assertEquals("targetCRS", "Back to Greenwich", op.getTargetCRS().getName().getCode()); assertEquals("method", "Longitude rotation", op.getMethod().getName().getCode()); assertEquals("parameters", "Longitude rotation", op.getParameterDescriptors().getName().getCode()); final ParameterValueGroup parameters = op.getParameterValues(); final ParameterValue<?>[] values = parameters.values().toArray(new ParameterValue<?>[1]); assertEquals("parameters", "Longitude rotation", parameters.getDescriptor().getName().getCode()); assertEquals("parameters[0]", "Longitude offset", values[0].getDescriptor().getName().getCode()); assertEquals("parameters[0]", OFFSET, values[0].doubleValue(), STRICT); assertEquals(1, values.length); final Matrix3 expected = new Matrix3(); expected.m02 = OFFSET; if (swapSourceAxes) { expected.m00 = expected.m11 = 0; expected.m01 = expected.m10 = 1; } assertMatrixEquals("Longitude rotation of a two-dimensional CRS", expected, MathTransforms.getMatrix(op.getMathTransform()), STRICT); }
0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1), MathTransforms.getMatrix(op.getMathTransform()), STRICT); 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, 1, 0, 0, 1, 0, 0, OFFSET, 0, 0, 0, 1}), MathTransforms.getMatrix(op.getMathTransform()), STRICT);
/** * Creates a dummy derived CRS defined by a longitude rotation from Paris to Greenwich prime meridian, * and swapping the axis order. The result is equivalent to {@link HardCodedCRS#WGS84_φλ}, * which of course makes the returned {@code DerivedCRS} totally useless. * Its purpose is only to perform easy tests. */ private static DefaultDerivedCRS createLongitudeRotation() { final DefaultConversion conversion = DefaultConversionTest.createLongitudeRotation(false); return new DefaultDerivedCRS(Collections.singletonMap(DefaultDerivedCRS.NAME_KEY, conversion.getTargetCRS().getName()), (SingleCRS) conversion.getSourceCRS(), conversion, HardCodedCS.GEODETIC_φλ); }
/** * Invoked by JAXB at unmarshalling time for storing the result temporarily. * * @param conversion the unmarshalled element. */ public void setElement(final DefaultConversion conversion) { metadata = conversion; Context.setWrapper(Context.current(), this); if (conversion.getMethod() == null) incomplete("method"); }
/** * 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")); } }
/** * Invoked by JAXB at marshalling time for getting the actual element to write * inside the {@code <gml:Conversion>} XML element. * This is the value or a copy of the value given in argument to the {@code wrap} method. * * @return the element to be marshalled. */ @XmlElement(name = "Conversion") public DefaultConversion getElement() { return DefaultConversion.castOrCopy(metadata); }
if (transform != null) { this.transform = transform; checkDimensions(method, 0, transform, properties); } else if (parameters == null) { throw new IllegalArgumentException(Resources.forProperties(properties) this.parameters = Parameters.unmodifiable(parameters); checkDimensions(properties);
0, 1, 0, OFFSET, 0, 0, 1, 0, 0, 0, 0, 1), MathTransforms.getMatrix(op.getMathTransform()), STRICT); op = op.specialize( DefaultConversion.class, // In normal use, this would be 'Conversion.class'. op.getSourceCRS(), // Keep the same source CRS. changeCS(op.getTargetCRS(), HardCodedCS.GEODETIC_φλ), // Swap axis order. DefaultFactories.forBuildin(MathTransformFactory.class)); 0, 0, 1, 0, 0, 1, 0, OFFSET, 0, 0, 0, 1), MathTransforms.getMatrix(op.getMathTransform()), STRICT);
/** * 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); } }
/** * Invoked by JAXB at unmarshalling time for storing the result temporarily. * * @param conversion the unmarshalled element. */ public void setElement(final DefaultConversion conversion) { metadata = conversion; Context.setWrapper(Context.current(), this); if (conversion.getMethod() == null) incomplete("method"); }
/** * Invoked by JAXB at marshalling time for getting the actual element to write * inside the {@code <gml:Conversion>} XML element. * This is the value or a copy of the value given in argument to the {@code wrap} method. * * @return the element to be marshalled. */ @XmlElement(name = "Conversion") public DefaultConversion getElement() { return DefaultConversion.castOrCopy(metadata); }
if (transform != null) { this.transform = transform; checkDimensions(method, 0, transform, properties); } else if (parameters == null) { throw new IllegalArgumentException(Resources.forProperties(properties) this.parameters = Parameters.unmodifiable(parameters); checkDimensions(properties);
conversion = new DefaultConversion(properties, method, null, parameters); } catch (IllegalArgumentException exception) { throw new InvalidGeodeticParameterException(exception.getLocalizedMessage(), exception);
/** * Returns the target CRS, which must be projected or {@code null}. */ @Override public final ProjectedCRS getTargetCRS() { return (ProjectedCRS) super.getTargetCRS(); } }