sis-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From desruisse...@apache.org
Subject svn commit: r1649623 - in /sis/branches/JDK8/core/sis-referencing/src: main/java/org/apache/sis/geometry/ main/java/org/apache/sis/internal/referencing/ main/java/org/apache/sis/referencing/ main/java/org/apache/sis/referencing/crs/ main/java/org/apach...
Date Mon, 05 Jan 2015 19:32:53 GMT
Author: desruisseaux
Date: Mon Jan  5 19:32:53 2015
New Revision: 1649623

URL: http://svn.apache.org/r1649623
Log:
Clarify in the AxesConvention contract that we do not rotate the prime meridian.
Instead provide two methods which, used together, simplify a little bit the task of handling
longitude rotation:
- CRS.getGreenwichLongitude(GeodeticCRS) which take care of converting the prime meridian
to angular degrees.
- GeneralEnvelope.translate(double...)

Modified:
    sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/geometry/GeneralEnvelope.java
    sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/internal/referencing/ReferencingUtilities.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/crs/DefaultCompoundCRS.java
    sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/cs/AxesConvention.java
    sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/datum/DefaultGeodeticDatum.java
    sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/datum/package-info.java
    sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/geometry/GeneralEnvelopeTest.java
    sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/internal/referencing/ReferencingUtilitiesTest.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/datum/HardCodedDatum.java

Modified: sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/geometry/GeneralEnvelope.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/geometry/GeneralEnvelope.java?rev=1649623&r1=1649622&r2=1649623&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/geometry/GeneralEnvelope.java
[UTF-8] (original)
+++ sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/geometry/GeneralEnvelope.java
[UTF-8] Mon Jan  5 19:32:53 2015
@@ -112,7 +112,7 @@ import static org.apache.sis.math.MathFu
  * @author  Martin Desruisseaux (IRD, Geomatys)
  * @author  Johann Sorel (Geomatys)
  * @since   0.3 (derived from geotk-2.4)
- * @version 0.3
+ * @version 0.5
  * @module
  *
  * @see Envelope2D
