sis-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From desruisse...@apache.org
Subject svn commit: r1558519 - in /sis/branches/JDK7/core/sis-referencing/src: main/java/org/apache/sis/referencing/GeodeticObjects.java main/java/org/apache/sis/referencing/cs/AxesConvention.java test/java/org/apache/sis/referencing/GeodeticObjectsTest.java
Date Wed, 15 Jan 2014 19:06:05 GMT
Author: desruisseaux
Date: Wed Jan 15 19:06:04 2014
New Revision: 1558519

URL: http://svn.apache.org/r1558519
Log:
Added GeodeticObjects.normalizedGeographic() 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/cs/AxesConvention.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=1558519&r1=1558518&r2=1558519&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] Wed Jan 15 19:06:04 2014
@@ -38,8 +38,10 @@ import org.opengis.referencing.datum.Ver
 import org.opengis.referencing.datum.TemporalDatum;
 import org.opengis.referencing.datum.DatumAuthorityFactory;
 import org.opengis.referencing.crs.CRSAuthorityFactory;
+import org.apache.sis.referencing.crs.DefaultGeographicCRS;
 import org.apache.sis.referencing.datum.DefaultVerticalDatum;
 import org.apache.sis.referencing.datum.DefaultTemporalDatum;
+import org.apache.sis.referencing.cs.AxesConvention;
 import org.apache.sis.util.resources.Vocabulary;
 
 import static org.opengis.referencing.IdentifiedObject.NAME_KEY;
@@ -60,7 +62,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.geographic();
+ *   GeographicCRS crs = GeodeticObjects.WGS84.normalizedGeographic();
  * }
  *
  * For each enumeration value, the name of the CRS, datum and ellipsoid objects may or may
