sis-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From desruisse...@apache.org
Subject svn commit: r1558561 - in /sis/branches/JDK7/core: sis-referencing/src/main/java/org/apache/sis/referencing/ sis-referencing/src/test/java/org/apache/sis/referencing/ sis-referencing/src/test/java/org/apache/sis/test/suite/ sis-utility/src/main/java/or...
Date Wed, 15 Jan 2014 20:53:24 GMT
Author: desruisseaux
Date: Wed Jan 15 20:53:24 2014
New Revision: 1558561

URL: http://svn.apache.org/r1558561
Log:
Provide a partial implementation of CRS.forCode(String).

Added:
    sis/branches/JDK7/core/sis-referencing/src/test/java/org/apache/sis/referencing/CRSTest.java
  (with props)
Modified:
    sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/CRS.java
    sis/branches/JDK7/core/sis-referencing/src/test/java/org/apache/sis/test/suite/ReferencingTestSuite.java
    sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/util/resources/Errors.java
    sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/util/resources/Errors.properties
    sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/util/resources/Errors_fr.properties

Modified: sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/CRS.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/CRS.java?rev=1558561&r1=1558560&r2=1558561&view=diff
==============================================================================
--- sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/CRS.java
[UTF-8] (original)
+++ sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/CRS.java
[UTF-8] Wed Jan 15 20:53:24 2014
@@ -20,12 +20,16 @@ import java.util.List;
 import java.util.ArrayList;
 import java.util.Collections;
 import org.opengis.util.FactoryException;
+import org.opengis.util.NoSuchIdentifierException;
 import org.opengis.referencing.NoSuchAuthorityCodeException;
 import org.opengis.referencing.crs.SingleCRS;
 import org.opengis.referencing.crs.CompoundCRS;
 import org.opengis.referencing.crs.CoordinateReferenceSystem;
+import org.apache.sis.internal.util.DefinitionURI;
 import org.apache.sis.internal.referencing.ReferencingUtilities;
 import org.apache.sis.referencing.crs.DefaultCompoundCRS;
+import org.apache.sis.util.resources.Errors;
+import org.apache.sis.util.CharSequences;
 import org.apache.sis.util.Static;
 
 import static org.apache.sis.util.ArgumentChecks.ensureNonNull;
