sis-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From desruisse...@apache.org
Subject svn commit: r1543548 - in /sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing: GeodeticObjects.java StandardDefinitions.java
Date Tue, 19 Nov 2013 19:49:24 GMT
Author: desruisseaux
Date: Tue Nov 19 19:49:23 2013
New Revision: 1543548

URL: http://svn.apache.org/r1543548
Log:
Added GeodeticDatum definitions for some common ones.

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

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=1543548&r1=1543547&r2=1543548&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] Tue Nov 19 19:49:23 2013
@@ -104,7 +104,7 @@ public enum GeodeticObjects {
      *   <tr><th>Ellipsoid axes unit:</th>     <td>{@link SI#METRE}</td></tr>
      * </table></blockquote>
      */
-    WGS84((short) 7030),
+    WGS84((short) 7030, (short) 6326),
 
     /**
      * World Geodetic System 1972.
@@ -120,7 +120,7 @@ public enum GeodeticObjects {
      *   <tr><th>Ellipsoid axes unit:</th>     <td>{@link SI#METRE}</td></tr>
      * </table></blockquote>
      */
-    WGS72((short) 7043),
+    WGS72((short) 7043, (short) 6322),
 
     /**
      * European Terrestrial Reference System 1989.
@@ -142,7 +142,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),
+    ETRS89((short) 7019, (short) 6258),
 
     /**
      * North American Datum 1983.
@@ -165,7 +165,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),
+    NAD83((short) 7019, (short) 6269),
 
     /**
      * North American Datum 1927.
@@ -181,7 +181,7 @@ public enum GeodeticObjects {
      *   <tr><th>Ellipsoid axes unit:</th>     <td>{@link SI#METRE}</td></tr>
      * </table></blockquote>
      */
-    NAD27((short) 7008),
+    NAD27((short) 7008, (short) 6267),
 
     /**
      * European Datum 1950.
@@ -197,7 +197,7 @@ public enum GeodeticObjects {
      *   <tr><th>Ellipsoid axes unit:</th>     <td>{@link SI#METRE}</td></tr>
      * </table></blockquote>
      */
-    ED50((short) 7022),
+    ED50((short) 7022, (short) 6230),
 
     /**
      * Unspecified datum based upon the GRS 1980 Authalic Sphere. Spheres use a simpler algorithm
for
@@ -215,7 +215,7 @@ public enum GeodeticObjects {
      *
      * @see org.apache.sis.referencing.datum.DefaultEllipsoid#getAuthalicRadius()
      */
-    SPHERE((short) 7048);
+    SPHERE((short) 7048, (short) 6047);
 
     /**
      * The EPSG code of the ellipsoid.
@@ -223,6 +223,11 @@ public enum GeodeticObjects {
     final short ellipsoid;
 
     /**
+     * The EPSG code of the datum.
+     */
+    final short datum;
+
+    /**
      * 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.
@@ -231,12 +236,13 @@ public enum GeodeticObjects {
 
     /**
      * Creates a new constant for the given EPSG or SIS codes.
-     * By convention, SIS codes are negative.
      *
      * @param ellipsoid The EPSG code for the ellipsoid.
+     * @param datum     The EPSG code for the datum.
      */
-    private GeodeticObjects(final short ellipsoid) {
+    private GeodeticObjects(final short ellipsoid, final short datum) {
         this.ellipsoid = ellipsoid;
+        this.datum     = datum;
     }
 
     /**
@@ -255,6 +261,48 @@ public enum GeodeticObjects {
     }
 
     /**
+     * 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:
+     *
+     * <blockquote><table class="sis">
+     *   <tr><th>Name or alias</th>                                   
 <th>Enum</th>            <th>EPSG</th></tr>
+     *   <tr><td>European Datum 1950</td>                             
 <td>{@link #ED50}</td>   <td>6230</td></tr>
+     *   <tr><td>European Terrestrial Reference System 1989</td>      
 <td>{@link #ETRS89}</td> <td>6258</td></tr>
+     *   <tr><td>North American Datum 1927</td>                       
 <td>{@link #NAD27}</td>  <td>6267</td></tr>
+     *   <tr><td>North American Datum 1983</td>                       
 <td>{@link #NAD83}</td>  <td>6269</td></tr>
+     *   <tr><td>Not specified (based on GRS 1980 Authalic Sphere)</td>
<td>{@link #SPHERE}</td> <td>6047</td></tr>
+     *   <tr><td>World Geodetic System 1972</td>                      
 <td>{@link #WGS72}</td>  <td>6322</td></tr>
+     *   <tr><td>World Geodetic System 1984</td>                      
 <td>{@link #WGS84}</td>  <td>6326</td></tr>
+     * </table></blockquote>
+     *
+     * @return The geodetic datum associated to this constant.
+     *
+     * @see org.apache.sis.referencing.datum.DefaultGeodeticDatum
+     * @see DatumAuthorityFactory#createGeodeticDatum(String)
+     */
+    public GeodeticDatum datum() {
+        GeodeticDatum object = datum(cached);
+        if (object == null) {
+            synchronized (this) {
+                object = datum(cached);
+                if (object == null) {
+                    final DatumAuthorityFactory factory = StandardObjects.datumFactory();
+                    if (factory != null) try {
+                        cached = object = factory.createGeodeticDatum(String.valueOf(datum));
+                        return object;
+                    } catch (FactoryException e) {
+                        StandardObjects.failure(this, "datum", e);
+                    }
+                    object = StandardDefinitions.createGeodeticDatum(datum, ellipsoid(),
primeMeridian());
+                    cached = object;
+                }
+            }
+        }
+        return object;
+    }
+
+    /**
      * Returns the ellipsoid associated to this geodetic object.
      * The following table summarizes the ellipsoids known to this class,
      * together with an enumeration value that can be used for fetching that ellipsoid:
@@ -340,35 +388,38 @@ public enum GeodeticObjects {
     }
 
     /**
-     * Returns the ellipsoid associated to the given object, or {@code null} if none.
+     * Returns the datum associated to the given object, or {@code null} if none.
      */
-    private static Ellipsoid ellipsoid(final IdentifiedObject object) {
-        if (object instanceof Ellipsoid) {
-            return (Ellipsoid) object;
-        }
+    private static GeodeticDatum datum(final IdentifiedObject object) {
         if (object instanceof GeodeticDatum) {
-            return ((GeodeticDatum) object).getEllipsoid();
+            return (GeodeticDatum) object;
         }
         if (object instanceof GeodeticCRS) {
-            return ((GeodeticCRS) object).getDatum().getEllipsoid();
+            return ((GeodeticCRS) object).getDatum();
         }
         return null;
     }
 
     /**
+     * Returns the ellipsoid associated to the given object, or {@code null} if none.
+     */
+    private static Ellipsoid ellipsoid(final IdentifiedObject object) {
+        if (object instanceof Ellipsoid) {
+            return (Ellipsoid) object;
+        }
+        final GeodeticDatum datum = datum(object);
+        return (datum != null) ? datum.getEllipsoid() : null;
+    }
+
+    /**
      * Returns the prime meridian associated to the given object, or {@code null} if none.
      */
     private static PrimeMeridian primeMeridian(final IdentifiedObject object) {
         if (object instanceof PrimeMeridian) {
             return (PrimeMeridian) object;
         }
-        if (object instanceof GeodeticDatum) {
-            return ((GeodeticDatum) object).getPrimeMeridian();
-        }
-        if (object instanceof GeodeticCRS) {
-            return ((GeodeticCRS) object).getDatum().getPrimeMeridian();
-        }
-        return null;
+        final GeodeticDatum datum = datum(object);
+        return (datum != null) ? datum.getPrimeMeridian() : null;
     }
 
 

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=1543548&r1=1543547&r2=1543548&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] Tue Nov 19 19:49:23 2013
@@ -22,12 +22,13 @@ import javax.measure.unit.SI;
 import javax.measure.unit.Unit;
 import javax.measure.unit.NonSI;
 import javax.measure.quantity.Length;
-import org.opengis.metadata.citation.Citation;
 import org.opengis.referencing.datum.Ellipsoid;
 import org.opengis.referencing.datum.PrimeMeridian;
+import org.opengis.referencing.datum.GeodeticDatum;
 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 static org.opengis.referencing.IdentifiedObject.NAME_KEY;
 import static org.opengis.referencing.IdentifiedObject.ALIAS_KEY;
@@ -57,20 +58,49 @@ final class StandardDefinitions {
     }
 
     /**
-     * Creates the Greenwich prime meridian. This is the only prime meridian supported by
SIS convenience shortcuts.
-     * If an other prime meridian is desired, the EPSG database shall be used.
+     * Returns a map of properties for the given EPSG code, name and alias.
+     *
+     * @param  code  The EPSG code.
+     * @param  name  The object name.
+     * @param  alias The alias, or {@code null} if none.
+     * @return The map of properties to give to constructors or factory methods.
      */
-    static PrimeMeridian primeMeridian() {
-        final Map<String,Object> properties = new HashMap<>(4);
-        properties.put(NAME_KEY, new NamedIdentifier(Citations.EPSG, "Greenwich")); // Name
is fixed by ISO 19111.
-        properties.put(IDENTIFIERS_KEY, new NamedIdentifier(Citations.EPSG, GREENWICH));
-        return new DefaultPrimeMeridian(properties, 0, NonSI.DEGREE_ANGLE);
+    private static Map<String,Object> properties(final short code, final String name,
final String alias) {
+        final Map<String,Object> map = new HashMap<>(8);
+        map.put(IDENTIFIERS_KEY, new NamedIdentifier(Citations.EPSG, String.valueOf(code)));
+        map.put(NAME_KEY, new NamedIdentifier(Citations.EPSG, name));
+        map.put(ALIAS_KEY, alias); // May be null, which is okay.
+        return map;
+    }
+
+    /**
+     * Creates a geodetic datum from hard-coded values for the given code.
+     *
+     * @param  code      The EPSG code.
+     * @param  ellipsoid The datum ellipsoid.
+     * @param  meridian  The datum prime meridian.
+     * @return The geodetic datum for the given code.
+     */
+    static GeodeticDatum createGeodeticDatum(final short code, final Ellipsoid ellipsoid,
final PrimeMeridian meridian) {
+        final String name;
+        final String alias;
+        switch (code) {
+            case 6326: name = "World Geodetic System 1984";                        alias
= "WGS 84"; break;
+            case 6322: name = "World Geodetic System 1972";                        alias
= "WGS 72"; break;
+            case 6258: name = "European Terrestrial Reference System 1989";        alias
= "ETRS89"; break;
+            case 6269: name = "North American Datum 1983";                         alias
= "NAD83";  break;
+            case 6267: name = "North American Datum 1927";                         alias
= "NAD27";  break;
+            case 6230: name = "European Datum 1950";                               alias
= "ED50";   break;
+            case 6047: name = "Not specified (based on GRS 1980 Authalic Sphere)"; alias
= null;     break;
+            default:   throw new AssertionError(code);
+        }
+        return new DefaultGeodeticDatum(properties(code, name, alias), ellipsoid, meridian);
     }
 
     /**
      * Creates an ellipsoid from hard-coded values for the given code.
      *
-     * @param  code The EPSG or SIS code.
+     * @param  code The EPSG code.
      * @return The ellipsoid for the given code.
      */
     static Ellipsoid createEllipsoid(final short code) {
@@ -89,19 +119,22 @@ final class StandardDefinitions {
             case 7048: name  = "GRS 1980 Authalic Sphere"; ivfDefinitive = false;  semiMajorAxis
= other = AUTHALIC_RADIUS;          break;
             default:   throw new AssertionError(code);
         }
-        final Map<String,Object> map = new HashMap<>(8);
-        final Citation authority;
-        if (code >= 0) {
-            map.put(IDENTIFIERS_KEY, new NamedIdentifier(authority = Citations.EPSG, String.valueOf(code)));
-        } else {
-            authority = Citations.SIS;
-        }
-        map.put(NAME_KEY, new NamedIdentifier(authority, name));
-        map.put(ALIAS_KEY, alias); // May be null, which is okay.
+        final Map<String,Object> map = properties(code, name, alias);
         if (ivfDefinitive) {
             return DefaultEllipsoid.createFlattenedSphere(map, semiMajorAxis, other, unit);
         } else {
             return DefaultEllipsoid.createEllipsoid(map, semiMajorAxis, other, unit);
         }
     }
+
+    /**
+     * Creates the Greenwich prime meridian. This is the only prime meridian supported by
SIS convenience shortcuts.
+     * If an other prime meridian is desired, the EPSG database shall be used.
+     */
+    static PrimeMeridian primeMeridian() {
+        final Map<String,Object> properties = new HashMap<>(4);
+        properties.put(NAME_KEY, new NamedIdentifier(Citations.EPSG, "Greenwich")); // Name
is fixed by ISO 19111.
+        properties.put(IDENTIFIERS_KEY, new NamedIdentifier(Citations.EPSG, GREENWICH));
+        return new DefaultPrimeMeridian(properties, 0, NonSI.DEGREE_ANGLE);
+    }
 }



Mime
View raw message