sis-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From desruisse...@apache.org
Subject svn commit: r1782433 - in /sis/branches/JDK8/core: sis-referencing/src/test/java/org/apache/sis/internal/referencing/provider/ sis-utility/src/main/java/org/apache/sis/measure/
Date Fri, 10 Feb 2017 07:12:38 GMT
Author: desruisseaux
Date: Fri Feb 10 07:12:37 2017
New Revision: 1782433

URL: http://svn.apache.org/viewvc?rev=1782433&view=rev
Log:
Complete TransverseMercator.Zoned test, and add Latitude and Longitude convenience constructors
from a DirectPosition.

Modified:
    sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/internal/referencing/provider/TransverseMercatorTest.java
    sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/measure/Angle.java
    sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/measure/Latitude.java
    sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/measure/Longitude.java

Modified: sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/internal/referencing/provider/TransverseMercatorTest.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/internal/referencing/provider/TransverseMercatorTest.java?rev=1782433&r1=1782432&r2=1782433&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/internal/referencing/provider/TransverseMercatorTest.java
[UTF-8] (original)
+++ sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/internal/referencing/provider/TransverseMercatorTest.java
[UTF-8] Fri Feb 10 07:12:37 2017
@@ -37,7 +37,7 @@ import static org.junit.Assert.*;
  */
 public final strictfp class TransverseMercatorTest extends TestCase {
     /**
-     * Tests {@link TransverseMercator#zone(double)}.
+     * Tests {@link TransverseMercator.Zoner#zone(double)}.
      */
     @Test
     public void testZone() {
@@ -47,7 +47,7 @@ public final strictfp class TransverseMe
     }
 
     /**
-     * Tests {@link TransverseMercator#centralMeridian(int)}.
+     * Tests {@link TransverseMercator.Zoner#centralMeridian(int)}.
      */
     @Test
     public void testCentralMeridian() {
@@ -57,25 +57,29 @@ public final strictfp class TransverseMe
     }
 
     /**
-     * Tests {@link TransverseMercator#setParameters(ParameterValueGroup, double, boolean,
boolean)}.
+     * Tests {@link TransverseMercator.Zoner#setParameters(ParameterValueGroup, boolean,
double, double)}
+     * followed by {@link TransverseMercator.Zoner#zone(ParameterValueGroup)}.
      */
     @Test
     @DependsOnMethod({
         "testZone",
         "testCentralMeridian"
     })
-    public void testCreate() {
+    public void testSetParameters() {
         final ParameterValueGroup p = TransverseMercator.PARAMETERS.createValue();
         assertEquals("UTM zone 10N", TransverseMercator.Zoner.UTM.setParameters(p, true,
0, -122));
         assertEquals(Constants.CENTRAL_MERIDIAN, -123, p.parameter(Constants.CENTRAL_MERIDIAN).doubleValue(),
STRICT);
         assertEquals(Constants.FALSE_NORTHING, 0, p.parameter(Constants.FALSE_NORTHING).doubleValue(),
STRICT);
+        assertEquals("UTM.zone(parameters)", 10, TransverseMercator.Zoner.UTM.zone(p));
 
         assertEquals("Transverse Mercator", TransverseMercator.Zoner.UTM.setParameters(p,
false, 0, -122));
         assertEquals(Constants.CENTRAL_MERIDIAN, -122, p.parameter(Constants.CENTRAL_MERIDIAN).doubleValue(),
STRICT);
         assertEquals(Constants.FALSE_NORTHING, 0, p.parameter(Constants.FALSE_NORTHING).doubleValue(),
STRICT);
+        assertEquals("UTM.zone(parameters)", 0, TransverseMercator.Zoner.UTM.zone(p));
 
         assertEquals("UTM zone 10S", TransverseMercator.Zoner.UTM.setParameters(p, false,
-0.0, -123));
         assertEquals(Constants.CENTRAL_MERIDIAN, -123, p.parameter(Constants.CENTRAL_MERIDIAN).doubleValue(),
STRICT);
         assertEquals(Constants.FALSE_NORTHING, 10000000, p.parameter(Constants.FALSE_NORTHING).doubleValue(),
STRICT);
+        assertEquals("UTM.zone(parameters)", -10, TransverseMercator.Zoner.UTM.zone(p));
     }
 }

Modified: sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/measure/Angle.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/measure/Angle.java?rev=1782433&r1=1782432&r2=1782433&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/measure/Angle.java [UTF-8]
(original)
+++ sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/measure/Angle.java [UTF-8]
Fri Feb 10 07:12:37 2017
@@ -23,7 +23,16 @@ import java.util.FormattableFlags;
 import java.text.Format;
 import java.text.ParseException;
 import java.io.Serializable;
+import javax.measure.Unit;
+import javax.measure.IncommensurableException;
+import org.opengis.geometry.DirectPosition;
+import org.opengis.referencing.cs.AxisDirection;
+import org.opengis.referencing.cs.CoordinateSystem;
+import org.opengis.referencing.cs.CoordinateSystemAxis;
+import org.opengis.referencing.crs.CoordinateReferenceSystem;
 import org.apache.sis.internal.util.Utilities;
+import org.apache.sis.util.resources.Errors;
+import org.apache.sis.util.Classes;
 
 import static java.lang.Double.doubleToLongBits;
 import static org.apache.sis.math.MathFunctions.isNegative;
@@ -58,7 +67,7 @@ import static org.apache.sis.math.MathFu
  *
  * @author  Martin Desruisseaux (MPO, IRD, Geomatys)
  * @since   0.3
- * @version 0.3
+ * @version 0.8
  * @module
  *
  * @see Latitude
@@ -132,6 +141,47 @@ public class Angle implements Comparable
     }
 
     /**
+     * Returns the angular value of the axis having the given direction.
+     * This helper method is used for subclass constructors expecting a {@link DirectPosition}
argument.
+     *
+     * @param  position  the position from which to get an angular value.
+     * @param  positive  axis direction of positive values.
+     * @param  negative  axis direction of negative values.
+     * @return angular value in degrees.
+     * @throws IllegalArgumentException if the given coordinate it not associated to a CRS,
+     *         or if no axis oriented toward the given directions is found, or if that axis
+     *         does not use {@linkplain Units#isAngular angular units}.
+     */
+    static double valueOf(final DirectPosition position, final AxisDirection positive, final
AxisDirection negative) {
+        final CoordinateReferenceSystem crs = position.getCoordinateReferenceSystem();
+        if (crs == null) {
+            throw new IllegalArgumentException(Errors.format(Errors.Keys.UnspecifiedCRS));
+        }
+        final CoordinateSystem cs = crs.getCoordinateSystem();
+        final int dimension = cs.getDimension();
+        IncommensurableException cause = null;
+        for (int i=0; i<dimension; i++) {
+            final CoordinateSystemAxis axis = cs.getAxis(i);
+            final AxisDirection dir = axis.getDirection();
+            final boolean isPositive = dir.equals(positive);
+            if (isPositive || dir.equals(negative)) {
+                double value = position.getOrdinate(i);
+                if (!isPositive) value = -value;
+                final Unit<?> unit = axis.getUnit();
+                if (unit != Units.DEGREE) try {
+                    value = unit.getConverterToAny(Units.DEGREE).convert(value);
+                } catch (IncommensurableException e) {
+                    cause = e;
+                    break;
+                }
+                return value;
+            }
+        }
+        throw new IllegalArgumentException(Errors.format(Errors.Keys.IllegalCRSType_1,
+                Classes.getLeafInterfaces(crs.getClass(), CoordinateReferenceSystem.class)[0]),
cause);
+    }
+
+    /**
      * Returns the angle value in decimal degrees.
      *
      * @return the angle value in decimal degrees.

Modified: sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/measure/Latitude.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/measure/Latitude.java?rev=1782433&r1=1782432&r2=1782433&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/measure/Latitude.java
[UTF-8] (original)
+++ sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/measure/Latitude.java
[UTF-8] Fri Feb 10 07:12:37 2017
@@ -16,6 +16,9 @@
  */
 package org.apache.sis.measure;
 