@@ -48,8 +52,22 @@ public final class CRS extends Static {
 
     /**
      * Returns a Coordinate Reference System from the given authority code.
+     * There is many thousands of CRS identified by EPSG codes or by other authorities.
+     * The following table lists a very small subset of some of those codes:
      *
-     * @todo This method is not yet implemented. It will be provided after the EPSG-backed
+     * <blockquote><table class="sis">
+     *   <tr><th>Name or alias</th>            <th>Code</th></tr>
+     *   <tr><td>ED50</td>                     <td>EPSG:4230</td></tr>
+     *   <tr><td>ETRS89</td>                   <td>EPSG:4258</td></tr>
+     *   <tr><td>NAD27</td>                    <td>EPSG:4267</td></tr>
+     *   <tr><td>NAD83</td>                    <td>EPSG:4269</td></tr>
+     *   <tr><td>GRS 1980 Authalic Sphere</td> <td>EPSG:4047</td></tr>
+     *   <tr><td>WGS 72</td>                   <td>EPSG:4322</td></tr>
+     *   <tr><td>WGS 84</td>                   <td>EPSG:4326</td></tr>
+     *   <tr><td>WGS 84 with (<var>longitude</var>, <var>latitude</var>)
axis order</td> <td>CRS:84</td></tr>
+     * </table></blockquote>
+     *
+     * @todo This method is only partially implemented. It will be fully supported after
the EPSG-backed
      *       authority factory has been ported to Apache SIS.
      *
      * @param  code The authority code.
@@ -61,7 +79,52 @@ public final class CRS extends Static {
             throws NoSuchAuthorityCodeException, FactoryException
     {
         ensureNonNull("code", code);
-        return null;
+        final String authority;
+        final String value;
+        final DefinitionURI uri = DefinitionURI.parse(code);
+        if (uri != null) {
+            final String type = uri.type;
+            if (type != null && !type.equalsIgnoreCase("crs")) {
+                throw new NoSuchIdentifierException(Errors.format(Errors.Keys.UnknownType_1,
type), type);
+            }
+            authority = uri.authority;
+            value = uri.code;
+        } else {
+            final int s = code.indexOf(DefinitionURI.SEPARATOR);
+            authority = CharSequences.trimWhitespaces(code.substring(0, Math.max(0, s)));
+            value = CharSequences.trimWhitespaces(code.substring(s + 1));
+        }
+        if (authority == null || authority.isEmpty()) {
+            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.
+         */
+        NumberFormatException cause = null;
+        try {
+            if (authority.equalsIgnoreCase("CRS")) {
+                switch (Integer.parseInt(value)) {
+                    case 84: return GeodeticObjects.WGS84.normalizedGeographic();
+                }
+            } else if (authority.equalsIgnoreCase("EPSG")) {
+                final int n = Integer.parseInt(value);
+                for (final GeodeticObjects candidate : GeodeticObjects.values()) {
+                    if (candidate.geographic == n) {
+                        return candidate.geographic();
+                    }
+                }
+            } else {
+                throw new NoSuchIdentifierException(Errors.format(Errors.Keys.UnknownAuthority_1,
authority), authority);
+            }
+        } catch (NumberFormatException e) {
+            cause = e;
+        }
+        final NoSuchAuthorityCodeException e = new NoSuchAuthorityCodeException(
+                Errors.format(Errors.Keys.NoSuchAuthorityCode_3, authority, CoordinateReferenceSystem.class,
value),
+                authority, value, code);
+        e.initCause(cause);
+        throw e;
     }
 
     /**

Added: sis/branches/JDK7/core/sis-referencing/src/test/java/org/apache/sis/referencing/CRSTest.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-referencing/src/test/java/org/apache/sis/referencing/CRSTest.java?rev=1558561&view=auto
==============================================================================
--- sis/branches/JDK7/core/sis-referencing/src/test/java/org/apache/sis/referencing/CRSTest.java
(added)
+++ sis/branches/JDK7/core/sis-referencing/src/test/java/org/apache/sis/referencing/CRSTest.java
[UTF-8] Wed Jan 15 20:53:24 2014
@@ -0,0 +1,65 @@
+/*
+ * 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.referencing;
+
+import org.opengis.referencing.crs.GeographicCRS;
+import org.opengis.util.FactoryException;
+import org.apache.sis.test.DependsOn;
+import org.apache.sis.test.TestCase;
+import org.junit.Test;
+
+import static org.junit.Assert.*;
+
+
+/**
+ * Tests the {@link CRS} class.
+ *
+ * @author  Martin Desruisseaux (Geomatys)
+ * @since   0.4
+ * @version 0.4
+ * @module
+ */
+@DependsOn({
+    GeodeticObjectsTest.class
+})
+public final strictfp class CRSTest extends TestCase {
+    /**
+     * Asserts that the result of {@link CRS#forCode(String)} is the given CRS.
+     */
+    private static void verifyForCode(final GeographicCRS expected, final String code) throws
FactoryException {
+        assertSame(code, expected, CRS.forCode(code));
+    }
+
+    /**
+     * Tests {@link CRS#forCode(String)}.
+     *
+     * @throws FactoryException If a CRS can not be constructed.
+     */
+    @Test
+    public void testForCode() throws FactoryException {
+        verifyForCode(GeodeticObjects.WGS84 .normalizedGeographic(), "CRS:84");
+        verifyForCode(GeodeticObjects.WGS84 .geographic(),           "EPSG:4326");
+        verifyForCode(GeodeticObjects.WGS84 .geographic(),           "urn:ogc:def:crs:EPSG::4326");
+        verifyForCode(GeodeticObjects.WGS84 .geographic(),           "http://www.opengis.net/gml/srs/epsg.xml#4326");
+        verifyForCode(GeodeticObjects.WGS72 .geographic(),           "EPSG:4322");
+        verifyForCode(GeodeticObjects.SPHERE.geographic(),           "EPSG:4047");
+        verifyForCode(GeodeticObjects.NAD83 .geographic(),           "EPSG:4269");
+        verifyForCode(GeodeticObjects.NAD27 .geographic(),           "EPSG:4267");
+        verifyForCode(GeodeticObjects.ETRS89.geographic(),           "EPSG:4258");
+        verifyForCode(GeodeticObjects.ED50  .geographic(),           "EPSG:4230");
+    }
+}

Propchange: sis/branches/JDK7/core/sis-referencing/src/test/java/org/apache/sis/referencing/CRSTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: sis/branches/JDK7/core/sis-referencing/src/test/java/org/apache/sis/referencing/CRSTest.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain;charset=UTF-8

