sis-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From desruisse...@apache.org
Subject svn commit: r1627358 - in /sis/branches/JDK8/core/sis-referencing/src: main/java/org/apache/sis/internal/jaxb/referencing/ main/java/org/apache/sis/internal/referencing/ main/java/org/apache/sis/referencing/ main/java/org/apache/sis/referencing/crs/ te...
Date Wed, 24 Sep 2014 16:18:48 GMT
Author: desruisseaux
Date: Wed Sep 24 16:18:48 2014
New Revision: 1627358

URL: http://svn.apache.org/r1627358
Log:
Normalized version of EPSG:4326 should have the "CRS:84" identifier.

Added:
    sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/internal/referencing/HardCoded.java
  (with props)
Modified:
    sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/internal/jaxb/referencing/CS_AxisDirection.java
    sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/internal/jaxb/referencing/CS_RangeMeaning.java
    sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/CRS.java
    sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/CommonCRS.java
    sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/crs/DefaultGeographicCRS.java
    sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/referencing/CRSTest.java
    sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/referencing/CommonCRSTest.java
    sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/referencing/crs/DefaultGeographicCRSTest.java

Modified: sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/internal/jaxb/referencing/CS_AxisDirection.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/internal/jaxb/referencing/CS_AxisDirection.java?rev=1627358&r1=1627357&r2=1627358&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/internal/jaxb/referencing/CS_AxisDirection.java
[UTF-8] (original)
+++ sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/internal/jaxb/referencing/CS_AxisDirection.java
[UTF-8] Wed Sep 24 16:18:48 2014
@@ -19,6 +19,8 @@ package org.apache.sis.internal.jaxb.ref
 import org.opengis.referencing.cs.AxisDirection;
 import org.apache.sis.internal.jaxb.gml.CodeListAdapter;
 
+import static org.apache.sis.internal.referencing.HardCoded.EPSG;
+
 
 /**
  * JAXB adapter for (un)marshalling of GeoAPI code list.
@@ -52,6 +54,6 @@ public final class CS_AxisDirection exte
      */
     @Override
     protected String getCodeSpace() {
-        return "EPSG";
+        return EPSG;
     }
 }

Modified: sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/internal/jaxb/referencing/CS_RangeMeaning.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/internal/jaxb/referencing/CS_RangeMeaning.java?rev=1627358&r1=1627357&r2=1627358&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/internal/jaxb/referencing/CS_RangeMeaning.java
[UTF-8] (original)
+++ sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/internal/jaxb/referencing/CS_RangeMeaning.java
[UTF-8] Wed Sep 24 16:18:48 2014
@@ -19,6 +19,8 @@ package org.apache.sis.internal.jaxb.ref
 import org.opengis.referencing.cs.RangeMeaning;
 import org.apache.sis.internal.jaxb.gml.CodeListAdapter;
 
+import static org.apache.sis.internal.referencing.HardCoded.EPSG;
+
 
 /**
  * JAXB adapter for (un)marshalling of GeoAPI code list.
@@ -52,6 +54,6 @@ public final class CS_RangeMeaning exten
      */
     @Override
     protected String getCodeSpace() {
-        return "EPSG";
+        return EPSG;
     }
 }

Added: sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/internal/referencing/HardCoded.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/internal/referencing/HardCoded.java?rev=1627358&view=auto
==============================================================================
--- sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/internal/referencing/HardCoded.java
(added)
+++ sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/internal/referencing/HardCoded.java
[UTF-8] Wed Sep 24 16:18:48 2014
@@ -0,0 +1,61 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.sis.internal.referencing;
+
+import org.apache.sis.util.Static;
+
+
+/**
+ * Hard coded values (typically identifiers).
+ *
+ * @author  Martin Desruisseaux (Geomatys)
+ * @since   0.5
+ * @version 0.5
+ * @module
+ */
+public final class HardCoded extends Static {
+    /**
+     * The {@value} code space.
+     */
+    public static final String EPSG = "EPSG";
+
+    /**
+     * The {@value} code space.
+     */
+    public static final String CRS = "CRS";
+
+    /**
+     * The {@code CRS:27} identifier for a coordinate reference system.
+     */
+    public static final byte CRS27 = 27;
+
+    /**
+     * The {@code CRS:83} identifier for a coordinate reference system.
+     */
+    public static final byte CRS83 = 83;
+
+    /**
+     * The {@code CRS:84} identifier for a coordinate reference system.
+     */
+    public static final byte CRS84 = 84;
+
+    /**
+     * Do not allow instantiation of this class.
+     */
+    private HardCoded() {
+    }
+}