+import org.opengis.geometry.DirectPosition;
+import org.opengis.referencing.cs.AxisDirection;
+
 
 /**
  * A latitude angle in decimal degrees.
@@ -47,7 +50,7 @@ package org.apache.sis.measure;
  *
  * @author  Martin Desruisseaux (MPO, IRD, Geomatys)
  * @since   0.3
- * @version 0.4
+ * @version 0.8
  * @module
  *
  * @see Longitude
@@ -104,6 +107,29 @@ public final class Latitude extends Angl
     }
 
     /**
+     * Constructs a newly allocated object containing the latitude value of the given position.
+     * For this method, the latitude value is defined as the angular value associated to
the first axis
+     * oriented toward {@linkplain AxisDirection#NORTH North} or {@linkplain AxisDirection#SOUTH
South}.
+     * Note that this is not necessarily the <cite>geodetic latitudes</cite>
used in
+     * {@linkplain org.apache.sis.referencing.crs.DefaultGeographicCRS geographic CRS};
+     * it may also be <cite>geocentric latitudes</cite>.
+     *
+     * <p>If the axis direction is South, then the sign of the ordinate value is inverted.
+     * If the ordinate value uses another angular units than {@linkplain Units#DEGREE degrees},
+     * then a unit conversion is applied.</p>
+     *
+     * @param  position  the coordinate from which to extract the latitude value in degrees.
+     * @throws IllegalArgumentException if the given coordinate it not associated to a CRS,
+     *         or if no axis oriented toward North or South is found, or if that axis does
+     *         not use {@linkplain Units#isAngular angular units}.
+     *
+     * @since 0.8
+     */
+    public Latitude(final DirectPosition position) throws IllegalArgumentException {
+        super(valueOf(position, AxisDirection.NORTH, AxisDirection.SOUTH));
+    }
+
+    /**
      * Returns the hemisphere character for an angle of the given sign.
      * This is used only by {@link #toString()}, not by {@link AngleFormat}.
      */