Modified: sis/branches/JDK7/core/sis-referencing/src/test/java/org/apache/sis/test/suite/ReferencingTestSuite.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-referencing/src/test/java/org/apache/sis/test/suite/ReferencingTestSuite.java?rev=1558561&r1=1558560&r2=1558561&view=diff
==============================================================================
--- sis/branches/JDK7/core/sis-referencing/src/test/java/org/apache/sis/test/suite/ReferencingTestSuite.java
[UTF-8] (original)
+++ sis/branches/JDK7/core/sis-referencing/src/test/java/org/apache/sis/test/suite/ReferencingTestSuite.java
[UTF-8] Wed Jan 15 20:53:24 2014
@@ -73,6 +73,7 @@ import org.junit.BeforeClass;
     org.apache.sis.referencing.crs.DefaultGeodeticCRSTest.class,
     org.apache.sis.referencing.StandardDefinitionsTest.class,
     org.apache.sis.referencing.GeodeticObjectsTest.class,
+    org.apache.sis.referencing.CRSTest.class,
 
     org.apache.sis.geometry.AbstractDirectPositionTest.class,
     org.apache.sis.geometry.GeneralDirectPositionTest.class,

Modified: sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/util/resources/Errors.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/util/resources/Errors.java?rev=1558561&r1=1558560&r2=1558561&view=diff
==============================================================================
--- sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/util/resources/Errors.java
[UTF-8] (original)
+++ sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/util/resources/Errors.java
[UTF-8] Wed Jan 15 20:53:24 2014
@@ -371,6 +371,11 @@ public final class Errors extends Indexe
         public static final short MismatchedMatrixSize_4 = 60;
 
         /**
+         * No authority was specified for code “{0}”. The expected syntax is “AUTHORITY:CODE”.
+         */
+        public static final short MissingAuthority_1 = 135;
+
+        /**
          * This operation requires the “{0}” module.
          */
         public static final short MissingRequiredModule_1 = 61;
@@ -416,6 +421,11 @@ public final class Errors extends Indexe
         public static final short NoConvergenceForPoints_2 = 69;
 
         /**
+         * No code “{2}” from authority “{0}” found for object of type ‘{1}’.
+         */
+        public static final short NoSuchAuthorityCode_3 = 137;
+
+        /**
          * Element “{0}” has not been found.
          */
         public static final short NoSuchElement_1 = 70;
@@ -631,6 +641,11 @@ public final class Errors extends Indexe
         public static final short UnexpectedFileFormat_2 = 111;
 
         /**
+         * Authority “{0}” is unknown.
+         */
+        public static final short UnknownAuthority_1 = 136;
+
+        /**
          * Axis direction “{0}” is unknown.
          */
         public static final short UnknownAxisDirection_1 = 112;