Propchange: sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/internal/referencing/HardCoded.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/internal/referencing/HardCoded.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain;charset=UTF-8

Modified: sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/CRS.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/CRS.java?rev=1627358&r1=1627357&r2=1627358&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/CRS.java
[UTF-8] (original)
+++ sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/CRS.java
[UTF-8] Wed Sep 24 16:18:48 2014
@@ -47,6 +47,7 @@ import org.apache.sis.referencing.crs.De
 import org.apache.sis.referencing.crs.DefaultCompoundCRS;
 import org.apache.sis.metadata.iso.extent.Extents;
 import org.apache.sis.util.resources.Errors;
+import org.apache.sis.util.logging.Logging;
 import org.apache.sis.util.CharSequences;
 import org.apache.sis.util.Utilities;
 import org.apache.sis.util.Static;
@@ -79,7 +80,7 @@ import static org.apache.sis.util.Argume
  *
  * @author  Martin Desruisseaux (IRD, Geomatys)
  * @since   0.3 (derived from geotk-2.1)
- * @version 0.4
+ * @version 0.5
  * @module
  */
 public final class CRS extends Static {
@@ -156,42 +157,21 @@ public final class CRS extends Static {
             throw new NoSuchIdentifierException(Errors.format(Errors.Keys.MissingAuthority_1,
code), code);
         }
         /*
-         * Code below this point is a temporary implementation to
-         * be removed after we ported the EPSG authority factory.
+         * Delegate to the factory for the code space of the given code. If no authority
factory
+         * is available, or if the factory failed to create the CRS, delegate to CommonCRS.
Note
+         * that CommonCRS is not expected to succeed if the real EPSG factory threw an exception,
+         * so we will log a message at the warning level in such case.
          */
-        NumberFormatException cause = null;
-        try {
-            if (authority.equalsIgnoreCase("CRS")) {
-                switch (Integer.parseInt(value)) {
-                    case 27: return CommonCRS.NAD27.normalizedGeographic();
-                    case 83: return CommonCRS.NAD83.normalizedGeographic();
-                    case 84: return CommonCRS.WGS84.normalizedGeographic();
-                }
-            } else if (authority.equalsIgnoreCase("EPSG")) {
-                final int n = Integer.parseInt(value);
-                if (n != 0) { // CommonCRS uses 0 as a sentinel value for "no EPSG code".
-                    for (final CommonCRS candidate : CommonCRS.values()) {
-                        if (candidate.geographic == n) return candidate.geographic();
-                        if (candidate.geocentric == n) return candidate.geocentric();
-                        if (candidate.geo3D      == n) return candidate.geographic3D();
-                    }
-                    for (final CommonCRS.Vertical candidate : CommonCRS.Vertical.values())
{
-                        if (candidate.isEPSG && candidate.crs == n) {
-                            return candidate.crs();
-                        }
-                    }
-                }
-            } else {
-                throw new NoSuchIdentifierException(Errors.format(Errors.Keys.UnknownAuthority_1,
authority), authority);
-            }
-        } catch (NumberFormatException e) {
-            cause = e;
+        CRSAuthorityFactory factory = null; // TODO
+        if (factory != null) try {
+            return factory.createCoordinateReferenceSystem(value);
+        } catch (FactoryException failure) {
+            final CoordinateReferenceSystem crs = CommonCRS.forCode(authority, value, failure);
+            Logging.unexpectedException(CRS.class, "forCode", failure); // See above comment.
+            return crs;
+        } else {
+            return CommonCRS.forCode(authority, value, null);
         }
-        final NoSuchAuthorityCodeException e = new NoSuchAuthorityCodeException(
-                Errors.format(Errors.Keys.NoSuchAuthorityCode_3, authority, CoordinateReferenceSystem.class,
value),
-                authority, value, code);
-        e.initCause(cause);
-        throw e;
     }
 
     /**

Modified: sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/CommonCRS.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/CommonCRS.java?rev=1627358&r1=1627357&r2=1627358&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/CommonCRS.java
[UTF-8] (original)
+++ sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/CommonCRS.java
[UTF-8] Wed Sep 24 16:18:48 2014
@@ -24,12 +24,15 @@ import javax.measure.unit.Unit;
 import javax.measure.quantity.Duration;
 import org.opengis.util.FactoryException;
 import org.opengis.util.InternationalString;
+import org.opengis.util.NoSuchIdentifierException;
+import org.opengis.referencing.NoSuchAuthorityCodeException;
 import org.opengis.referencing.IdentifiedObject;
 import org.opengis.referencing.crs.GeodeticCRS;
 import org.opengis.referencing.crs.VerticalCRS;
 import org.opengis.referencing.crs.TemporalCRS;
 import org.opengis.referencing.crs.GeographicCRS;
 import org.opengis.referencing.crs.GeocentricCRS;
+import org.opengis.referencing.crs.CoordinateReferenceSystem;
 import org.opengis.referencing.cs.TimeCS;
 import org.opengis.referencing.cs.VerticalCS;
 import org.opengis.referencing.cs.CartesianCS;
@@ -56,11 +59,17 @@ import org.apache.sis.referencing.crs.De
 import org.apache.sis.internal.system.SystemListener;
 import org.apache.sis.internal.system.Modules;
 import org.apache.sis.util.resources.Vocabulary;
+import org.apache.sis.util.resources.Errors;
 import org.apache.sis.util.logging.Logging;
 import org.apache.sis.measure.Units;
 
 import static java.util.Collections.singletonMap;
 import static org.opengis.referencing.IdentifiedObject.NAME_KEY;
+import static org.apache.sis.internal.referencing.HardCoded.CRS;
+import static org.apache.sis.internal.referencing.HardCoded.EPSG;
+import static org.apache.sis.internal.referencing.HardCoded.CRS27;
+import static org.apache.sis.internal.referencing.HardCoded.CRS83;
+import static org.apache.sis.internal.referencing.HardCoded.CRS84;
 
 
 /**
@@ -105,7 +114,7 @@ import static org.opengis.referencing.Id
  *
  * @author  Martin Desruisseaux (Geomatys)
  * @since   0.4
- * @version 0.4
+ * @version 0.5
  * @module
  */
 public enum CommonCRS {
@@ -1338,4 +1347,60 @@ public enum CommonCRS {
     static void failure(final Object caller, final String method, final FactoryException
e) {
         Logging.unexpectedException(caller.getClass(), method, e);
     }
+
+    /**
+     * Returns a coordinate reference system for the given authority code.
+     * This method is invoked as a fallback when {@link CRS#forCode(String)}
+     * can not create a CRS for a given code.
+     *
+     * @param authority The authority, either {@code "CRS"} or {@code "EPSG"} (case-insensitive).
+     * @param code      The code, to be parsed as an integer.
+     * @param failure   The exception to throw in case of failure, or {@code null} for creating
our own.
+     *                  A non-null value is provided when a real EPSG factory exists but
failed to create the CRS.
+     *                  In such case, we want to report the error from the real factory instead
than from this fallback.
+     *
+     * @since 0.5
+     */
+    static CoordinateReferenceSystem forCode(final String authority, final String code, final
FactoryException failure)
+            throws FactoryException
+    {
+        NumberFormatException cause = null;
+        try {
+            if (authority.equalsIgnoreCase(CRS)) {
+                switch (Integer.parseInt(code)) {
+                    case CRS27: return CommonCRS.NAD27.normalizedGeographic();
+                    case CRS83: return CommonCRS.NAD83.normalizedGeographic();
+                    case CRS84: return CommonCRS.WGS84.normalizedGeographic();
+                }
+            } else if (authority.equalsIgnoreCase(EPSG)) {
+                final int n = Integer.parseInt(code);
+                if (n != 0) { // CommonCRS uses 0 as a sentinel value for "no EPSG code".
+                    for (final CommonCRS candidate : CommonCRS.values()) {
+                        if (candidate.geographic == n) return candidate.geographic();
+                        if (candidate.geocentric == n) return candidate.geocentric();
+                        if (candidate.geo3D      == n) return candidate.geographic3D();
+                    }
+                    for (final CommonCRS.Vertical candidate : CommonCRS.Vertical.values())
{
+                        if (candidate.isEPSG && candidate.crs == n) {
+                            return candidate.crs();
+                        }
+                    }
+                }
+            } else if (failure != null) {
+                throw failure;
+            } else {
+                throw new NoSuchIdentifierException(Errors.format(Errors.Keys.UnknownAuthority_1,
authority), authority);
+            }
+        } catch (NumberFormatException e) {
+            cause = e;
+        }
+        if (failure != null) {
+            throw failure;
+        }
+        final NoSuchAuthorityCodeException e = new NoSuchAuthorityCodeException(
+                Errors.format(Errors.Keys.NoSuchAuthorityCode_3, authority, CoordinateReferenceSystem.class,
code),
+                authority, code, code);
+        e.initCause(cause);
+        throw e;
+    }
 }

Modified: sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/crs/DefaultGeographicCRS.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/crs/DefaultGeographicCRS.java?rev=1627358&r1=1627357&r2=1627358&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/crs/DefaultGeographicCRS.java
[UTF-8] (original)
+++ sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/crs/DefaultGeographicCRS.java
[UTF-8] Wed Sep 24 16:18:48 2014
@@ -17,15 +17,28 @@
 package org.apache.sis.referencing.crs;
 
 import java.util.Map;
+import java.util.HashMap;
+import java.util.Arrays;
 import javax.xml.bind.annotation.XmlTransient;
-import org.opengis.referencing.cs.CoordinateSystem;
-import org.opengis.referencing.cs.EllipsoidalCS;
+import org.apache.sis.metadata.iso.citation.Citations;
+import org.apache.sis.metadata.iso.ImmutableIdentifier;
+import org.opengis.referencing.ReferenceIdentifier;
 import org.opengis.referencing.datum.GeodeticDatum;
 import org.opengis.referencing.crs.GeographicCRS;
+import org.opengis.referencing.cs.EllipsoidalCS;
+import org.opengis.referencing.cs.CoordinateSystem;
+import org.opengis.referencing.cs.CoordinateSystemAxis;
 import org.apache.sis.referencing.cs.AxesConvention;
 import org.apache.sis.referencing.AbstractReferenceSystem;
 import org.apache.sis.io.wkt.Formatter;
 
+import org.apache.sis.measure.Longitude;
+import static org.apache.sis.internal.referencing.HardCoded.CRS;
+import static org.apache.sis.internal.referencing.HardCoded.EPSG;
+import static org.apache.sis.internal.referencing.HardCoded.CRS27;
+import static org.apache.sis.internal.referencing.HardCoded.CRS83;
+import static org.apache.sis.internal.referencing.HardCoded.CRS84;
+
 
 /**
  * A coordinate reference system based on an ellipsoidal approximation of the geoid.
@@ -43,12 +56,22 @@ import org.apache.sis.io.wkt.Formatter;
  *
  * @author  Martin Desruisseaux (IRD, Geomatys)
  * @since   0.4 (derived from geotk-1.2)
- * @version 0.4
+ * @version 0.5
  * @module
  */
 @XmlTransient
 public class DefaultGeographicCRS extends DefaultGeodeticCRS implements GeographicCRS {
     /**
+     * Some codes in the EPSG namespace, in ascending order.
+     */
+    private static final short[] EPSG_CODES = {4267, 4269, 4326};
+
+    /**
+     * Codes in the CRS namespace for each code listed in the {@link #EPSG} list.
+     */
+    private static final byte[] CRS_CODES = {CRS27, CRS83, CRS84};
+
+    /**
      * Serial number for inter-operability with different versions.
      */
     private static final long serialVersionUID = 861224913438092335L;
@@ -196,9 +219,32 @@ public class DefaultGeographicCRS extend
 
     /**
      * Returns a coordinate reference system of the same type than this CRS but with different
axes.
+     *
+     * {@section Special case}
+     * If the first axis is the longitude in the [-180 … +180]° range and the identifier
is EPSG:4267,
+     * EPSG:4269 or EPSG:4326, then this method magically add the CRS:27, CRS:83 or CRS:84
identifier.
+     * Without this special case, the normal behavior would be no identifier. The expected
behavior is
+     * that {@code CommonCRS.WGS84.normalizedGeographic()} returns a CRS having the "CRS:84"
identifier.
      */
     @Override
-    final AbstractCRS createSameType(final Map<String,?> properties, final CoordinateSystem
cs) {
+    final AbstractCRS createSameType(Map<String,?> properties, final CoordinateSystem
cs) {
+        final CoordinateSystemAxis axis = cs.getAxis(0);
+        if (axis.getMinimumValue() == Longitude.MIN_VALUE &&
+            axis.getMaximumValue() == Longitude.MAX_VALUE) // For excluding the AxesConvention.POSITIVE_RANGE
case.
+        {
+            for (final ReferenceIdentifier identifier : super.getIdentifiers()) {
+                if (EPSG.equals(identifier.getCodeSpace())) try {
+                    final int i = Arrays.binarySearch(EPSG_CODES, Short.parseShort(identifier.getCode()));
+                    if (i >= 0) {
+                        final Map<String,Object> c = new HashMap<>(properties);
+                        c.put(IDENTIFIERS_KEY, new ImmutableIdentifier(Citations.OGC, CRS,
Short.toString(CRS_CODES[i])));
+                        properties = c;
+                    }
+                } catch (NumberFormatException e) {
+                    // Okay to igore, because it is not the purpose of this method to disallow
non-numeric codes.
+                }
+            }
+        }
         return new DefaultGeographicCRS(properties, super.getDatum(), (EllipsoidalCS) cs);
     }
 

Modified: sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/referencing/CRSTest.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/referencing/CRSTest.java?rev=1627358&r1=1627357&r2=1627358&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/referencing/CRSTest.java
[UTF-8] (original)
+++ sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/referencing/CRSTest.java
[UTF-8] Wed Sep 24 16:18:48 2014
@@ -51,6 +51,8 @@ public final strictfp class CRSTest exte
      * Tests {@link CRS#forCode(String)} with EPSG codes.
      *
      * @throws FactoryException If a CRS can not be constructed.
+     *
+     * @see CommonCRSTest#testForCode()
      */
     @Test
     public void testForEpsgCode() throws FactoryException {
@@ -77,6 +79,8 @@ public final strictfp class CRSTest exte
      * Tests {@link CRS#forCode(String)} with CRS codes.
      *
      * @throws FactoryException If a CRS can not be constructed.
+     *
+     * @see CommonCRSTest#testForCode()
      */
     @Test
     @DependsOnMethod("testForEpsgCode")

Modified: sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/referencing/CommonCRSTest.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/referencing/CommonCRSTest.java?rev=1627358&r1=1627357&r2=1627358&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/referencing/CommonCRSTest.java
[UTF-8] (original)
+++ sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/referencing/CommonCRSTest.java
[UTF-8] Wed Sep 24 16:18:48 2014
@@ -18,6 +18,8 @@ package org.apache.sis.referencing;
 
 import java.util.Date;
 import org.opengis.test.Validators;
+import org.opengis.util.FactoryException;
+import org.opengis.referencing.crs.SingleCRS;
 import org.opengis.referencing.crs.TemporalCRS;
 import org.opengis.referencing.crs.VerticalCRS;
 import org.opengis.referencing.crs.GeographicCRS;
@@ -43,7 +45,7 @@ import static org.apache.sis.test.TestUt
  *
  * @author  Martin Desruisseaux (IRD, Geomatys)
  * @since   0.4 (derived from geotk-2.2)
- * @version 0.4
+ * @version 0.5
  * @module
  */
 @DependsOn({
@@ -196,4 +198,43 @@ public final strictfp class CommonCRSTes
             assertEquals(name, days, origin.getTime() / DAY_LENGTH - julianEpoch, 0);
         }
     }
+
+    /**
+     * Tests {@link CommonCRS#forCode(String, String, FactoryException)}.
+     *
+     * @throws FactoryException If a CRS can not be constructed.
+     *
+     * @see CRSTest#testForEpsgCode()
+     * @see CRSTest#testForCrsCode()
+     *
+     * @since 0.5
+     */
+    @Test
+    public void testForCode() throws FactoryException {
+        verifyForCode(CommonCRS.WGS84 .geographic(),            "EPSG", "4326");
+        verifyForCode(CommonCRS.WGS72 .geographic(),            "EPSG", "4322");
+        verifyForCode(CommonCRS.SPHERE.geographic(),            "EPSG", "4047");
+        verifyForCode(CommonCRS.NAD83 .geographic(),            "EPSG", "4269");
+        verifyForCode(CommonCRS.NAD27 .geographic(),            "EPSG", "4267");
+        verifyForCode(CommonCRS.ETRS89.geographic(),            "EPSG", "4258");
+        verifyForCode(CommonCRS.ED50  .geographic(),            "EPSG", "4230");
+        verifyForCode(CommonCRS.WGS84 .geocentric(),            "EPSG", "4978");
+        verifyForCode(CommonCRS.WGS72 .geocentric(),            "EPSG", "4984");
+        verifyForCode(CommonCRS.ETRS89.geocentric(),            "EPSG", "4936");
+        verifyForCode(CommonCRS.WGS84 .geographic3D(),          "EPSG", "4979");
+        verifyForCode(CommonCRS.WGS72 .geographic3D(),          "EPSG", "4985");
+        verifyForCode(CommonCRS.ETRS89.geographic3D(),          "EPSG", "4937");
+        verifyForCode(CommonCRS.Vertical.MEAN_SEA_LEVEL.crs(),  "EPSG", "5714");
+        verifyForCode(CommonCRS.Vertical.DEPTH.crs(),           "EPSG", "5715");
+        verifyForCode(CommonCRS.WGS84.normalizedGeographic(),   "CRS",  "84");
+        verifyForCode(CommonCRS.NAD83.normalizedGeographic(),   "CRS",  "83");
+        verifyForCode(CommonCRS.NAD27.normalizedGeographic(),   "CRS",  "27");
+    }
+
+    /**
+     * Asserts that the result of {@link CommonCRS#forCode(String, String, FactoryException)}
is the given CRS.
+     */
+    private static void verifyForCode(final SingleCRS expected, final String authority, final
String code) throws FactoryException {
+        assertSame(code, expected, CommonCRS.forCode(authority, code, null));
+    }
 }

Modified: sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/referencing/crs/DefaultGeographicCRSTest.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/referencing/crs/DefaultGeographicCRSTest.java?rev=1627358&r1=1627357&r2=1627358&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/referencing/crs/DefaultGeographicCRSTest.java
[UTF-8] (original)
+++ sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/referencing/crs/DefaultGeographicCRSTest.java
[UTF-8] Wed Sep 24 16:18:48 2014
@@ -19,6 +19,8 @@ package org.apache.sis.referencing.crs;
 import org.opengis.test.Validators;
 import org.opengis.referencing.cs.EllipsoidalCS;
 import org.opengis.referencing.cs.CoordinateSystemAxis;
+import org.opengis.referencing.crs.GeographicCRS;
+import org.opengis.referencing.ReferenceIdentifier;
 import org.apache.sis.referencing.cs.AxesConvention;
 import org.apache.sis.referencing.CommonCRS;
 import org.apache.sis.io.wkt.Convention;
@@ -28,6 +30,7 @@ import org.apache.sis.test.TestCase;
 import org.junit.Test;
 
 import static org.apache.sis.test.MetadataAssert.*;
+import static org.apache.sis.test.TestUtilities.getSingleton;
 
 
 /**
@@ -87,6 +90,51 @@ public final strictfp class DefaultGeogr
     }
 
     /**
+     * Verifies the {@link CommonCRS#WGS84} identifiers in both normalized and unnormalized
CRS.
+     * The intend is actually to test the replacement of {@code "EPSG:4326"} by {@code "CRS:84"}.
+     */
+    @Test
+    public void testIdentifiers() {
+        GeographicCRS crs = CommonCRS.WGS72.geographic();
+        ReferenceIdentifier identifier = getSingleton(crs.getIdentifiers());
+        assertEquals("codespace", "EPSG", identifier.getCodeSpace());
+        assertEquals("code",      "4322", identifier.getCode());
+
+        crs = CommonCRS.WGS72.normalizedGeographic();
+        assertTrue(crs.getIdentifiers().isEmpty());
+
+        crs = CommonCRS.WGS84.geographic();
+        identifier = getSingleton(crs.getIdentifiers());
+        assertEquals("codespace", "EPSG", identifier.getCodeSpace());
+        assertEquals("code",      "4326", identifier.getCode());
+
+        crs = CommonCRS.WGS84.normalizedGeographic();
+        identifier = getSingleton(crs.getIdentifiers());
+        assertEquals("codespace", "CRS", identifier.getCodeSpace());
+        assertEquals("code",      "84",  identifier.getCode());
+
+        crs = CommonCRS.NAD83.geographic();
+        identifier = getSingleton(crs.getIdentifiers());
+        assertEquals("codespace", "EPSG", identifier.getCodeSpace());
+        assertEquals("code",      "4269", identifier.getCode());
+
+        crs = CommonCRS.NAD83.normalizedGeographic();
+        identifier = getSingleton(crs.getIdentifiers());
+        assertEquals("codespace", "CRS", identifier.getCodeSpace());
+        assertEquals("code",      "83",  identifier.getCode());
+
+        crs = CommonCRS.NAD27.geographic();
+        identifier = getSingleton(crs.getIdentifiers());
+        assertEquals("codespace", "EPSG", identifier.getCodeSpace());
+        assertEquals("code",      "4267", identifier.getCode());
+
+        crs = CommonCRS.NAD27.normalizedGeographic();
+        identifier = getSingleton(crs.getIdentifiers());
+        assertEquals("codespace", "CRS", identifier.getCodeSpace());
+        assertEquals("code",      "27",  identifier.getCode());
+    }
+
+    /**
      * Tests WKT 1 formatting.
      */
     @Test



Mime
View raw message