Modified: sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/measure/Longitude.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/measure/Longitude.java?rev=1782433&r1=1782432&r2=1782433&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/measure/Longitude.java
[UTF-8] (original)
+++ sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/measure/Longitude.java
[UTF-8] Fri Feb 10 07:12:37 2017
@@ -16,6 +16,10 @@
  */
 package org.apache.sis.measure;
 
+import static org.apache.sis.measure.Angle.valueOf;
+import org.opengis.geometry.DirectPosition;
+import org.opengis.referencing.cs.AxisDirection;
+
 
 /**
  * A longitude angle in decimal degrees.
@@ -32,7 +36,7 @@ package org.apache.sis.measure;
  *
  * @author  Martin Desruisseaux (MPO, IRD, Geomatys)
  * @since   0.3
- * @version 0.4
+ * @version 0.8
  * @module
  *
  * @see Latitude
@@ -90,6 +94,29 @@ public final class Longitude extends Ang
     }
 
     /**
+     * Constructs a newly allocated object containing the longitude value of the given position.
+     * For this method, the longitude value is defined as the angular value associated to
the first axis
+     * oriented toward {@linkplain AxisDirection#EAST East} or {@linkplain AxisDirection#WEST
West}.
+     * Note that this is not necessarily the <cite>geodetic longitudes</cite>
used in
+     * {@linkplain org.apache.sis.referencing.crs.DefaultGeographicCRS geographic CRS};
+     * it may also be <cite>geocentric longitudes</cite>.
+     *
+     * <p>If the axis direction is West, then the sign of the ordinate value is inverted.
+     * If the ordinate value uses another angular units than {@linkplain Units#DEGREE degrees},
+     * then a unit conversion is applied.</p>
+     *
+     * @param  position  the coordinate from which to extract the longitude value in degrees.
+     * @throws IllegalArgumentException if the given coordinate it not associated to a CRS,
+     *         or if no axis oriented toward East or West is found, or if that axis does
+     *         not use {@linkplain Units#isAngular angular units}.
+     *
+     * @since 0.8
+     */
+    public Longitude(final DirectPosition position) throws IllegalArgumentException {
+        super(valueOf(position, AxisDirection.EAST, AxisDirection.WEST));
+    }
+
+    /**
      * Returns the hemisphere character for an angle of the given sign.
      * This is used only by {@link #toString()}, not by {@link AngleFormat}.
      */



Mime
View raw message