sis-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From desruisse...@apache.org
Subject svn commit: r1556773 - in /sis/branches/JDK7/core/sis-referencing/src: main/java/org/apache/sis/referencing/ test/java/org/apache/sis/referencing/
Date Thu, 09 Jan 2014 09:58:51 GMT
Author: desruisseaux
Date: Thu Jan  9 09:58:51 2014
New Revision: 1556773

URL: http://svn.apache.org/r1556773
Log:
First draft of a GeodeticObjects.geographic() method.

Modified:
    sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/GeodeticObjects.java
    sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/StandardDefinitions.java
    sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/StandardObjects.java
    sis/branches/JDK7/core/sis-referencing/src/test/java/org/apache/sis/referencing/GeodeticObjectsTest.java

Modified: sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/GeodeticObjects.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/GeodeticObjects.java?rev=1556773&r1=1556772&r2=1556773&view=diff
==============================================================================
--- sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/GeodeticObjects.java
[UTF-8] (original)
+++ sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/GeodeticObjects.java
[UTF-8] Thu Jan  9 09:58:51 2014
@@ -28,6 +28,8 @@ import org.opengis.referencing.crs.Geode
 import org.opengis.referencing.crs.VerticalCRS;
 import org.opengis.referencing.crs.TemporalCRS;
 import org.opengis.referencing.crs.GeographicCRS;
+import org.opengis.referencing.cs.EllipsoidalCS;
+import org.opengis.referencing.cs.AxisDirection;
 import org.opengis.referencing.datum.Ellipsoid;
 import org.opengis.referencing.datum.GeodeticDatum;
 import org.opengis.referencing.datum.PrimeMeridian;
@@ -35,6 +37,7 @@ import org.opengis.referencing.datum.Ver
 import org.opengis.referencing.datum.VerticalDatumType;
 import org.opengis.referencing.datum.TemporalDatum;
 import org.opengis.referencing.datum.DatumAuthorityFactory;
+import org.opengis.referencing.crs.CRSAuthorityFactory;
 import org.apache.sis.referencing.datum.DefaultVerticalDatum;
 import org.apache.sis.referencing.datum.DefaultTemporalDatum;
 import org.apache.sis.util.resources.Vocabulary;