@@ -440,6 +440,32 @@ public class GeneralEnvelope extends Arr
     }
 
     /**
+     * Translates the envelope by the given vector. For every dimension <var>i</var>,
the
+     * {@linkplain #getLower(int) lower} and {@linkplain #getUpper(int) upper} values are
+     * increased by {@code vector[i]}.
+     *
+     * <p>This method does not check if the translation result is inside the coordinate
system domain
+     * (e.g. [-180 … +180]° of longitude). Callers can normalize the envelope when desired
by call to
+     * the {@link #normalize()} method.</p>
+     *
+     * @param vector The translation vector. The length of this array shall be equal to this
envelope
+     *        {@linkplain #getDimension() dimension}.
+     *
+     * @since 0.5
+     */
+    public void translate(final double... vector) {
+        ensureNonNull("vector", vector);
+        final int beginIndex = beginIndex();
+        ensureDimensionMatches("vector", endIndex() - beginIndex, vector);
+        final int upperIndex = beginIndex + (ordinates.length >>> 1);
+        for (int i=0; i<vector.length; i++) {
+            final double t = vector[i];
+            ordinates[beginIndex + i] += t;
+            ordinates[upperIndex + i] += t;
+        }
+    }
+
+    /**
      * Adds to this envelope a point of the given array.
      * This method does not check for anti-meridian spanning. It is invoked only
      * by the {@link Envelopes} transform methods, which build "normal" envelopes.

Modified: sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/internal/referencing/ReferencingUtilities.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/internal/referencing/ReferencingUtilities.java?rev=1649623&r1=1649622&r2=1649623&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/internal/referencing/ReferencingUtilities.java
[UTF-8] (original)
+++ sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/internal/referencing/ReferencingUtilities.java
[UTF-8] Mon Jan  5 19:32:53 2015
@@ -19,24 +19,24 @@ package org.apache.sis.internal.referenc
 import java.util.Collection;
 import java.util.logging.Logger;
 import javax.measure.unit.Unit;
+import javax.measure.quantity.Angle;
 import org.opengis.annotation.UML;
 import org.opengis.annotation.Specification;
 import org.opengis.referencing.cs.*;
 import org.opengis.referencing.crs.*;
-import org.opengis.referencing.datum.Datum;
-import org.opengis.referencing.datum.GeodeticDatum;
+import org.opengis.referencing.datum.PrimeMeridian;
 import org.apache.sis.util.Static;
 import org.apache.sis.util.Utilities;
 import org.apache.sis.util.logging.Logging;
 import org.apache.sis.util.resources.Errors;
 import org.apache.sis.internal.jaxb.Context;
 import org.apache.sis.referencing.CommonCRS;
+import org.apache.sis.referencing.datum.DefaultPrimeMeridian;
 import org.apache.sis.referencing.crs.DefaultGeographicCRS;
 import org.apache.sis.referencing.cs.AxesConvention;
-import org.apache.sis.referencing.datum.DefaultGeodeticDatum;
 
 import static java.util.Collections.singletonMap;
-import static org.opengis.referencing.IdentifiedObject.NAME_KEY;
+import static org.apache.sis.internal.util.Numerics.epsilonEqual;
 
 
 /**
@@ -167,15 +167,11 @@ public final class ReferencingUtilities
     }
 
     /**
-     * Derives a geographic CRS with (<var>longitude</var>, <var>latitude</var>)
axis order
-     * in decimal degrees, relative to Greenwich. If no such CRS can be obtained of created,
-     * returns null.
-     *
-     * <p>This method is similar to the use of {@link AxesConvention#NORMALIZED} except
for the following:</p>
-     * <ul>
-     *   <li>The datum prime meridian is set to Greenwich.</li>
-     *   <li>This method does not require an Apache SIS implementation of the CRS object.</li>
-     * </ul>
+     * Derives a geographic CRS with (<var>longitude</var>, <var>latitude</var>)
axis order in decimal degrees.
+     * If no such CRS can be obtained or created, returns {@code null}.
+     *
+     * <p>This method does not set the prime meridian to Greenwich.
+     * Meridian rotation, if needed, shall be performed by the caller.</p>
      *
      * @param  crs A source CRS, or {@code null}.
      * @return A two-dimensional geographic CRS with standard axes, or {@code null} if none.
@@ -189,16 +185,11 @@ public final class ReferencingUtilities
         while (crs instanceof GeneralDerivedCRS) {
             crs = ((GeneralDerivedCRS) crs).getBaseCRS();
         }
-        /*
-         * At this point we usually have a GeographicCRS, but it could also be a GeocentricCRS.
-         * In any case if the datum does not have the Greenwich prime meridian, we need to
fix.
-         */
         if (crs instanceof GeodeticCRS) {
-            GeodeticDatum datum = ((GeodeticCRS) crs).getDatum();
-            if (datum.getPrimeMeridian().getGreenwichLongitude() != 0) {
-                datum = new DefaultGeodeticDatum(singletonMap(NAME_KEY, datum.getName().getCode()),
-                        datum.getEllipsoid(), CommonCRS.WGS84.primeMeridian());
-            } else if (crs instanceof DefaultGeographicCRS) {
+            /*
+             * At this point we usually have a GeographicCRS, but it could also be a GeocentricCRS.
+             */
+            if (crs instanceof DefaultGeographicCRS) {
                 return ((DefaultGeographicCRS) crs).forConvention(AxesConvention.NORMALIZED);
             }
             final CoordinateSystem cs = CommonCRS.defaultGeographic().getCoordinateSystem();
@@ -206,7 +197,7 @@ public final class ReferencingUtilities
                 return (GeographicCRS) crs;
             }
             return new DefaultGeographicCRS(singletonMap(DefaultGeographicCRS.NAME_KEY, crs.getName().getCode()),
-                    datum, (EllipsoidalCS) cs);
+                    ((GeodeticCRS) crs).getDatum(), (EllipsoidalCS) cs);
         }
         if (crs instanceof CompoundCRS) {
             for (final CoordinateReferenceSystem e : ((CompoundCRS) crs).getComponents())
{
@@ -220,6 +211,46 @@ public final class ReferencingUtilities
     }
 
     /**
+     * Returns the longitude value relative to the Greenwich Meridian, expressed in the specified
units.
+     * This method provides the same functionality than {@link DefaultPrimeMeridian#getGreenwichLongitude(Unit)},
+     * but on arbitrary implementation.
+     *
+     * @param  primeMeridian The prime meridian from which to get the Greenwich longitude.
+     * @param  unit The unit for the prime meridian to return.
+     * @return The prime meridian in the given units.
+     *
+     * @see DefaultPrimeMeridian#getGreenwichLongitude(Unit)
+     */
+    public static double getGreenwichLongitude(final PrimeMeridian primeMeridian, final Unit<Angle>
unit) {
+        if (primeMeridian instanceof DefaultPrimeMeridian) { // Maybe the user overrode some
methods.
+            return ((DefaultPrimeMeridian) primeMeridian).getGreenwichLongitude(unit);
+        } else {
+            return primeMeridian.getAngularUnit().getConverterTo(unit).convert(primeMeridian.getGreenwichLongitude());
+        }
+    }
+
+    /**
+     * Returns {@code true} if the Greenwich longitude of the {@code actual} prime meridian
is equals to the
+     * Greenwich longitude of the {@code expected} prime meridian. The comparison is performed
in unit of the
+     * expected prime meridian.
+     *
+     * @param expected The expected prime meridian, or {@code null}.
+     * @param actual The actual prime meridian, or {@code null}.
+     * @return {@code true} if both prime meridian have the same Greenwich longitude,
+     *         in unit of the expected prime meridian.
+     */
+    public static boolean isGreenwichLongitudeEquals(final PrimeMeridian expected, final
PrimeMeridian actual) {
+        if (expected == actual) {
+            return true;
+        }
+        if (expected == null || actual == null) {
+            return false;
+        }
+        return epsilonEqual(expected.getGreenwichLongitude(),
+                getGreenwichLongitude(actual, expected.getAngularUnit()));
+    }
+
+    /**
      * Ensures that the given argument value is {@code false}. This method is invoked by
private setter methods,
      * which are themselves invoked by JAXB at unmarshalling time. Invoking this method from
those setter methods
      * serves two purposes:

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=1649623&r1=1649622&r2=1649623&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] Mon Jan  5 19:32:53 2015
@@ -20,6 +20,7 @@ import java.util.Map;
 import java.util.List;
 import java.util.ArrayList;
 import java.util.Collections;
+import javax.measure.unit.NonSI;
 import org.opengis.util.FactoryException;
 import org.opengis.util.NoSuchIdentifierException;
 import org.opengis.referencing.NoSuchAuthorityCodeException;
@@ -31,6 +32,7 @@ import org.opengis.referencing.crs.Singl
 import org.opengis.referencing.crs.CompoundCRS;
 import org.opengis.referencing.crs.CoordinateReferenceSystem;
 import org.opengis.referencing.crs.CRSAuthorityFactory;
+import org.opengis.referencing.crs.GeodeticCRS;
 import org.opengis.referencing.crs.GeographicCRS;
 import org.opengis.referencing.crs.ProjectedCRS;
 import org.opengis.referencing.crs.TemporalCRS;
@@ -485,4 +487,20 @@ check:      while (lower != 0 || upper !
         }
         return crs;
     }
+
+    /**
+     * Returns the Greenwich longitude of the prime meridian of the given CRS in degrees.
+     * If the prime meridian uses an other unit than degrees, then the value will be converted.
+     *
+     * @param  crs The coordinate reference system from which to get the prime meridian.
+     * @return The Greenwich longitude (in degrees) of the prime meridian of the given CRS.
+     *
+     * @since 0.5
+     *
+     * @see org.apache.sis.referencing.datum.DefaultPrimeMeridian#getGreenwichLongitude(Unit)
+     */
+    public static double getGreenwichLongitude(final GeodeticCRS crs) {
+        ArgumentChecks.ensureNonNull("crs", crs);
+        return ReferencingUtilities.getGreenwichLongitude(crs.getDatum().getPrimeMeridian(),
NonSI.DEGREE_ANGLE);
+    }
 }