Modified: sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/util/resources/Errors.properties
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/util/resources/Errors.properties?rev=1558561&r1=1558560&r2=1558561&view=diff
==============================================================================
--- sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/util/resources/Errors.properties
[ISO-8859-1] (original)
+++ sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/util/resources/Errors.properties
[ISO-8859-1] Wed Jan 15 20:53:24 2014
@@ -85,6 +85,7 @@ MismatchedCRS                     = The 
 MismatchedDimension_2             = Mismatched object dimensions: {0}D and {1}D.
 MismatchedDimension_3             = Argument \u2018{0}\u2019 has {2} dimension{2,choice,1#|2#s},
while {1} was expected.
 MismatchedMatrixSize_4            = Mismatched matrix sizes: expected {0}\u00d7{1} but got
{2}\u00d7{3}.
+MissingAuthority_1                = No authority was specified for code \u201c{0}\u201d.
The expected syntax is \u201cAUTHORITY:CODE\u201d.
 MissingRequiredModule_1           = This operation requires the \u201c{0}\u201d module.
 MissingSchemeInURI                = Missing scheme in URI.
 MissingValueForOption_1           = Missing value for option \u201c{0}\u201d.
@@ -116,6 +117,7 @@ NotAPrimitiveWrapper_1            = Clas
 NotASkewSymmetricMatrix           = Matrix is not skew-symmetric.
 NotAUnicodeIdentifier_1           = Text \u201c{0}\u201d is not a Unicode identifier.
 NotComparableClass_1              = Class \u2018{0}\u2019 is not a comparable.
+NoSuchAuthorityCode_3             = No code \u201c{2}\u201d from authority \u201c{0}\u201d
found for object of type \u2018{1}\u2019.
 NoSuchElement_1                   = Element \u201c{0}\u201d has not been found.
 NoSuchProperty_2                  = No property named \u201c{0}\u201d has been found in \u201c{1}\u201d.
 NoUnit                            = No unit of measurement has been specified.
@@ -138,6 +140,7 @@ UnexpectedChange_1                = Unex
 UnexpectedEndOfFile_1             = Unexpected end of file while reading \u201c{0}\u201d.
 UnexpectedEndOfString_1           = More characters were expected at the end of \u201c{0}\u201d.
 UnexpectedFileFormat_2            = File \u201c{1}\u201d seems to be encoded in an other
format than {0}.
+UnknownAuthority_1                = Authority \u201c{0}\u201d is unknown.
 UnknownAxisDirection_1            = Axis direction \u201c{0}\u201d is unknown.
 UnknownCommand_1                  = Command \u201c{0}\u201d is not recognized.
 UnknownEnumValue_1                = Unknown enumeration value: {0}.

Modified: sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/util/resources/Errors_fr.properties
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/util/resources/Errors_fr.properties?rev=1558561&r1=1558560&r2=1558561&view=diff
==============================================================================
--- sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/util/resources/Errors_fr.properties
[ISO-8859-1] (original)
+++ sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/util/resources/Errors_fr.properties
[ISO-8859-1] Wed Jan 15 20:53:24 2014
@@ -75,6 +75,7 @@ MismatchedCRS                     = Le s
 MismatchedDimension_2             = Les dimensions des objets ({0}D et {1}D) ne concordent
pas.
 MismatchedDimension_3             = L\u2019argument \u2018{0}\u2019 a {2} dimension{2,choice,1#|2#s},
alors qu\u2019on en attendait {1}.
 MismatchedMatrixSize_4            = Une matrice de taille de {0}\u00d7{1} \u00e9tait attendue
mais la matrice donn\u00e9es est de taille {2}\u00d7{3}.
+MissingAuthority_1                = Aucune autorit\u00e9 n\u2019a \u00e9t\u00e9 sp\u00e9cifi\u00e9e
pour le code \u201c{0}\u201d. Le format attendu est \u201cAUTORIT\u00c9:CODE\u201d.
 MissingRequiredModule_1           = Cette op\u00e9ration requiert le module \u201c{0}\u201d.
 MissingSchemeInURI                = Il manque le sch\u00e9ma d\u2019URI.
 MissingValueForOption_1           = Aucune valeur n\u2019a \u00e9t\u00e9 d\u00e9finie pour
l\u2019option \u201c{0}\u201d.
@@ -106,6 +107,7 @@ NotAPrimitiveWrapper_1            = La c
 NotASkewSymmetricMatrix           = La matrice n\u2019est pas antisym\u00e9trique.
 NotAUnicodeIdentifier_1           = Le texte \u201c{0}\u201d n\u2019est pas un identifiant
Unicode.
 NotComparableClass_1              = La classe \u2018{0}\u2019 n\u2019est pas comparable.
+NoSuchAuthorityCode_3             = Aucun code \u201c{2}\u201d de l\u2019autorit\u00e9 \u201c{0}\u201d
n\u2019a \u00e9t\u00e9 trouv\u00e9 pour un objet de type \u2018{1}\u2019.
 NoSuchElement_1                   = L\u2019\u00e9lement \u201c{0}\u201d n\u2019a pas \u00e9t\u00e9
trouv\u00e9.
 NoSuchProperty_2                  = Aucune propri\u00e9t\u00e9 nomm\u00e9e \u201c{0}\u201d
n\u2019a \u00e9t\u00e9 trouv\u00e9e dans \u201c{1}\u201d.
 NoUnit                            = Aucune unit\u00e9 de mesure n\u2019a \u00e9t\u00e9 sp\u00e9cifi\u00e9e.
@@ -127,6 +129,7 @@ UnexpectedChange_1                = Chan
 UnexpectedEndOfFile_1             = Fin de fichier inattendue lors de la lecture de \u201c{0}\u201d.
 UnexpectedEndOfString_1           = D\u2019autres caract\u00e8res \u00e9taient attendus \u00e0
la fin du texte \u201c{0}\u201d.
 UnexpectedFileFormat_2            = Le fichier \u201c{1}\u201d semble \u00eatre encod\u00e9
dans un autre format que {0}.
+UnknownAuthority_1                = L\u2019autorit\u00e9 \u201c{0}\u201d n\u2019est pas reconnue.
 UnknownAxisDirection_1            = La direction d\u2019axe \u201c{0}\u201d n\u2019est pas
reconnue.
 UnknownCommand_1                  = La commande \u201c{0}\u201d n\u2019est pas reconnue.
 UnknownEnumValue_1                = Valeur d\u2019\u00e9num\u00e9ration inconnue: {0}.



Mime
View raw message