Author: desruisseaux Date: Fri Nov 4 22:45:28 2016 New Revision: 1768119 URL: http://svn.apache.org/viewvc?rev=1768119&view=rev Log: Fix for SIS-333: Ellipsoid that are sphere should have <isSphere>true</isSphere> as their second defining parameter in GML.
Added: sis/branches/JDK8/core/sis-referencing/src/test/resources/org/apache/sis/referencing/datum/Sphere.xml - copied, changed from r1768094, sis/branches/JDK8/core/sis-referencing/src/test/resources/org/apache/sis/referencing/datum/Ellipsoid.xml Modified: sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/internal/jaxb/referencing/SecondDefiningParameter.java sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/datum/DefaultEllipsoid.java sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/internal/jaxb/referencing/SecondDefiningParameterTest.java sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/referencing/datum/DefaultEllipsoidTest.java Modified: sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/internal/jaxb/referencing/SecondDefiningParameter.java URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/internal/jaxb/referencing/SecondDefiningParameter.java?rev=1768119&r1=1768118&r2=1768119&view=diff ============================================================================== --- sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/internal/jaxb/referencing/SecondDefiningParameter.java [UTF-8] (original) +++ sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/internal/jaxb/referencing/SecondDefiningParameter.java [UTF-8] Fri Nov 4 22:45:28 2016 @@ -18,7 +18,6 @@ package org.apache.sis.internal.jaxb.ref import javax.xml.bind.annotation.XmlElement; import javax.xml.bind.annotation.XmlRootElement; -import javax.measure.Unit; import org.opengis.referencing.datum.Ellipsoid; import org.apache.sis.measure.Units; import org.apache.sis.xml.Namespaces; @@ -42,15 +41,43 @@ import org.apache.sis.util.resources.Err public final class SecondDefiningParameter { /** * Nested parameter, for JAXB purpose. + * This is used for marshalling XML like below: + * + * {@preformat xml + * <gml:secondDefiningParameter> + * <gml:SecondDefiningParameter> + * <gml:semiMinorAxis uom="urn:ogc:def:uom:EPSG::9001">6371007</gml:semiMinorAxis> + * </gml:SecondDefiningParameter> + * </gml:secondDefiningParameter> + * } */ @XmlElement(name = "SecondDefiningParameter") public SecondDefiningParameter secondDefiningParameter; /** + * Whether the ellipsoid is a sphere, or {@code null} if unspecified. + * If this value is {@code true}, then the XML shall be marshalled like below: + * + * {@preformat xml + * <gml:secondDefiningParameter> + * <gml:SecondDefiningParameter> + * <gml:isSphere>true</gml:isSphere> + * </gml:SecondDefiningParameter> + * </gml:secondDefiningParameter> + * } + * + * @since 0.8 + */ + @XmlElement + public Boolean isSphere; + + /** * The measure, which is either the polar radius or the inverse of the flattening value. * We distinguish those two cases by the unit: if the measure is the inverse flattening, * then the unit must be {@link Units#UNITY}. * + * <p>This value should be {@code null} if {@link #isSphere} is {@code true}.</p> + * * @see Ellipsoid#getSemiMinorAxis() * @see Ellipsoid#getInverseFlattening() */ @@ -65,14 +92,16 @@ public final class SecondDefiningParamet /** * Stores the semi-minor axis or the inverse of the flattening value. * - * @param ellipsoid The ellipsoid from which to get the semi-minor or inverse flattening value. - * @param nested {@code true} if the element should be nested in an other XML type. + * @param ellipsoid the ellipsoid from which to get the semi-minor or inverse flattening value. + * @param nested {@code true} if the element should be nested in an other XML type. */ public SecondDefiningParameter(final Ellipsoid ellipsoid, final boolean nested) { if (nested) { secondDefiningParameter = new SecondDefiningParameter(ellipsoid, false); } else { - if (ellipsoid.isIvfDefinitive()) { + if (ellipsoid.isSphere()) { + isSphere = Boolean.TRUE; + } else if (ellipsoid.isIvfDefinitive()) { measure = new Measure(ellipsoid.getInverseFlattening(), Units.UNITY); } else { measure = new Measure(ellipsoid.getSemiMinorAxis(), ellipsoid.getAxisUnit()); @@ -92,7 +121,7 @@ public final class SecondDefiningParamet /** * Returns the semi-minor axis value as a measurement. * - * @return The measure of the semi-minor axis. + * @return the measure of the semi-minor axis. */ @XmlElement(name = "semiMinorAxis") public Measure getSemiMinorAxis() { @@ -104,7 +133,7 @@ public final class SecondDefiningParamet * The unit of measurement (if any) shall be linear, but we do not verify that now. * This will be verified by {@code DefaultEllipsoid.setSecondDefiningParameter(…)}. * - * @param measure The semi-minor axis value. + * @param measure the semi-minor axis value. */ public void setSemiMinorAxis(final Measure measure) { this.measure = measure; @@ -114,7 +143,7 @@ public final class SecondDefiningParamet * Returns the inverse of the flattening value as a measurement. * Note: The unit of this measurement is dimensionless. * - * @return The inverse of the flattening value as a measurement. + * @return the inverse of the flattening value as a measurement. */ @XmlElement(name = "inverseFlattening") public Measure getInverseFlattening() { @@ -128,7 +157,7 @@ public final class SecondDefiningParamet * This method overwrite the unit with a dimensionless one. This is required anyway * in order to distinguish between the two cases.</p> * - * @param measure The inverse flattening value. + * @param measure the inverse flattening value. */ public void setInverseFlattening(final Measure measure) { if (measure.setUnit(Units.UNITY)) { Modified: sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/datum/DefaultEllipsoid.java URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/datum/DefaultEllipsoid.java?rev=1768119&r1=1768118&r2=1768119&view=diff ============================================================================== --- sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/datum/DefaultEllipsoid.java [UTF-8] (original) +++ sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/datum/DefaultEllipsoid.java [UTF-8] Fri Nov 4 22:45:28 2016 @@ -219,12 +219,12 @@ public class DefaultEllipsoid extends Ab * </tr> * </table> * - * @param properties The properties to be given to the identified object. - * @param semiMajorAxis The equatorial radius. - * @param semiMinorAxis The polar radius. - * @param inverseFlattening The inverse of the flattening value. - * @param ivfDefinitive {@code true} if the inverse flattening is definitive. - * @param unit The units of the semi-major and semi-minor axis values. + * @param properties the properties to be given to the identified object. + * @param semiMajorAxis the equatorial radius. + * @param semiMinorAxis the polar radius. + * @param inverseFlattening the inverse of the flattening value. + * @param ivfDefinitive {@code true} if the inverse flattening is definitive. + * @param unit the units of the semi-major and semi-minor axis values. * * @see #createEllipsoid(Map, double, double, Unit) * @see #createFlattenedSphere(Map, double, double, Unit) @@ -255,7 +255,7 @@ public class DefaultEllipsoid extends Ab * * <p>This constructor performs a shallow copy, i.e. the properties are not cloned.</p> * - * @param ellipsoid The ellipsoid to copy. + * @param ellipsoid the ellipsoid to copy. * * @see #castOrCopy(Ellipsoid) */ @@ -273,11 +273,11 @@ public class DefaultEllipsoid extends Ab * The properties map is given unchanged to the * {@linkplain AbstractIdentifiedObject#AbstractIdentifiedObject(Map) super-class constructor}. * - * @param properties The properties to be given to the identified object. - * @param semiMajorAxis The equatorial radius in the given unit. - * @param semiMinorAxis The polar radius in the given unit. - * @param unit The units of the semi-major and semi-minor axis values. - * @return An ellipsoid with the given axis length. + * @param properties the properties to be given to the identified object. + * @param semiMajorAxis the equatorial radius in the given unit. + * @param semiMinorAxis the polar radius in the given unit. + * @param unit the units of the semi-major and semi-minor axis values. + * @return an ellipsoid with the given axis length. * * @see org.apache.sis.referencing.factory.GeodeticObjectFactory#createEllipsoid(Map, double, double, Unit) */ @@ -299,11 +299,11 @@ public class DefaultEllipsoid extends Ab * The properties map is given unchanged to the * {@linkplain AbstractIdentifiedObject#AbstractIdentifiedObject(Map) super-class constructor}. * - * @param properties The properties to be given to the identified object. - * @param semiMajorAxis The equatorial radius in the given unit. - * @param inverseFlattening The inverse flattening value. - * @param unit The units of the semi-major and semi-minor axis values. - * @return An ellipsoid with the given axis length. + * @param properties the properties to be given to the identified object. + * @param semiMajorAxis the equatorial radius in the given unit. + * @param inverseFlattening the inverse flattening value. + * @param unit the units of the semi-major and semi-minor axis values. + * @return an ellipsoid with the given axis length. * * @see org.apache.sis.referencing.factory.GeodeticObjectFactory#createFlattenedSphere(Map, double, double, Unit) */ @@ -327,8 +327,8 @@ public class DefaultEllipsoid extends Ab * Otherwise if the given object is already a SIS implementation, then the given object is returned unchanged. * Otherwise a new SIS implementation is created and initialized to the attribute values of the given object. * - * @param object The object to get as a SIS implementation, or {@code null} if none. - * @return A SIS implementation containing the values of the given object (may be the + * @param object the object to get as a SIS implementation, or {@code null} if none. + * @return a SIS implementation containing the values of the given object (may be the * given object itself), or {@code null} if the argument was null. */ public static DefaultEllipsoid castOrCopy(final Ellipsoid object) { @@ -363,7 +363,7 @@ public class DefaultEllipsoid extends Ab * Returns the linear unit of the {@linkplain #getSemiMajorAxis() semi-major} * and {@linkplain #getSemiMinorAxis() semi-minor} axis values. * - * @return The axis linear unit. + * @return the axis linear unit. */ @Override public Unit<Length> getAxisUnit() { @@ -374,7 +374,7 @@ public class DefaultEllipsoid extends Ab * Length of the semi-major axis of the ellipsoid. * This is the equatorial radius in {@linkplain #getAxisUnit() axis linear unit}. * - * @return Length of semi-major axis. + * @return length of semi-major axis. */ @Override public double getSemiMajorAxis() { @@ -385,7 +385,7 @@ public class DefaultEllipsoid extends Ab * Length of the semi-minor axis of the ellipsoid. This is the * polar radius in {@linkplain #getAxisUnit() axis linear unit}. * - * @return Length of semi-minor axis. + * @return length of semi-minor axis. */ @Override public double getSemiMinorAxis() { @@ -396,7 +396,7 @@ public class DefaultEllipsoid extends Ab * Returns the radius of a hypothetical sphere having the same surface than this ellipsoid. * The radius is expressed in {@linkplain #getAxisUnit() axis linear unit}. * - * @return The radius of a sphere having the same surface than this ellipsoid. + * @return the radius of a sphere having the same surface than this ellipsoid. * * @see org.apache.sis.referencing.CommonCRS#SPHERE */ @@ -489,7 +489,7 @@ public class DefaultEllipsoid extends Ab * For perfect spheres (i.e. if {@link #isSphere()} returns {@code true}), * the {@link Double#POSITIVE_INFINITY} value is used. * - * @return The inverse flattening value. + * @return the inverse flattening value. */ @Override public double getInverseFlattening() { @@ -531,11 +531,11 @@ public class DefaultEllipsoid extends Ab * Orthodromic distances are different than the <cite>loxodromic distance</cite>. * The later is a longer distance on a path with a constant direction on the compass.</div> * - * @param λ1 Longitude of first point (in decimal degrees). - * @param φ1 Latitude of first point (in decimal degrees). - * @param λ2 Longitude of second point (in decimal degrees). - * @param φ2 Latitude of second point (in decimal degrees). - * @return The orthodromic distance (in the units of this ellipsoid's axis). + * @param λ1 longitude of first point (in decimal degrees). + * @param φ1 latitude of first point (in decimal degrees). + * @param λ2 longitude of second point (in decimal degrees). + * @param φ2 latitude of second point (in decimal degrees). + * @return the orthodromic distance (in the units of this ellipsoid's axis). */ public double orthodromicDistance(double λ1, double φ1, double λ2, double φ2) { λ1 = toRadians(λ1); @@ -628,14 +628,14 @@ public class DefaultEllipsoid extends Ab * {@code WGS84.semiMajorAxisDifference(ED50)} returns 251 metres. This information is a parameter of * {@linkplain org.apache.sis.referencing.operation.transform.MolodenskyTransform Molodensky transformations}.</div> * - * @param other The other ellipsoid from which to get semi-major axis length difference. + * @param other the other ellipsoid from which to get semi-major axis length difference. * @return (<var>other</var> ellipsoid semi-major axis) - (<var>this</var> ellipsoid semi-major axis). * * @since 0.7 */ public double semiMajorAxisDifference(final Ellipsoid other) { double semiMajor = other.getSemiMajorAxis(); - semiMajor = other.getAxisUnit().getConverterTo(getAxisUnit()).convert(semiMajor); // Often a no-op. + semiMajor = other.getAxisUnit().getConverterTo(getAxisUnit()).convert(semiMajor); // Often a no-op. final DoubleDouble a = new DoubleDouble(semiMajor); // Presumed accurate in base 10 if no unit conversion. a.subtract(getSemiMajorAxis()); // Presumed accurate in base 10 (not 2) by definition. return a.value; @@ -649,7 +649,7 @@ public class DefaultEllipsoid extends Ab * {@code WGS84.flatteningDifference(ED50)} returns approximatively 1.41927E-05. This information is a parameter of * {@linkplain org.apache.sis.referencing.operation.transform.MolodenskyTransform Molodensky transformations}.</div> * - * @param other The other ellipsoid from which to get flattening difference. + * @param other the other ellipsoid from which to get flattening difference. * @return (<var>other</var> ellipsoid flattening) - (<var>this</var> ellipsoid flattening). * * @since 0.7 @@ -663,10 +663,10 @@ public class DefaultEllipsoid extends Ab /** * Compares this ellipsoid with the specified object for equality. * - * @param object The object to compare to {@code this}. - * @param mode {@link ComparisonMode#STRICT STRICT} for performing a strict comparison, or - * {@link ComparisonMode#IGNORE_METADATA IGNORE_METADATA} for comparing only properties - * relevant to coordinate transformations. + * @param object the object to compare to {@code this}. + * @param mode {@link ComparisonMode#STRICT STRICT} for performing a strict comparison, or + * {@link ComparisonMode#IGNORE_METADATA IGNORE_METADATA} for comparing only + * properties relevant to coordinate transformations. * @return {@code true} if both objects are equal. */ @Override @@ -748,7 +748,7 @@ public class DefaultEllipsoid extends Ab * See {@link org.apache.sis.referencing.AbstractIdentifiedObject#computeHashCode()} * for more information. * - * @return The hash code value. This value may change in any future Apache SIS version. + * @return the hash code value. This value may change in any future Apache SIS version. */ @Override protected long computeHashCode() { @@ -831,6 +831,8 @@ public class DefaultEllipsoid extends Ab } else { if (inverseFlattening == 0) { inverseFlattening = Formulas.getInverseFlattening(semiMajorAxis, semiMinorAxis); + } else if (inverseFlattening == Double.POSITIVE_INFINITY && semiMinorAxis == 0) { + semiMinorAxis = semiMajorAxis; } } if (unit == null) { @@ -885,36 +887,50 @@ public class DefaultEllipsoid extends Ab * @see #afterUnmarshal(Unmarshaller, Object) */ private void setSecondDefiningParameter(SecondDefiningParameter second) { - while (second.secondDefiningParameter != null) { + if (second.secondDefiningParameter != null) { second = second.secondDefiningParameter; } + boolean duplicate = false; + if (Boolean.TRUE.equals(second.isSphere)) { + duplicate = (inverseFlattening != 0); + if (!duplicate) { + inverseFlattening = Double.POSITIVE_INFINITY; + } + } final Measure measure = second.measure; if (measure != null) { final boolean isIvfDefinitive = second.isIvfDefinitive(); - if ((isIvfDefinitive ? inverseFlattening : semiMinorAxis) == 0) { + duplicate |= (isIvfDefinitive ? inverseFlattening : semiMinorAxis) != 0; + if (!duplicate) { ivfDefinitive = isIvfDefinitive; double value = measure.value; if (isIvfDefinitive) { + /* + * Interpreting an inverse flattening factor of 0 as synonymous of infinity + * is a Well-Known Text (WKT) convention, not part of GML standard. However + * in practice some software do that. + */ if (value == 0) { value = Double.POSITIVE_INFINITY; } ensureStrictlyPositive("inverseFlattening", inverseFlattening = value); - } else if (semiMinorAxis == 0) { + } else { ensureStrictlyPositive("semiMinorAxis", semiMinorAxis = value); harmonizeAxisUnits(measure.getUnit(Length.class)); } - } else { - MetadataUtilities.propertyAlreadySet(DefaultEllipsoid.class, - "setSecondDefiningParameter", "secondDefiningParameter"); } } + if (duplicate) { + MetadataUtilities.propertyAlreadySet(DefaultEllipsoid.class, + "setSecondDefiningParameter", "secondDefiningParameter"); + } } /** * Ensures that the semi-minor axis uses the same unit than the semi-major one. * The {@link #unit} field shall be set to the semi-major axis unit before this method call. * - * @param uom The semi-minor axis unit. + * @param uom the semi-minor axis unit. */ private void harmonizeAxisUnits(final Unit<Length> uom) { if (unit == null) { Modified: sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/internal/jaxb/referencing/SecondDefiningParameterTest.java URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/internal/jaxb/referencing/SecondDefiningParameterTest.java?rev=1768119&r1=1768118&r2=1768119&view=diff ============================================================================== --- sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/internal/jaxb/referencing/SecondDefiningParameterTest.java [UTF-8] (original) +++ sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/internal/jaxb/referencing/SecondDefiningParameterTest.java [UTF-8] Fri Nov 4 22:45:28 2016 @@ -36,41 +36,74 @@ import static org.apache.sis.test.Assert */ public final strictfp class SecondDefiningParameterTest extends XMLTestCase { /** - * The XML to be used for testing purpose. + * XML of an ellipsoid defined by semi-major and semi-minor axes. + * The numerical values used for this test is the ones of Clarke 1866 (EPSG:7008). */ - private static final String XML = + private static final String ELLIPSOID = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>\n" + "<gml:SecondDefiningParameter xmlns:gml=\"http://www.opengis.net/gml/3.2\">\n" + - " <gml:semiMinorAxis uom=\"urn:ogc:def:uom:EPSG::9001\">6371000.0</gml:semiMinorAxis>\n" + + " <gml:semiMinorAxis uom=\"urn:ogc:def:uom:EPSG::9001\">6356583.8</gml:semiMinorAxis>\n" + "</gml:SecondDefiningParameter>"; /** - * Generates a XML tree using the annotations on the {@link SecondDefiningParameter} class. + * XML of a sphere. * - * @throws JAXBException If an error occurred during the marshalling process. + * @see <a href="https://issues.apache.org/jira/browse/SIS-333">SIS-333</a> + */ + private static final String SPHERE = + "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>\n" + + "<gml:SecondDefiningParameter xmlns:gml=\"http://www.opengis.net/gml/3.2\">\n" + + " <gml:isSphere>true</gml:isSphere>\n" + + "</gml:SecondDefiningParameter>"; + + /** + * Tests marshalling of an ellipsoid. + * + * @throws JAXBException if an error occurred during the marshalling process. */ @Test public void testMarshalling() throws JAXBException { final DefaultEllipsoid ellipsoid = DefaultEllipsoid.createEllipsoid(Collections.singletonMap( - DefaultEllipsoid.NAME_KEY, "Sphere"), 6371000, 6371000, Units.METRE); + DefaultEllipsoid.NAME_KEY, "Clarke 1866"), 6378206.4, 6356583.8, Units.METRE); final SecondDefiningParameter sdp = new SecondDefiningParameter(ellipsoid, false); - assertXmlEquals( - "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>\n" + - "<gml:SecondDefiningParameter xmlns:gml=\"http://www.opengis.net/gml/3.2\">\n" + - " <gml:semiMinorAxis uom=\"urn:ogc:def:uom:EPSG::9001\">6371000.0</gml:semiMinorAxis>\n" + - "</gml:SecondDefiningParameter>", - marshal(sdp), "xmlns:*", "xsi:schemaLocation"); + assertXmlEquals(ELLIPSOID, marshal(sdp), "xmlns:*", "xsi:schemaLocation"); } /** - * Creates a {@link SecondDefiningParameter} from a XML tree. + * Tests unmarshalling of an ellipsoid. * - * @throws JAXBException If an error occurred during the unmarshalling process. + * @throws JAXBException if an error occurred during the unmarshalling process. */ @Test public void testUnmarshalling() throws JAXBException { - final SecondDefiningParameter sdp = unmarshal(SecondDefiningParameter.class, XML); - assertEquals(6371000.0, sdp.measure.value, 0); - assertEquals(Units.METRE, sdp.measure.unit); + final SecondDefiningParameter sdp = unmarshal(SecondDefiningParameter.class, ELLIPSOID); + assertNull("isSphere", sdp.isSphere); + assertEquals("measure", 6356583.8, sdp.measure.value, STRICT); + assertEquals("measure", Units.METRE, sdp.measure.unit); + } + + /** + * Tests marshalling of a sphere. + * + * @throws JAXBException if an error occurred during the marshalling process. + */ + @Test + public void testMarshallingSphere() throws JAXBException { + final DefaultEllipsoid ellipsoid = DefaultEllipsoid.createEllipsoid(Collections.singletonMap( + DefaultEllipsoid.NAME_KEY, "Sphere"), 6371000, 6371000, Units.METRE); + final SecondDefiningParameter sdp = new SecondDefiningParameter(ellipsoid, false); + assertXmlEquals(SPHERE, marshal(sdp), "xmlns:*", "xsi:schemaLocation"); + } + + /** + * Tests unmarshalling of a sphere. + * + * @throws JAXBException if an error occurred during the unmarshalling process. + */ + @Test + public void testUnmarshallingSphere() throws JAXBException { + final SecondDefiningParameter sdp = unmarshal(SecondDefiningParameter.class, SPHERE); + assertEquals("isSphere", Boolean.TRUE, sdp.isSphere); + assertNull("measure", sdp.measure); } } Modified: sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/referencing/datum/DefaultEllipsoidTest.java URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/referencing/datum/DefaultEllipsoidTest.java?rev=1768119&r1=1768118&r2=1768119&view=diff ============================================================================== --- sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/referencing/datum/DefaultEllipsoidTest.java [UTF-8] (original) +++ sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/referencing/datum/DefaultEllipsoidTest.java [UTF-8] Fri Nov 4 22:45:28 2016 @@ -48,7 +48,12 @@ public final strictfp class DefaultEllip /** * An XML file in this package containing an ellipsoid definition. */ - private static final String XML_FILE = "Ellipsoid.xml"; + private static final String ELLIPSOID_FILE = "Ellipsoid.xml"; + + /** + * An XML file in this package containing a sphere definition. + */ + private static final String SPHERE_FILE = "Sphere.xml"; /** * Half of a minute of angle, in degrees. @@ -209,23 +214,50 @@ public final strictfp class DefaultEllip } /** - * Tests unmarshalling and marshalling. + * Tests unmarshalling and marshalling of an ellipsoid. * - * @throws JAXBException If an error occurred during (un)marshalling. + * @throws JAXBException if an error occurred during (un)marshalling. */ @Test - public void testXML() throws JAXBException { - final DefaultEllipsoid ellipsoid = unmarshalFile(DefaultEllipsoid.class, XML_FILE); + public void testEllipsoidXML() throws JAXBException { + final DefaultEllipsoid ellipsoid = unmarshalFile(DefaultEllipsoid.class, ELLIPSOID_FILE); assertEquals("name", "Clarke 1880 (international foot)", ellipsoid.getName().getCode()); assertEquals("remarks", "Definition in feet assumed to be international foot.", ellipsoid.getRemarks().toString()); + assertFalse ("isSphere", ellipsoid.isSphere()); assertFalse ("isIvfDefinitive", ellipsoid.isIvfDefinitive()); - assertEquals("semiMajorAxis", 20926202, ellipsoid.getSemiMajorAxis(), 0); - assertEquals("semiMinorAxis", 20854895, ellipsoid.getSemiMinorAxis(), 0); + assertEquals("semiMajorAxis", 20926202, ellipsoid.getSemiMajorAxis(), STRICT); + assertEquals("semiMinorAxis", 20854895, ellipsoid.getSemiMinorAxis(), STRICT); assertEquals("inverseFlattening", 293.46630765562986, ellipsoid.getInverseFlattening(), 1E-12); assertEquals("axisUnit", Units.FOOT, ellipsoid.getAxisUnit()); /* * Marshall and compare to the original file. */ - assertMarshalEqualsFile(XML_FILE, ellipsoid, "xlmns:*", "xsi:schemaLocation"); + assertMarshalEqualsFile(ELLIPSOID_FILE, ellipsoid, "xlmns:*", "xsi:schemaLocation"); + } + + /** + * Tests unmarshalling and marshalling of a sphere. + * + * @throws JAXBException if an error occurred during (un)marshalling. + * + * @see <a href="https://issues.apache.org/jira/browse/SIS-333">SIS-333</a> + * + * @since 0.8 + */ + @Test + public void testSphereXML() throws JAXBException { + final DefaultEllipsoid ellipsoid = unmarshalFile(DefaultEllipsoid.class, SPHERE_FILE); + assertEquals("name", "GRS 1980 Authalic Sphere", ellipsoid.getName().getCode()); + assertEquals("remarks", "Authalic sphere derived from GRS 1980 ellipsoid (code 7019).", ellipsoid.getRemarks().toString()); + assertTrue ("isSphere", ellipsoid.isSphere()); + assertFalse ("isIvfDefinitive", ellipsoid.isIvfDefinitive()); + assertEquals("semiMajorAxis", 6371007, ellipsoid.getSemiMajorAxis(), STRICT); + assertEquals("semiMinorAxis", 6371007, ellipsoid.getSemiMinorAxis(), STRICT); + assertEquals("inverseFlattening", Double.POSITIVE_INFINITY, ellipsoid.getInverseFlattening(), STRICT); + assertEquals("axisUnit", Units.METRE, ellipsoid.getAxisUnit()); + /* + * Marshall and compare to the original file. + */ + assertMarshalEqualsFile(SPHERE_FILE, ellipsoid, "xlmns:*", "xsi:schemaLocation"); } } Copied: sis/branches/JDK8/core/sis-referencing/src/test/resources/org/apache/sis/referencing/datum/Sphere.xml (from r1768094, sis/branches/JDK8/core/sis-referencing/src/test/resources/org/apache/sis/referencing/datum/Ellipsoid.xml) URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-referencing/src/test/resources/org/apache/sis/referencing/datum/Sphere.xml?p2=sis/branches/JDK8/core/sis-referencing/src/test/resources/org/apache/sis/referencing/datum/Sphere.xml&p1=sis/branches/JDK8/core/sis-referencing/src/test/resources/org/apache/sis/referencing/datum/Ellipsoid.xml&r1=1768094&r2=1768119&rev=1768119&view=diff ============================================================================== --- sis/branches/JDK8/core/sis-referencing/src/test/resources/org/apache/sis/referencing/datum/Ellipsoid.xml (original) +++ sis/branches/JDK8/core/sis-referencing/src/test/resources/org/apache/sis/referencing/datum/Sphere.xml Fri Nov 4 22:45:28 2016 @@ -21,15 +21,15 @@ <gml:Ellipsoid xsi:schemaLocation = "http://www.opengis.net/gml/3.2 http://schemas.opengis.net/gml/3.2.1/datums.xsd" xmlns:gml = "http://www.opengis.net/gml/3.2" xmlns:xsi = "http://www.w3.org/2001/XMLSchema-instance" - gml:id = "epsg-ellipsoid-7055"> + gml:id = "epsg-ellipsoid-7048"> - <gml:identifier codeSpace="IOGP">urn:ogc:def:ellipsoid:EPSG::7055</gml:identifier> - <gml:name>Clarke 1880 (international foot)</gml:name> - <gml:remarks>Definition in feet assumed to be international foot.</gml:remarks> - <gml:semiMajorAxis uom="urn:ogc:def:uom:EPSG::9002">20926202</gml:semiMajorAxis> + <gml:identifier codeSpace="IOGP">urn:ogc:def:ellipsoid:EPSG::7048</gml:identifier> + <gml:name>GRS 1980 Authalic Sphere</gml:name> + <gml:remarks>Authalic sphere derived from GRS 1980 ellipsoid (code 7019).</gml:remarks> + <gml:semiMajorAxis uom="urn:ogc:def:uom:EPSG::9001">6371007</gml:semiMajorAxis> <gml:secondDefiningParameter> <gml:SecondDefiningParameter> - <gml:semiMinorAxis uom="urn:ogc:def:uom:EPSG::9002">20854895</gml:semiMinorAxis> + <gml:isSphere>true</gml:isSphere> </gml:SecondDefiningParameter> </gml:secondDefiningParameter> </gml:Ellipsoid>