Modified: sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/crs/DefaultCompoundCRS.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/crs/DefaultCompoundCRS.java?rev=1649623&r1=1649622&r2=1649623&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/crs/DefaultCompoundCRS.java
[UTF-8] (original)
+++ sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/crs/DefaultCompoundCRS.java
[UTF-8] Mon Jan  5 19:32:53 2015
@@ -328,6 +328,10 @@ public class DefaultCompoundCRS extends
     /**
      * {@inheritDoc}
      *
+     * <p>If the given convention is {@link AxesConvention#CONVENTIONALLY_ORIENTED}
or
+     * {@link AxesConvention#NORMALIZED}, then this method will also reorder the components
+     * with horizontal CRS (geodetic or projected) first, then vertical CRS, then temporal
CRS.</p>
+     *
      * @return {@inheritDoc}
      */
     @Override
@@ -337,8 +341,8 @@ public class DefaultCompoundCRS extends
         if (crs == null) {
             crs = this;
             boolean changed = false;
-            final List<? extends CoordinateReferenceSystem> components =
-                    (convention != AxesConvention.NORMALIZED) ? this.components : singles;
+            final boolean reorderCRS = convention.ordinal() <= AxesConvention.CONVENTIONALLY_ORIENTED.ordinal();
+            final List<? extends CoordinateReferenceSystem> components = reorderCRS
? singles : this.components;
             final CoordinateReferenceSystem[] newComponents = new CoordinateReferenceSystem[components.size()];
             for (int i=0; i<newComponents.length; i++) {
                 CoordinateReferenceSystem component = components.get(i);
@@ -350,7 +354,7 @@ public class DefaultCompoundCRS extends
                 newComponents[i] = component;
             }
             if (changed) {
-                if (convention == AxesConvention.NORMALIZED) {
+                if (reorderCRS) {
                     Arrays.sort(newComponents, SubTypes.BY_TYPE); // This array typically
has less than 4 elements.
                 }
                 crs = new DefaultCompoundCRS(IdentifiedObjects.getProperties(this, IDENTIFIERS_KEY),
newComponents);

Modified: sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/cs/AxesConvention.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/cs/AxesConvention.java?rev=1649623&r1=1649622&r2=1649623&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/cs/AxesConvention.java
[UTF-8] (original)
+++ sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/cs/AxesConvention.java
[UTF-8] Mon Jan  5 19:32:53 2015
@@ -34,10 +34,10 @@ import org.opengis.referencing.cs.AxisDi
  *   <tr>
  *     <th>Property</th>
  *     <th>Example</th>
- *     <th>{@linkplain #NORMALIZED}</th>
- *     <th>{@linkplain #CONVENTIONALLY_ORIENTED}</th>
- *     <th>{@linkplain #RIGHT_HANDED}</th>
- *     <th>{@linkplain #POSITIVE_RANGE}</th>
+ *     <th>{@linkplain #NORMALIZED              Normalized}</th>
+ *     <th>{@linkplain #CONVENTIONALLY_ORIENTED Conventionally<br>oriented}</th>
+ *     <th>{@linkplain #RIGHT_HANDED            Right<br>handed}</th>
+ *     <th>{@linkplain #POSITIVE_RANGE          Positive<br>range}</th>
  *   </tr>
  *   <tr>
  *     <td>Axis order</td>
@@ -109,8 +109,8 @@ import org.opengis.referencing.cs.AxisDi
  */
 public enum AxesConvention {
     /**
-     * Axes order, direction, units, prime meridian and range of ordinate values are forced
to commonly used
-     * pre-defined values. This enum represents the following changes to apply on a coordinate
system:
+     * Axes order, direction and units of measure are forced to commonly used pre-defined
values.
+     * This enum represents the following changes to apply on a coordinate system:
      *
      * <ul>
      *   <li>Axes are oriented and ordered as defined for {@link #CONVENTIONALLY_ORIENTED}
coordinate systems.</li>
@@ -123,10 +123,12 @@ public enum AxesConvention {
      *   </li>
      * </ul>
      *
-     * <div class="note"><b>Note:</b>
-     * The rules for normalized coordinate systems may be adjusted in future SIS versions
based on experience gained.
-     * For more predictable results, consider using the {@link #CONVENTIONALLY_ORIENTED}
or {@link #RIGHT_HANDED} enum
-     * instead.</div>
+     * Current implementation does not normalize longitude values to the [-180 … +180]°
range and does not set
+     * the {@linkplain org.apache.sis.referencing.datum.DefaultGeodeticDatum#getPrimeMeridian()
prime meridian} to
+     * Greenwich, because doing so would cause the conversion between old and new coordinate
systems to be non-affine.
+     * Furthermore changing the prime meridian would be a datum change rather than a coordinate
system change.
+     * However those rules may be adjusted in future SIS versions based on experience gained.
+     * For more predictable results, consider using {@link #CONVENTIONALLY_ORIENTED} or {@link
#RIGHT_HANDED} instead.
      *
      * @see org.apache.sis.referencing.CommonCRS#normalizedGeographic()
      */
@@ -215,12 +217,12 @@ public enum AxesConvention {
      * {@linkplain org.apache.sis.referencing.cs.DefaultCoordinateSystemAxis#getRangeMeaning()
range meaning}
      * are shifted to their ranges of positive values. The units of measurement and range
period are unchanged.
      *
-     * <p><b>Usage:</b><br>
+     * {@section Usage}
      * The most frequent usage of this enum is for shifting longitude values from the [-180
… +180]° range
      * to the [0 … 360]° range. However this enum could also be used with climatological
calendars if their
-     * time axis has a wrapround range meaning.</p>
+     * time axis has a wrapround range meaning.
      *
-     * <p><b>Caution:</b><br>
+     * <p><b>Caution:</b>
      * Conversions between the original Coordinate System and new CS compliant to this {@code
POSITIVE_RANGE}
      * may not be affine. For example if an image was spanning the [0 … 360]° range of
longitude values, then
      * a change to the [-180 … +180]° range requires cutting the right side (the side
spanning the [180 … 360]°

Modified: sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/datum/DefaultGeodeticDatum.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/datum/DefaultGeodeticDatum.java?rev=1649623&r1=1649622&r2=1649623&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/datum/DefaultGeodeticDatum.java
[UTF-8] (original)
+++ sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/datum/DefaultGeodeticDatum.java
[UTF-8] Mon Jan  5 19:32:53 2015
@@ -41,10 +41,10 @@ import org.apache.sis.util.ComparisonMod
 import org.apache.sis.io.wkt.Formatter;
 
 import static org.apache.sis.util.Utilities.deepEquals;
-import static org.apache.sis.util.Utilities.equalsIgnoreMetadata;
 import static org.apache.sis.util.ArgumentChecks.ensureNonNull;
 import static org.apache.sis.util.ArgumentChecks.ensureNonNullElement;
 import static org.apache.sis.internal.referencing.WKTUtilities.toFormattable;
+import static org.apache.sis.internal.referencing.ReferencingUtilities.isGreenwichLongitudeEquals;
 
 // Branch-dependent imports
 import java.util.Objects;
@@ -259,7 +259,7 @@ public class DefaultGeodeticDatum extend
                 param = param.clone();
                 param.verify();
                 final GeodeticDatum targetDatum = param.getTargetDatum();
-                if (targetDatum != null && !equalsIgnoreMetadata(primeMeridian, targetDatum.getPrimeMeridian()))
{
+                if (targetDatum != null && !isGreenwichLongitudeEquals(primeMeridian,
targetDatum.getPrimeMeridian())) {
                     throw new IllegalArgumentException(Errors.format(
                             Errors.Keys.MismatchedPrimeMeridianInBWP_1, primeMeridian.getName()));
                 }

Modified: sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/datum/package-info.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/datum/package-info.java?rev=1649623&r1=1649622&r2=1649623&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/datum/package-info.java
[UTF-8] (original)
+++ sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/datum/package-info.java
[UTF-8] Mon Jan  5 19:32:53 2015
@@ -33,6 +33,8 @@
  *   <li>{@link org.apache.sis.referencing.datum.DefaultEllipsoid#getAuthalicRadius()}</li>
  *   <li>{@link org.apache.sis.referencing.datum.DefaultEllipsoid#getEccentricity()}</li>
  *   <li>{@link org.apache.sis.referencing.datum.DefaultEllipsoid#orthodromicDistance(double,
double, double, double)}</li>
+ *   <li>{@link org.apache.sis.referencing.datum.DefaultPrimeMeridian#getGreenwichLongitude(javax.measure.unit.Unit)
+ *       DefaultPrimeMeridian.getGreenwichLongitude(Unit)}</li>
  *   <li>{@link org.apache.sis.referencing.datum.DefaultGeodeticDatum#getBursaWolfParameters()}</li>
  *   <li>{@link org.apache.sis.referencing.datum.DefaultGeodeticDatum#getPositionVectorTransformation
  *       DefaultGeodeticDatum.getPositionVectorTransformation(GeodeticDatum, Extent)}</li>

Modified: sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/geometry/GeneralEnvelopeTest.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/geometry/GeneralEnvelopeTest.java?rev=1649623&r1=1649622&r2=1649623&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/geometry/GeneralEnvelopeTest.java
[UTF-8] (original)
+++ sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/geometry/GeneralEnvelopeTest.java
[UTF-8] Mon Jan  5 19:32:53 2015
@@ -40,7 +40,7 @@ import static org.apache.sis.geometry.Ab
  * @author  Martin Desruisseaux (IRD, Geomatys)
  * @author  Johann Sorel (Geomatys)
  * @since   0.3 (derived from geotk-2.4)
- * @version 0.3
+ * @version 0.5
  * @module
  */
 @DependsOn(AbstractEnvelopeTest.class)
@@ -527,6 +527,18 @@ public strictfp class GeneralEnvelopeTes
     }
 
     /**
+     * Tests {@link GeneralEnvelope#translate(double...)}.
+     *
+     * @since 0.5
+     */
+    @Test
+    public void testTranslate() {
+        final GeneralEnvelope envelope = new GeneralEnvelope(new double[] {4, 5}, new double[]
{8, 7});
+        envelope.translate(2, -4);
+        assertEnvelopeEquals(envelope, 6, 1, 10, 3);
+    }
+
+    /**
      * Tests the {@link GeneralEnvelope#toString()} method.
      */
     @Test

Modified: sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/internal/referencing/ReferencingUtilitiesTest.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/internal/referencing/ReferencingUtilitiesTest.java?rev=1649623&r1=1649622&r2=1649623&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/internal/referencing/ReferencingUtilitiesTest.java
[UTF-8] (original)
+++ sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/internal/referencing/ReferencingUtilitiesTest.java
[UTF-8] Mon Jan  5 19:32:53 2015
@@ -16,11 +16,18 @@
  */
 package org.apache.sis.internal.referencing;
 
+import javax.measure.unit.Unit;
+import javax.measure.unit.NonSI;
 import org.opengis.referencing.cs.*;
+import org.opengis.referencing.datum.PrimeMeridian;
+import org.apache.sis.referencing.datum.DefaultPrimeMeridian;
+import org.apache.sis.referencing.datum.HardCodedDatum;
 import org.apache.sis.test.TestCase;
 import org.junit.Test;
 
 import static org.junit.Assert.*;
+import static java.util.Collections.singletonMap;
+import static org.opengis.referencing.IdentifiedObject.NAME_KEY;
 import static org.apache.sis.internal.referencing.ReferencingUtilities.*;
 
 
@@ -34,6 +41,11 @@ import static org.apache.sis.internal.re
  */
 public final strictfp class ReferencingUtilitiesTest extends TestCase {
     /**
+     * Tolerance threshold for strict floating point comparisons.
+     */
+    private static final double STRICT = 0;
+
+    /**
      * Tests {@link ReferencingUtilities#toWKTType(Class, Class)}.
      */
     @Test
@@ -50,4 +62,33 @@ public final strictfp class ReferencingU
         assertEquals("temporal",    toWKTType(CoordinateSystem.class, TimeCS          .class));
         assertEquals("vertical",    toWKTType(CoordinateSystem.class, VerticalCS      .class));
     }
+
+    /**
+     * Tests {@link ReferencingUtilities#getGreenwichLongitude(PrimeMeridian, Unit)}.
+     */
+    @Test
+    public void testGetGreenwichLongitude() {
+        assertEquals(0,          getGreenwichLongitude(HardCodedDatum.GREENWICH, NonSI.DEGREE_ANGLE),
STRICT);
+        assertEquals(0,          getGreenwichLongitude(HardCodedDatum.GREENWICH, NonSI.GRADE),
       STRICT);
+        assertEquals(2.5969213,  getGreenwichLongitude(HardCodedDatum.PARIS,     NonSI.GRADE),
       STRICT);
+        assertEquals(2.33722917, getGreenwichLongitude(HardCodedDatum.PARIS,     NonSI.DEGREE_ANGLE),
1E-12);
+        assertEquals(2.33720833, getGreenwichLongitude(HardCodedDatum.PARIS_RGS, NonSI.DEGREE_ANGLE),
1E-8);
+        assertEquals(2.596898,   getGreenwichLongitude(HardCodedDatum.PARIS_RGS, NonSI.GRADE),
       1E-6);
+    }
+
+    /**
+     * Tests {@link ReferencingUtilities#isGreenwichLongitudeEquals(PrimeMeridian, PrimeMeridian)}.
+     */
+    @Test
+    public void testIsGreenwichLongitudeEquals() {
+        assertFalse(isGreenwichLongitudeEquals(HardCodedDatum.GREENWICH, HardCodedDatum.PARIS));
+        assertFalse(isGreenwichLongitudeEquals(HardCodedDatum.PARIS, HardCodedDatum.PARIS_RGS));
+        assertFalse(isGreenwichLongitudeEquals(HardCodedDatum.PARIS_RGS, HardCodedDatum.PARIS));
+        /*
+         * Test two prime meridians using different units (Paris in grade and Paris in degrees).
+         */
+        final PrimeMeridian pd = new DefaultPrimeMeridian(singletonMap(NAME_KEY, "Paris"),
2.33722917, NonSI.DEGREE_ANGLE);
+        assertTrue(isGreenwichLongitudeEquals(HardCodedDatum.PARIS, pd));
+        assertTrue(isGreenwichLongitudeEquals(pd, HardCodedDatum.PARIS));
+    }
 }

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=1649623&r1=1649622&r2=1649623&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] Mon Jan  5 19:32:53 2015
@@ -17,6 +17,7 @@
 package org.apache.sis.referencing;
 
 import org.opengis.referencing.crs.CoordinateReferenceSystem;
+import org.opengis.referencing.crs.GeodeticCRS;
 import org.opengis.referencing.crs.SingleCRS;
 import org.opengis.util.FactoryException;
 import org.apache.sis.referencing.crs.DefaultCompoundCRS;
@@ -42,6 +43,11 @@ import static org.apache.sis.test.Assert
 })
 public final strictfp class CRSTest extends TestCase {
     /**
+     * Tolerance threshold for strict floating point comparisons.
+     */
+    private static final double STRICT = 0;
+
+    /**
      * Asserts that the result of {@link CRS#forCode(String)} is the given CRS.
      */
     private static void verifyForCode(final SingleCRS expected, final String code) throws
FactoryException {
@@ -224,4 +230,12 @@ public final strictfp class CRSTest exte
             assertSame("[1…2]", y,  CRS.getComponentAt(xy, 1, 2));
         }
     }
+
+    /**
+     * Tests {@link CRS#getGreenwichLongitude(GeodeticCRS)}.
+     */
+    @Test
+    public void testGetGreenwichLongitude() {
+        assertEquals(0, CRS.getGreenwichLongitude(HardCodedCRS.WGS84), STRICT);
+    }
 }

Modified: sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/referencing/datum/HardCodedDatum.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/referencing/datum/HardCodedDatum.java?rev=1649623&r1=1649622&r2=1649623&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/referencing/datum/HardCodedDatum.java
[UTF-8] (original)
+++ sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/referencing/datum/HardCodedDatum.java
[UTF-8] Mon Jan  5 19:32:53 2015
@@ -35,7 +35,7 @@ import static org.opengis.referencing.Id
  *
  * @author  Martin Desruisseaux (Geomatys)
  * @since   0.4
- * @version 0.4
+ * @version 0.5
  * @module
  */
 public final strictfp class HardCodedDatum {
@@ -43,7 +43,20 @@ public final strictfp class HardCodedDat
      * Greenwich meridian (EPSG:8901), with angular measurements in decimal degrees.
      */
     public static final DefaultPrimeMeridian GREENWICH = new DefaultPrimeMeridian(
-            properties("Greenwich", "8901"), 0, NonSI.DEGREE_ANGLE);;
+            properties("Greenwich", "8901"), 0, NonSI.DEGREE_ANGLE);
+
+    /**
+     * Paris meridian (EPSG:8903), with angular measurements in grad.
+     */
+    public static final DefaultPrimeMeridian PARIS = new DefaultPrimeMeridian(
+            properties("Paris", "8903"), 2.5969213, NonSI.GRADE);
+
+    /**
+     * Old Paris meridian (EPSG:8914) defined as 2°20'13.95"E.
+     * Equivalent to 2.596898 grad (value given by EPSG).
+     */
+    public static final DefaultPrimeMeridian PARIS_RGS = new DefaultPrimeMeridian(
+            properties("Paris RGS", "8914"), 2 + (20 + 13.95/60)/60, NonSI.DEGREE_ANGLE);
 
     /**
      * WGS 1984 datum (EPSG:6326). Prime meridian is Greenwich.



Mime
View raw message