sis-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From desruisse...@apache.org
Subject svn commit: r1649769 - in /sis/branches/JDK8/core/sis-referencing/src: main/java/org/apache/sis/internal/referencing/ReferencingUtilities.java test/java/org/apache/sis/internal/referencing/ReferencingUtilitiesTest.java
Date Tue, 06 Jan 2015 10:19:44 GMT
Author: desruisseaux
Date: Tue Jan  6 10:19:44 2015
New Revision: 1649769

URL: http://svn.apache.org/r1649769
Log:
Added tests for toNormalizedGeographicCRS(CoordinateReferenceSystem).

Modified:
    sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/internal/referencing/ReferencingUtilities.java
    sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/internal/referencing/ReferencingUtilitiesTest.java

Modified: sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/internal/referencing/ReferencingUtilities.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/internal/referencing/ReferencingUtilities.java?rev=1649769&r1=1649768&r2=1649769&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/internal/referencing/ReferencingUtilities.java
[UTF-8] (original)
+++ sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/internal/referencing/ReferencingUtilities.java
[UTF-8] Tue Jan  6 10:19:44 2015
@@ -29,6 +29,7 @@ import org.apache.sis.util.Static;
 import org.apache.sis.util.Utilities;
 import org.apache.sis.util.logging.Logging;
 import org.apache.sis.util.resources.Errors;
+import org.apache.sis.util.resources.Vocabulary;
 import org.apache.sis.internal.jaxb.Context;
 import org.apache.sis.referencing.CommonCRS;
 import org.apache.sis.referencing.datum.DefaultPrimeMeridian;
@@ -188,14 +189,15 @@ public final class ReferencingUtilities
             /*
              * At this point we usually have a GeographicCRS, but it could also be a GeocentricCRS.
              */
-            if (crs instanceof DefaultGeographicCRS) {
+            if (crs instanceof DefaultGeographicCRS && crs.getCoordinateSystem().getDimension()
== 2) {
                 return ((DefaultGeographicCRS) crs).forConvention(AxesConvention.NORMALIZED);
             }
             final CoordinateSystem cs = CommonCRS.defaultGeographic().getCoordinateSystem();
             if (crs instanceof GeographicCRS && Utilities.equalsIgnoreMetadata(cs,
crs.getCoordinateSystem())) {
                 return (GeographicCRS) crs;
             }
-            return new DefaultGeographicCRS(singletonMap(DefaultGeographicCRS.NAME_KEY, crs.getName().getCode()),
+            return new DefaultGeographicCRS(
+                    singletonMap(DefaultGeographicCRS.NAME_KEY, Vocabulary.format(Vocabulary.Keys.Unnamed)),
                     ((GeodeticCRS) crs).getDatum(), (EllipsoidalCS) cs);
         }
         if (crs instanceof CompoundCRS) {

Modified: sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/internal/referencing/ReferencingUtilitiesTest.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/internal/referencing/ReferencingUtilitiesTest.java?rev=1649769&r1=1649768&r2=1649769&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/internal/referencing/ReferencingUtilitiesTest.java
[UTF-8] (original)
+++ sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/internal/referencing/ReferencingUtilitiesTest.java
[UTF-8] Tue Jan  6 10:19:44 2015
@@ -19,9 +19,13 @@ package org.apache.sis.internal.referenc
 import javax.measure.unit.Unit;
 import javax.measure.unit.NonSI;
 import org.opengis.referencing.cs.*;
+import org.opengis.referencing.crs.CoordinateReferenceSystem;
+import org.opengis.referencing.crs.GeographicCRS;
 import org.opengis.referencing.datum.PrimeMeridian;
 import org.apache.sis.referencing.datum.DefaultPrimeMeridian;
 import org.apache.sis.referencing.datum.HardCodedDatum;
+import org.apache.sis.referencing.crs.HardCodedCRS;
+import org.apache.sis.util.Utilities;
 import org.apache.sis.test.TestCase;
 import org.junit.Test;
 
@@ -75,6 +79,33 @@ public final strictfp class ReferencingU
     }
 
     /**
+     * Asserts that normalization of the given CRS produces {@link HardCodedCRS#WGS84} (ignoring
metadata).
+     *
+     * @param message The message to show in case of failure.
+     * @param createExpected {@code true} if we expect normalization to create a new CRS
object.
+     * @param crs The CRS for which to test normalization.
+     */
+    private static void assertNormalizedEqualsWGS84(final String message, final boolean createExpected,
+            final CoordinateReferenceSystem crs)
+    {
+        final GeographicCRS normalizedCRS = toNormalizedGeographicCRS(crs);
+        assertTrue(message, Utilities.equalsIgnoreMetadata(HardCodedCRS.WGS84, normalizedCRS));
+        assertEquals("New CRS instance expected:", createExpected, normalizedCRS != HardCodedCRS.WGS84);
+    }
+
+    /**
+     * Tests {@link ReferencingUtilities#toNormalizedGeographicCRS(CoordinateReferenceSystem)}.
+     */
+    @Test
+    public void testToNormalizedGeographicCRS() {
+        assertNormalizedEqualsWGS84("Expected identity operation.",    false, HardCodedCRS.WGS84);
+        assertNormalizedEqualsWGS84("Shall extract the 2D component.", false, HardCodedCRS.GEOID_3D);
+        assertNormalizedEqualsWGS84("Shall extract the 2D component.", false, HardCodedCRS.GEOID_4D);
+        assertNormalizedEqualsWGS84("Shall build a the 2D component.", true,  HardCodedCRS.WGS84_3D);
+        assertNormalizedEqualsWGS84("Shall normalize axis order.",     true,  HardCodedCRS.WGS84_φλ);
+    }
+
+    /**
      * Tests {@link ReferencingUtilities#toWKTType(Class, Class)}.
      */
     @Test



Mime
View raw message