not be the same.
@@ -223,10 +225,10 @@ public enum GeodeticObjects {
     /**
      * The EPSG code of the geographic CRS.
      */
-    final short crs;
+    final short geographic;
 
     /**
-     * The EPSG code of the datum. The value is often {@link #crs} + 2000,
+     * The EPSG code of the datum. The value is often {@link #geographic} + 2000,
      * but it doesn't have to be always the case.
      */
     final short datum;
@@ -244,16 +246,23 @@ public enum GeodeticObjects {
     private transient volatile IdentifiedObject cached;
 
     /**
+     * The normalized geographic CRS, created when first needed.
+     *
+     * @see #normalizedGeographic()
+     */
+    private transient volatile GeographicCRS normalized;
+
+    /**
      * Creates a new constant for the given EPSG or SIS codes.
      *
-     * @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 crs, final short datum, final short ellipsoid) {
-        this.crs       = crs;
-        this.datum     = datum;
-        this.ellipsoid = ellipsoid;
+     * @param geographic 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 geographic, final short datum, final short ellipsoid)
{
+        this.geographic = geographic;
+        this.datum      = datum;
+        this.ellipsoid  = ellipsoid;
     }
 
     /**
@@ -272,10 +281,47 @@ 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.
+     * Returns a two-dimensional geographic CRS with axes in the non-standard but computationally
convenient
+     * (<var>longitude</var>, <var>latitude</var>) order. The coordinate
system axes will be oriented toward
+     * {@linkplain AxisDirection#EAST East} and {@linkplain AxisDirection#NORTH North} 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></td></tr>
+     *   <tr><td>ETRS89</td>                   <td>{@link #ETRS89}</td>
<td></td></tr>
+     *   <tr><td>NAD27</td>                    <td>{@link #NAD27}</td>
 <td></td></tr>
+     *   <tr><td>NAD83</td>                    <td>{@link #NAD83}</td>
 <td></td></tr>
+     *   <tr><td>GRS 1980 Authalic Sphere</td> <td>{@link #SPHERE}</td>
<td></td></tr>
+     *   <tr><td>WGS 72</td>                   <td>{@link #WGS72}</td>
 <td></td></tr>
+     *   <tr><td>WGS 84</td>                   <td>{@link #WGS84}</td>
 <td></td></tr>
+     * </table></blockquote>
+     *
+     * @return The geographic CRS with non-standard (<var>longitude</var>, <var>latitude</var>)
axis order.
+     *
+     * @see DefaultGeographicCRS#forConvention(AxesConvention)
+     * @see AxesConvention#NORMALIZED
+     */
+    public GeographicCRS normalizedGeographic() {
+        GeographicCRS object = normalized;
+        if (object == null) {
+            DefaultGeographicCRS crs = DefaultGeographicCRS.castOrCopy(geographic());
+            crs = crs.forConvention(AxesConvention.RIGHT_HANDED); // Equivalent to NORMALIZED
in our cases, but faster.
+            synchronized (this) {
+                object = normalized;
+                if (object == null) {
+                    normalized = object = crs;
+                }
+            }
+        }
+        return object;
+    }
+
+    /**
+     * Returns the two-dimensional geographic CRS with axes in the standard (<var>latitude</var>,
<var>longitude</var>)
+     * order. The coordinate system axes will be 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:
      *
@@ -290,7 +336,7 @@ public enum GeodeticObjects {
      *   <tr><td>WGS 84</td>                   <td>{@link #WGS84}</td>
 <td>4326</td></tr>
      * </table></blockquote>
      *
-     * @return The geographic CRS associated to this constant.
+     * @return The geographic CRS with standard (<var>latitude</var>, <var>longitude</var>)
axis order.
      *
      * @see org.apache.sis.referencing.crs.DefaultGeographicCRS
      * @see CRSAuthorityFactory#createGeographicCRS(String)
@@ -303,7 +349,7 @@ public enum GeodeticObjects {
                 if (object == null) {
                     final CRSAuthorityFactory factory = StandardObjects.crsFactory();
                     if (factory != null) try {
-                        cached = object = factory.createGeographicCRS(String.valueOf(crs));
+                        cached = object = factory.createGeographicCRS(String.valueOf(geographic));
                         return object;
                     } catch (FactoryException e) {
                         StandardObjects.failure(this, "geographic", e);
@@ -319,7 +365,8 @@ public enum GeodeticObjects {
                     } else {
                         cs = WGS84.geographic().getCoordinateSystem();
                     }
-                    object = StandardDefinitions.createGeographicCRS(crs, datum(), cs);
+                    object = StandardDefinitions.createGeographicCRS(geographic, datum(),
cs);
+                    cached = object;
                 }
             }
         }

Modified: sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/cs/AxesConvention.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/cs/AxesConvention.java?rev=1558519&r1=1558518&r2=1558519&view=diff
==============================================================================
--- sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/cs/AxesConvention.java
[UTF-8] (original)
+++ sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/cs/AxesConvention.java
[UTF-8] Wed Jan 15 19:06:04 2014
@@ -113,6 +113,8 @@ public enum AxesConvention {
      *
      * {@note The rules for normalized coordinate systems may be adjusted in future SIS versions
based on experience
      *        gained. For more predictable results, consider using the <code>RIGHT_HANDED</code>
enum instead.}
+     *
+     * @see org.apache.sis.referencing.GeodeticObjects#normalizedGeographic()
      */
     NORMALIZED,
 

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=1558519&r1=1558518&r2=1558519&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] Wed Jan 15 19:06:04 2014
@@ -18,6 +18,7 @@ package org.apache.sis.referencing;
 
 import java.util.Date;
 import org.opengis.referencing.crs.GeographicCRS;
+import org.opengis.referencing.cs.CoordinateSystem;
 import org.opengis.referencing.datum.TemporalDatum;
 import org.opengis.referencing.datum.VerticalDatum;
 import org.opengis.referencing.datum.VerticalDatumType;
@@ -40,7 +41,7 @@ import static org.apache.sis.test.TestUt
  * @module
  */
 @DependsOn({
-  org.apache.sis.referencing.datum.DefaultGeodeticDatumTest.class,
+  org.apache.sis.referencing.crs.DefaultGeodeticCRSTest.class,
   org.apache.sis.referencing.datum.DefaultVerticalDatumTest.class,
   StandardDefinitionsTest.class
 })
@@ -55,9 +56,21 @@ public final strictfp class GeodeticObje
      */
     @Test
     public void testWGS84() {
-        final GeographicCRS crs = GeodeticObjects.WGS84.geographic();
-        Validators.validate(crs);
-        GeodeticObjectVerifier.assertIsWGS84(crs, false, true);
+        final GeographicCRS geographic = GeodeticObjects.WGS84.geographic();
+        Validators.validate(geographic);
+        GeodeticObjectVerifier.assertIsWGS84(geographic, false, true);
+        assertSame("Cached value", geographic, GeodeticObjects.WGS84.geographic());
+        /*
+         * Verifies the variant using (longitude, latitude) axis order.
+         */
+        final GeographicCRS normalized = GeodeticObjects.WGS84.normalizedGeographic();
+        Validators.validate(normalized);
+        assertSame(geographic.getDatum(), normalized.getDatum());
+        final CoordinateSystem φλ = geographic.getCoordinateSystem();
+        final CoordinateSystem λφ = normalized.getCoordinateSystem();
+        assertSame("Longitude", φλ.getAxis(1), λφ.getAxis(0));
+        assertSame("Latitude",  φλ.getAxis(0), λφ.getAxis(1));
+        assertSame("Cached value", normalized, GeodeticObjects.WGS84.normalizedGeographic());
     }
 
     /**



Mime
View raw message