@@ -57,7 +60,7 @@ import static org.opengis.referencing.Id
  * (<var>longitude</var>, <var>latitude</var>) axis order on the
{@link #WGS84} geodetic datum:</p>
  *
  * {@preformat java
- *   GeographicCRS crs = GeodeticObjects.WGS84.crs(true);
+ *   GeographicCRS crs = GeodeticObjects.WGS84.geographic();
  * }
  *
  * For each enumeration value, the name of the CRS, datum and ellipsoid objects may or may
not be the same.
@@ -104,7 +107,7 @@ public enum GeodeticObjects {
      *   <tr><th>Ellipsoid axes unit:</th>     <td>{@link SI#METRE}</td></tr>
      * </table></blockquote>
      */
-    WGS84((short) 7030, (short) 6326),
+    WGS84((short) 4326, (short) 6326, (short) 7030),
 
     /**
      * World Geodetic System 1972.
@@ -120,7 +123,7 @@ public enum GeodeticObjects {
      *   <tr><th>Ellipsoid axes unit:</th>     <td>{@link SI#METRE}</td></tr>
      * </table></blockquote>
      */
-    WGS72((short) 7043, (short) 6322),
+    WGS72((short) 4322, (short) 6322, (short) 7043),
 
     /**
      * European Terrestrial Reference System 1989.
@@ -142,7 +145,7 @@ public enum GeodeticObjects {
      *        The <cite>Web Map Server</cite> <code>"CRS:83"</code>
authority code uses the NAD83 datum,
      *        while the <code>"IGNF:MILLER"</code> authority code uses the GRS80
datum.}
      */
-    ETRS89((short) 7019, (short) 6258),
+    ETRS89((short) 4258, (short) 6258, (short) 7019),
 
     /**
      * North American Datum 1983.
@@ -165,7 +168,7 @@ public enum GeodeticObjects {
      *        The <cite>Web Map Server</cite> <code>"CRS:83"</code>
authority code uses the NAD83 datum,
      *        while the <code>"IGNF:MILLER"</code> authority code uses the GRS80
datum.}
      */
-    NAD83((short) 7019, (short) 6269),
+    NAD83((short) 4269, (short) 6269, (short) 7019),
 
     /**
      * North American Datum 1927.
@@ -181,7 +184,7 @@ public enum GeodeticObjects {
      *   <tr><th>Ellipsoid axes unit:</th>     <td>{@link SI#METRE}</td></tr>
      * </table></blockquote>
      */
-    NAD27((short) 7008, (short) 6267),
+    NAD27((short) 4267, (short) 6267, (short) 7008),
 
     /**
      * European Datum 1950.
@@ -197,7 +200,7 @@ public enum GeodeticObjects {
      *   <tr><th>Ellipsoid axes unit:</th>     <td>{@link SI#METRE}</td></tr>
      * </table></blockquote>
      */
-    ED50((short) 7022, (short) 6230),
+    ED50((short) 4230, (short) 6230, (short) 7022),
 
     /**
      * Unspecified datum based upon the GRS 1980 Authalic Sphere. Spheres use a simpler algorithm
for
@@ -215,19 +218,25 @@ public enum GeodeticObjects {
      *
      * @see org.apache.sis.referencing.datum.DefaultEllipsoid#getAuthalicRadius()
      */
-    SPHERE((short) 7048, (short) 6047);
+    SPHERE((short) 4047, (short) 6047, (short) 7048);
 
     /**
-     * The EPSG code of the ellipsoid.
+     * The EPSG code of the geographic CRS.
      */
-    final short ellipsoid;
+    final short crs;
 
     /**
-     * The EPSG code of the datum.
+     * The EPSG code of the datum. The value is often {@link #crs} + 2000,
+     * but it doesn't have to be always the case.
      */
     final short datum;
 
     /**
+     * The EPSG code of the ellipsoid.
+     */
+    final short ellipsoid;
+
+    /**
      * The cached object. This is initially {@code null}, then set to various kind of objects
depending
      * on which method has been invoked. The kind of object stored in this field may change
during the
      * application execution.
@@ -237,12 +246,14 @@ public enum GeodeticObjects {
     /**
      * Creates a new constant for the given EPSG or SIS codes.
      *
-     * @param ellipsoid The EPSG code for the ellipsoid.
+     * @param crs       The EPSG code for the geographic CRS.
      * @param datum     The EPSG code for the datum.
+     * @param ellipsoid The EPSG code for the ellipsoid.
      */
-    private GeodeticObjects(final short ellipsoid, final short datum) {
-        this.ellipsoid = ellipsoid;
+    private GeodeticObjects(final short crs, final short datum, final short ellipsoid) {
+        this.crs       = crs;
         this.datum     = datum;
+        this.ellipsoid = ellipsoid;
     }
 
     /**
@@ -261,6 +272,61 @@ public enum GeodeticObjects {
     }
 
     /**
+     * Returns the two-dimensional geographic CRS associated to this geodetic object.
+     * The coordinate system axes will be in (<var>latitude</var>, <var>longitude</var>)
order
+     * oriented toward {@linkplain AxisDirection#NORTH North} and {@linkplain AxisDirection#EAST
East}
+     * respectively, with units in degrees.
+     * The following table summarizes the coordinate reference systems known to this class,
+     * together with an enumeration value that can be used for fetching that CRS:
+     *
+     * <blockquote><table class="sis">
+     *   <tr><th>Name or alias</th>            <th>Enum</th>
           <th>EPSG</th></tr>
+     *   <tr><td>ED50</td>                     <td>{@link #ED50}</td>
  <td>4230</td></tr>
+     *   <tr><td>ETRS89</td>                   <td>{@link #ETRS89}</td>
<td>4258</td></tr>
+     *   <tr><td>NAD27</td>                    <td>{@link #NAD27}</td>
 <td>4267</td></tr>
+     *   <tr><td>NAD83</td>                    <td>{@link #NAD83}</td>
 <td>4269</td></tr>
+     *   <tr><td>GRS 1980 Authalic Sphere</td> <td>{@link #SPHERE}</td>
<td>4047</td></tr>
+     *   <tr><td>WGS 72</td>                   <td>{@link #WGS72}</td>
 <td>4322</td></tr>
+     *   <tr><td>WGS 84</td>                   <td>{@link #WGS84}</td>
 <td>4326</td></tr>
+     * </table></blockquote>
+     *
+     * @return The geographic CRS associated to this constant.
+     *
+     * @see org.apache.sis.referencing.crs.DefaultGeographicCRS
+     * @see CRSAuthorityFactory#createGeographicCRS(String)
+     */
+    public GeographicCRS geographic() {
+        GeographicCRS object = geographic(cached);
+        if (object == null) {
+            synchronized (this) {
+                object = geographic(cached);
+                if (object == null) {
+                    final CRSAuthorityFactory factory = StandardObjects.crsFactory();
+                    if (factory != null) try {
+                        cached = object = factory.createGeographicCRS(String.valueOf(crs));
+                        return object;
+                    } catch (FactoryException e) {
+                        StandardObjects.failure(this, "geographic", e);
+                    }
+                    /*
+                     * All constants defined in this enumeration use the same coordinate
system, EPSG:6422.
+                     * We will arbitrarily create this CS only for WGS84 (the most frequently
created CRS),
+                     * and share that CS instance for all other constants.
+                     */
+                    final EllipsoidalCS cs;
+                    if (this == WGS84) {
+                        cs = (EllipsoidalCS) StandardDefinitions.createCoordinateSystem((short)
6422);
+                    } else {
+                        cs = WGS84.geographic().getCoordinateSystem();
+                    }
+                    object = StandardDefinitions.createGeographicCRS(crs, datum(), cs);
+                }
+            }
+        }
+        return object;
+    }
+
+    /**
      * Returns the geodetic datum associated to this geodetic object.
      * The following table summarizes the datums known to this class,
      * together with an enumeration value that can be used for fetching that datum:
@@ -388,6 +454,13 @@ public enum GeodeticObjects {
     }
 
     /**
+     * Returns the geographic CRS associated to the given object, or {@code null} if none.
+     */
+    private static GeographicCRS geographic(final IdentifiedObject object) {
+        return (object instanceof GeographicCRS) ? (GeographicCRS) object : null;
+    }
+
+    /**
      * Returns the datum associated to the given object, or {@code null} if none.
      */
     private static GeodeticDatum datum(final IdentifiedObject object) {

Modified: sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/StandardDefinitions.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/StandardDefinitions.java?rev=1556773&r1=1556772&r2=1556773&view=diff
==============================================================================
--- sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/StandardDefinitions.java
[UTF-8] (original)
+++ sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/StandardDefinitions.java
[UTF-8] Thu Jan  9 09:58:51 2014
@@ -25,10 +25,21 @@ import javax.measure.quantity.Length;
 import org.opengis.referencing.datum.Ellipsoid;
 import org.opengis.referencing.datum.PrimeMeridian;
 import org.opengis.referencing.datum.GeodeticDatum;
+import org.opengis.referencing.cs.RangeMeaning;
+import org.opengis.referencing.cs.AxisDirection;
+import org.opengis.referencing.cs.CoordinateSystem;
+import org.opengis.referencing.cs.CoordinateSystemAxis;
+import org.opengis.referencing.cs.EllipsoidalCS;
+import org.opengis.referencing.crs.GeographicCRS;
 import org.apache.sis.metadata.iso.citation.Citations;
 import org.apache.sis.referencing.datum.DefaultEllipsoid;
 import org.apache.sis.referencing.datum.DefaultPrimeMeridian;
 import org.apache.sis.referencing.datum.DefaultGeodeticDatum;
+import org.apache.sis.referencing.cs.DefaultEllipsoidalCS;
+import org.apache.sis.referencing.cs.DefaultCoordinateSystemAxis;
+import org.apache.sis.referencing.crs.DefaultGeographicCRS;
+import org.apache.sis.measure.Longitude;
+import org.apache.sis.measure.Latitude;
 
 import static org.opengis.referencing.IdentifiedObject.NAME_KEY;
 import static org.opengis.referencing.IdentifiedObject.ALIAS_KEY;
@@ -74,6 +85,30 @@ final class StandardDefinitions {
     }
 
     /**
+     * Creates a geodetic CRS from hard-coded values for the given code.
+     *
+     * @param  code  The EPSG code.
+     * @param  datum The geodetic datum.
+     * @param  cs    The coordinate system.
+     * @return The geographic CRS for the given code.
+     */
+    static GeographicCRS createGeographicCRS(final short code, final GeodeticDatum datum,
final EllipsoidalCS cs) {
+        final String name;
+        String alias = null;
+        switch (code) {
+            case 4326: name = "WGS 84"; break;
+            case 4322: name = "WGS 72"; break;
+            case 4258: name = "ETRS89"; alias = "ETRS89-GRS80"; break;
+            case 4269: name = "NAD83"; break;
+            case 4267: name = "NAD27"; break;
+            case 4230: name = "ED50"; break;
+            case 4047: name = "Unspecified datum based upon the GRS 1980 Authalic Sphere";
break;
+            default:   throw new AssertionError(code);
+        }
+        return new DefaultGeographicCRS(properties(code, name, alias), datum, cs);
+    }
+
+    /**
      * Creates a geodetic datum from hard-coded values for the given code.
      *
      * @param  code      The EPSG code.
@@ -137,4 +172,74 @@ final class StandardDefinitions {
         properties.put(IDENTIFIERS_KEY, new NamedIdentifier(Citations.EPSG, GREENWICH));
         return new DefaultPrimeMeridian(properties, 0, NonSI.DEGREE_ANGLE);
     }
+
+    /**
+     * Creates a coordinate system from hard-coded values for the given code.
+     * The coordinate system names used by this method contains only the first
+     * part of the names declared in the EPSG database.
+     *
+     * @param  code The EPSG code.
+     * @return The coordinate system for the given code.
+     */
+    static CoordinateSystem createCoordinateSystem(final short code) {
+        final String name;
+        short xc, yc, zc = 0; // Not necessarily (long, lat) order.
+        switch (code) {
+            case 6422: name = "Ellipsoidal 2D"; xc = 106; yc = 107;           break;
+            case 6423: name = "Ellipsoidal 3D"; xc = 108; yc = 109; zc = 110; break;
+            default:   throw new AssertionError(code);
+        }
+        final Map<String,?> properties = properties(code, name, null);
+        final CoordinateSystemAxis xAxis = createAxis(xc);
+        final CoordinateSystemAxis yAxis = createAxis(yc);
+        if (zc != 0) {
+            final CoordinateSystemAxis zAxis = createAxis(zc);
+            return new DefaultEllipsoidalCS(properties, xAxis, yAxis, zAxis);
+        }
+        return new DefaultEllipsoidalCS(properties, xAxis, yAxis);
+    }
+
+    /**
+     * Creates an axis from hard-coded values for the given code.
+     *
+     * @param  code The EPSG code.
+     * @return The coordinate system axis for the given code.
+     */
+    private static CoordinateSystemAxis createAxis(final short code) {
+        final String name, abrv;
+        final Unit<?> unit;
+        final double min, max;
+        final RangeMeaning rm;
+        final AxisDirection dir;
+        switch (code) {
+            case 106:
+            case 108:  name = "Geodetic latitude";
+                       abrv = "φ";
+                       unit = NonSI.DEGREE_ANGLE;
+                       dir  = AxisDirection.NORTH;
+                       min  = Latitude.MIN_VALUE;
+                       max  = Latitude.MAX_VALUE;
+                       rm   = RangeMeaning.EXACT;
+                       break;
+            case 107:
+            case 109:  name = "Geodetic longitude";
+                       abrv = "λ";
+                       unit = NonSI.DEGREE_ANGLE;
+                       dir  = AxisDirection.EAST;
+                       min  = Longitude.MIN_VALUE;
+                       max  = Longitude.MAX_VALUE;
+                       rm   = RangeMeaning.WRAPAROUND;
+                       break;
+            case 110:  name = "llipsoidal height ";
+                       abrv = "h";
+                       unit = SI.METRE;
+                       dir  = AxisDirection.UP;
+                       min  = Double.NEGATIVE_INFINITY;
+                       max  = Double.POSITIVE_INFINITY;
+                       rm   = null;
+                       break;
+            default:   throw new AssertionError(code);
+        }
+        return new DefaultCoordinateSystemAxis(properties(code, name, null), abrv, dir, unit,
min, max, rm);
+    }
 }

Modified: sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/StandardObjects.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/StandardObjects.java?rev=1556773&r1=1556772&r2=1556773&view=diff
==============================================================================
--- sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/StandardObjects.java
[UTF-8] (original)
+++ sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/StandardObjects.java
[UTF-8] Thu Jan  9 09:58:51 2014
@@ -18,6 +18,7 @@ package org.apache.sis.referencing;
 
 import java.lang.reflect.Method;
 import org.opengis.util.FactoryException;
+import org.opengis.referencing.crs.CRSAuthorityFactory;
 import org.opengis.referencing.datum.DatumAuthorityFactory;
 import org.apache.sis.internal.system.Modules;
 import org.apache.sis.internal.system.SystemListener;
@@ -64,6 +65,14 @@ final class StandardObjects extends Syst
     }
 
     /**
+     * Returns the EPSG factory to use for creating CRS, or {@code null} if none.
+     * If this method returns {@code null}, then the caller will silently fallback on hard-coded
values.
+     */
+    static CRSAuthorityFactory crsFactory() {
+        return null; // TODO
+    }
+
+    /**
      * Returns the EPSG factory to use for creating datum, ellipsoids and prime meridians,
or {@code null} if none.
      * If this method returns {@code null}, then the caller will silently fallback on hard-coded
values.
      */

Modified: sis/branches/JDK7/core/sis-referencing/src/test/java/org/apache/sis/referencing/GeodeticObjectsTest.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-referencing/src/test/java/org/apache/sis/referencing/GeodeticObjectsTest.java?rev=1556773&r1=1556772&r2=1556773&view=diff
==============================================================================
--- sis/branches/JDK7/core/sis-referencing/src/test/java/org/apache/sis/referencing/GeodeticObjectsTest.java
[UTF-8] (original)
+++ sis/branches/JDK7/core/sis-referencing/src/test/java/org/apache/sis/referencing/GeodeticObjectsTest.java
[UTF-8] Thu Jan  9 09:58:51 2014
@@ -17,6 +17,7 @@
 package org.apache.sis.referencing;
 
 import java.util.Date;
+import org.opengis.referencing.crs.GeographicCRS;
 import org.opengis.referencing.datum.TemporalDatum;
 import org.opengis.referencing.datum.VerticalDatum;
 import org.opengis.referencing.datum.VerticalDatumType;
@@ -50,6 +51,16 @@ public final strictfp class GeodeticObje
     private static final double DAY_LENGTH = 24 * 60 * 60 * 1000;
 
     /**
+     * Tests the {@link GeodeticObjects#WGS84} constant.
+     */
+    @Test
+    public void testWGS84() {
+        final GeographicCRS crs = GeodeticObjects.WGS84.geographic();
+        Validators.validate(crs);
+        GeodeticObjectVerifier.assertIsWGS84(crs, false, true);
+    }
+
+    /**
      * Verifies the vertical datum enumeration.
      */
     @Test



Mime
View raw message