sis-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From desruisse...@apache.org
Subject svn commit: r1782972 - in /sis/branches/JDK8/core/sis-referencing/src: main/java/org/apache/sis/internal/referencing/provider/ main/java/org/apache/sis/referencing/ main/java/org/apache/sis/referencing/gazetteer/ test/java/org/apache/sis/referencing/ga...
Date Tue, 14 Feb 2017 15:06:58 GMT
Author: desruisseaux
Date: Tue Feb 14 15:06:58 2017
New Revision: 1782972

URL: http://svn.apache.org/viewvc?rev=1782972&view=rev
Log:
Begin on-the-fly reprojection before MGRS label encoding (work in progress).

Modified:
    sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/internal/referencing/provider/PolarStereographicA.java
    sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/CommonCRS.java
    sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/gazetteer/MGRSEncoder.java
    sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/gazetteer/MilitaryGridReferenceSystem.java
    sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/referencing/gazetteer/MilitaryGridReferenceSystemTest.java

Modified: sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/internal/referencing/provider/PolarStereographicA.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/internal/referencing/provider/PolarStereographicA.java?rev=1782972&r1=1782971&r2=1782972&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/internal/referencing/provider/PolarStereographicA.java
[UTF-8] (original)
+++ sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/internal/referencing/provider/PolarStereographicA.java
[UTF-8] Tue Feb 14 15:06:58 2017
@@ -17,10 +17,16 @@
 package org.apache.sis.internal.referencing.provider;
 
 import javax.xml.bind.annotation.XmlTransient;
+import org.opengis.parameter.ParameterValueGroup;
 import org.opengis.parameter.ParameterDescriptor;
 import org.opengis.parameter.ParameterDescriptorGroup;
 import org.apache.sis.metadata.iso.citation.Citations;
 import org.apache.sis.parameter.ParameterBuilder;
+import org.apache.sis.internal.referencing.Formulas;
+import org.apache.sis.internal.util.Constants;
+import org.apache.sis.internal.util.Numerics;
+import org.apache.sis.measure.Latitude;
+import org.apache.sis.measure.Units;
 
 
 /**
@@ -101,4 +107,28 @@ public final class PolarStereographicA e
     public PolarStereographicA() {
         super(PARAMETERS);
     }
+
+    /**
+     * If the given parameter values are those of a Universal Polar Stereographic projection,
+     * returns -1 for South pole or +1 for North pole. Otherwise returns 0. It is caller's
+     * responsibility to verify that the operation method is {@value #NAME}.
+     *
+     * @param  group  the Transverse Mercator projection parameters.
+     * @return zone number (positive if North, negative if South),
+     *         or 0 if the given parameters are not for a zoned projection.
+     *
+     * @since 0.8
+     */
+    public static int isUPS(final ParameterValueGroup group) {
+        if (Numerics.epsilonEqual(group.parameter(Constants.SCALE_FACTOR)    .doubleValue(Units.UNITY),
 1, Numerics.COMPARISON_THRESHOLD) &&
+            Numerics.epsilonEqual(group.parameter(Constants.FALSE_EASTING)   .doubleValue(Units.METRE),
 0, Formulas.LINEAR_TOLERANCE) &&
+            Numerics.epsilonEqual(group.parameter(Constants.FALSE_NORTHING)  .doubleValue(Units.METRE),
 0, Formulas.LINEAR_TOLERANCE) &&
+            Numerics.epsilonEqual(group.parameter(Constants.CENTRAL_MERIDIAN).doubleValue(Units.DEGREE),
0, Formulas.ANGULAR_TOLERANCE))
+        {
+            final double φ = group.parameter(Constants.LATITUDE_OF_ORIGIN).doubleValue(Units.DEGREE);
+            if (Numerics.epsilonEqual(φ, Latitude.MAX_VALUE, Formulas.ANGULAR_TOLERANCE))
return +1;
+            if (Numerics.epsilonEqual(φ, Latitude.MIN_VALUE, Formulas.ANGULAR_TOLERANCE))
return -1;
+        }
+        return 0;
+    }
 }

Modified: sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/CommonCRS.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/CommonCRS.java?rev=1782972&r1=1782971&r2=1782972&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/CommonCRS.java
[UTF-8] (original)
+++ sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/CommonCRS.java
[UTF-8] Tue Feb 14 15:06:58 2017
@@ -33,6 +33,7 @@ import org.opengis.referencing.crs.Tempo
 import org.opengis.referencing.crs.GeographicCRS;
 import org.opengis.referencing.crs.GeocentricCRS;
 import org.opengis.referencing.crs.ProjectedCRS;
+import org.opengis.referencing.crs.SingleCRS;
 import org.opengis.referencing.cs.TimeCS;
 import org.opengis.referencing.cs.VerticalCS;
 import org.opengis.referencing.cs.CartesianCS;
@@ -69,6 +70,7 @@ import org.apache.sis.util.resources.Voc
 import org.apache.sis.util.logging.Logging;
 import org.apache.sis.util.ArgumentChecks;
 import org.apache.sis.util.Exceptions;
+import org.apache.sis.util.Utilities;
 import org.apache.sis.math.MathFunctions;
 import org.apache.sis.measure.Latitude;
 import org.apache.sis.measure.Units;
@@ -416,6 +418,31 @@ public enum CommonCRS {
     }
 
     /**
+     * Returns the value for the given datum or CRS, or {@code null} if none.
+     * The given object can be either an instance of {@link GeodeticDatum},
+     * or an instance of {@link SingleCRS} associated to a geodetic datum.
+     *
+     * @param  object  the object (datum or CRS) for which to get a {@code CommonCRS} value.
+     * @return the {@code CommonCRS} value for the given geodetic object, or {@code null}
if none.
+     *
+     * @see #datum()
+     * @since 0.8
+     */
+    public static CommonCRS forDatum(IdentifiedObject object) {
+        if (object instanceof SingleCRS) {
+            object = ((SingleCRS) object).getDatum();
+        }
+        if (object instanceof GeodeticDatum) {
+            for (final CommonCRS c : values()) {
+                if (Utilities.equalsIgnoreMetadata(c.datum(), object)) {
+                    return c;
+                }
+            }
+        }
+        return null;
+    }
+
+    /**
      * Returns the default two-dimensional normalized geographic CRS.
      * The CRS returned by this method has the following properties:
      *
@@ -724,6 +751,7 @@ public enum CommonCRS {
      *
      * @return the geodetic datum associated to this enum.
      *
+     * @see #forDatum(GeodeticDatum)
      * @see org.apache.sis.referencing.datum.DefaultGeodeticDatum
      */
     public GeodeticDatum datum() {

Modified: sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/gazetteer/MGRSEncoder.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/gazetteer/MGRSEncoder.java?rev=1782972&r1=1782971&r2=1782972&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/gazetteer/MGRSEncoder.java
[UTF-8] (original)
+++ sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/gazetteer/MGRSEncoder.java
[UTF-8] Tue Feb 14 15:06:58 2017
@@ -19,20 +19,23 @@ package org.apache.sis.referencing.gazet
 import org.opengis.util.FactoryException;
 import org.opengis.geometry.DirectPosition;
 import org.opengis.referencing.crs.CoordinateReferenceSystem;
+import org.opengis.referencing.crs.GeographicCRS;
 import org.opengis.referencing.crs.ProjectedCRS;
 import org.opengis.referencing.operation.Projection;
 import org.opengis.referencing.operation.OperationMethod;
 import org.opengis.referencing.operation.MathTransform;
 import org.opengis.referencing.operation.TransformException;
 import org.apache.sis.internal.referencing.provider.TransverseMercator;
-import org.apache.sis.referencing.crs.DefaultGeographicCRS;
+import org.apache.sis.internal.referencing.provider.PolarStereographicA;
 import org.apache.sis.referencing.crs.DefaultProjectedCRS;
 import org.apache.sis.referencing.cs.AxesConvention;
 import org.apache.sis.referencing.IdentifiedObjects;
+import org.apache.sis.referencing.CommonCRS;
 import org.apache.sis.referencing.CRS;
 import org.apache.sis.math.MathFunctions;
 import org.apache.sis.util.resources.Errors;
 import org.apache.sis.util.StringBuilders;
+import org.apache.sis.util.Utilities;
 
 
 /**
@@ -69,6 +72,16 @@ final class MGRSEncoder {
     private static final double UTM_NORTH_BOUNDS = 84;
 
     /**
+     * Special {@link #crsZone} value for the UPS South (Universal Polar Stereographic) projection.
+     */
+    private static final int SOUTH_POLE = -1000;
+
+    /**
+     * Special {@link #crsZone} value for the UPS North (Universal Polar Stereographic) projection.
+     */
+    private static final int NORTH_POLE = 1000;
+
+    /**
      * Size of the 100,000-meter squares.
      */
     static final double GRID_SQUARE_SIZE = 100_000;
@@ -108,23 +121,33 @@ final class MGRSEncoder {
     private static final char EXCLUDE_O = 'O';
 
     /**
-     * UTM zone of position CRS (negative for South hemisphere), or 0 if that CRS is not
an UTM projection.
-     * Note that this is not necessarily the same zone than the one to use for formatting
any given coordinate
-     * in that projected CRS, since the {@link #zone(double, char)} method has special rules
for some latitudes.
+     * The datum of the CRS given at construction time, or {@code null} if unsupported.
+     * Only the datums enumerated in {@link CommonCRS} are currently supported.
      */
-    private int crsZone;
+    private final CommonCRS datum;
+
+    /**
+     * UTM zone of position CRS (negative for South hemisphere), or {@value #NORTH_POLE}
or {@value #SOUTH_POLE}
+     * if the CRS is a Universal Polar Stereographic projection, or 0 if the CRS is not a
recognized projection.
+     * Note that this is not necessarily the same zone than the one to use for formatting
any given coordinate in
+     * that projected CRS, since the {@link #zone(int, double, char)} method has special
rules for some latitudes.
+     */
+    private final int crsZone;
 
     /**
      * Coordinate conversion from the position CRS to a CRS of the same type but with normalized
axes.
      * Axis directions are (East, North) and axis units are metres or degrees, depending
on the CRS type.
+     *
+     * <p>This transform should perform only simple operation like swapping axis order
an unit conversions.
+     * It should not perform more complex operations that would require to go back to geographic
coordinates.</p>
      */
-    private MathTransform toNormalized;
+    private final MathTransform toNormalized;
 
     /**
-     * Coordinate conversion from the <em>normalized</em> position CRS to a normalized
geographic CRS.
-     * Axis directions are (East, North) and axis units are degrees.
+     * Coordinate conversion from the <em>normalized</em> position CRS to a geographic
CRS.
+     * Axis directions are (North, East) as in EPSG geodetic dataset and axis units are degrees.
      */
-    private MathTransform toGeographic;
+    private final MathTransform toGeographic;
 
     /**
      * Creates a new converter from direct positions to MGRS labels.
@@ -133,36 +156,57 @@ final class MGRSEncoder {
         if (crs == null) {
             throw new IllegalArgumentException(Errors.format(Errors.Keys.UnspecifiedCRS));
         }
+        datum = CommonCRS.forDatum(crs);
+        if (datum == null) {
+            throw new TransformException("Unsupported datum");      // TODO: localize
+        }
         if (crs instanceof ProjectedCRS) {
-            Projection projection = ((ProjectedCRS) crs).getConversionFromBase();
+            ProjectedCRS  projCRS = (ProjectedCRS) crs;
+            Projection projection = projCRS.getConversionFromBase();
             final OperationMethod method = projection.getMethod();
             if (IdentifiedObjects.isHeuristicMatchForName(method, TransverseMercator.NAME))
{
                 crsZone = TransverseMercator.Zoner.UTM.zone(projection.getParameterValues());
-                if (crsZone != 0) {
-                    /*
-                     * Usually, the projected CRS already has (E,N) axis orientations with
metres units,
-                     * so we let 'toNormalized' to null. In the rarer cases where the CRS
axes do not
-                     * have the expected orientations and units, then we build a normalized
version of
-                     * that CRS and compute the transformation to that CRS.
-                     */
-                    DefaultProjectedCRS normalized = DefaultProjectedCRS.castOrCopy((ProjectedCRS)
crs);
-                    if (normalized != (normalized = normalized.forConvention(AxesConvention.NORMALIZED)))
{
-                        toNormalized = CRS.findOperation(crs, normalized, null).getMathTransform();
-                        projection = normalized.getConversionFromBase();
-                    }
-                    /*
-                     * We will also need the transformation from the normalized projected
CRS to longitude
-                     * and latitude (in that order) in degrees. We can get this transform
directly from the
-                     * projected CRS if its base CRS already has the expected axis orientations
and units.
-                     */
-                    DefaultGeographicCRS geographic = DefaultGeographicCRS.castOrCopy(normalized.getBaseCRS());
-                    if (geographic != (geographic = geographic.forConvention(AxesConvention.NORMALIZED)))
{
-                        toGeographic = CRS.findOperation(normalized, geographic, null).getMathTransform();
-                    } else {
-                        toGeographic = projection.getMathTransform().inverse();
-                    }
+            } else if (IdentifiedObjects.isHeuristicMatchForName(method, PolarStereographicA.NAME))
{
+                crsZone = NORTH_POLE * PolarStereographicA.isUPS(projection.getParameterValues());
+            } else {
+                crsZone = 0;                                    // Neither UTM or UPS projection.
+            }
+            if (crsZone != 0) {
+                /*
+                 * Usually, the projected CRS already has (E,N) axis orientations with metres
units,
+                 * so we let 'toNormalized' to null. In the rarer cases where the CRS axes
do not
+                 * have the expected orientations and units, then we build a normalized version
of
+                 * that CRS and compute the transformation to that CRS.
+                 */
+                DefaultProjectedCRS normalized;
+                projCRS = normalized = DefaultProjectedCRS.castOrCopy(projCRS);
+                normalized = normalized.forConvention(AxesConvention.NORMALIZED);
+                if (normalized != projCRS) {
+                    toNormalized = CRS.findOperation(projCRS, normalized, null).getMathTransform();
+                    projection = normalized.getConversionFromBase();
+                } else {
+                    toNormalized = null;            // ProjectedCRS (UTM or UPS) is already
normalized.
                 }
+            } else {
+                toNormalized = null;    // ProjectedCRS is neither UTM or UPS — will need
full reprojection.
+            }
+            /*
+             * We will also need the transformation from the normalized projected CRS to
latitude and
+             * longitude (in that order) in degrees. We can get this transform directly from
the
+             * projected CRS if its base CRS already has the expected axis orientations and
units.
+             */
+            GeographicCRS geographic = projCRS.getBaseCRS();
+            GeographicCRS standard = datum.geographic();
+            if (Utilities.equalsIgnoreMetadata(geographic.getCoordinateSystem(), standard.getCoordinateSystem()))
{
+                toGeographic = projection.getMathTransform().inverse();
+            } else {
+                toGeographic = CRS.findOperation(projCRS, standard, null).getMathTransform();
             }
+        } else {
+            crsZone      = 0;
+            toNormalized = null;
+            toGeographic = null;
+            // TODO
         }
     }
 
@@ -235,15 +279,19 @@ final class MGRSEncoder {
         final DirectPosition geographic;
         if (crsZone != 0) {
             geographic = toGeographic.transform(position, null);
-            final double φ = geographic.getOrdinate(1);
+            final double φ = geographic.getOrdinate(0);
             if (φ >= UTM_SOUTH_BOUNDS && φ <= UTM_NORTH_BOUNDS) {
-                final char   band = latitudeBand(φ);
-                final double    λ = geographic.getOrdinate(0);
-                final int utmZone = TransverseMercator.Zoner.UTM.zone(λ);
-                final int    zone = zone(utmZone, λ, band);
-                if (zone != crsZone) {
-                    // TODO: reproject
-                    throw new IllegalArgumentException();
+                final boolean isNorth = MathFunctions.isPositive(φ);
+                final char    band    = latitudeBand(φ);
+                final double  λ       = geographic.getOrdinate(1);
+                final int     utmZone = TransverseMercator.Zoner.UTM.zone(λ);
+                final int     zone    = zone(utmZone, λ, band);
+                if ((isNorth ? zone : -zone) != crsZone) try {
+                    final double cl = TransverseMercator.Zoner.UTM.centralMeridian(zone);
+                    position = CRS.findOperation(datum.geographic(), datum.UTM(φ, cl), null)
+                            .getMathTransform().transform(geographic, null);
+                } catch (FactoryException e) {
+                    throw new TransformException(e.toString(), e);
                 }
                 buffer.append(zone).append(band);
                 if (digits >= 0) {

Modified: sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/gazetteer/MilitaryGridReferenceSystem.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/gazetteer/MilitaryGridReferenceSystem.java?rev=1782972&r1=1782971&r2=1782972&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/gazetteer/MilitaryGridReferenceSystem.java
[UTF-8] (original)
+++ sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/gazetteer/MilitaryGridReferenceSystem.java
[UTF-8] Tue Feb 14 15:06:58 2017
@@ -24,8 +24,9 @@ import org.opengis.util.FactoryException
 import org.opengis.geometry.DirectPosition;
 import org.opengis.referencing.crs.CoordinateReferenceSystem;
 import org.opengis.referencing.operation.TransformException;
-import org.apache.sis.util.ArgumentChecks;
+import org.apache.sis.referencing.CommonCRS;
 import org.apache.sis.math.MathFunctions;
+import org.apache.sis.util.ArgumentChecks;
 import org.apache.sis.util.resources.Errors;
 
 
@@ -33,6 +34,8 @@ import org.apache.sis.util.resources.Err
  * The Military Grid Reference System (MGRS).
  * The MGRS is the geocoordinate standard used by NATO militaries for locating points on
the earth.
  * It is based on the Universal Transverse Mercator (UTM) and the polar stereographic projections.
+ * Despite its name, MGRS is not used only for military purposes; it is used also for organizing
+ * Earth Observation data in a directory tree on some cloud storages for example.
  *
  * <div class="section">Immutability and thread safety</div>
  * This class is immutable and thus thread-safe. However the {@code Coder} performing conversions
@@ -47,9 +50,38 @@ import org.apache.sis.util.resources.Err
  */
 public class MilitaryGridReferenceSystem {
     /**
-     * Creates a new Military Grid Reference System (MGRS).
+     * The target datum, represented by a {@code CommonCRS} instance.
+     * Only the datums enumerated in {@link CommonCRS} are currently supported.
+     */
+    private final CommonCRS datum;
+
+    /**
+     * Creates a new Military Grid Reference System (MGRS) using the WGS84 datum.
      */
     public MilitaryGridReferenceSystem() {
+        datum = CommonCRS.WGS84;
+    }
+
+    /**
+     * Creates a new Military Grid Reference System (MGRS) using the specified datum.
+     * Only the datums enumerated in {@link CommonCRS} are currently supported.
+     *
+     * @param  datum  the target datum as a {@code CommonCRS} enumerated value.
+     */
+    public MilitaryGridReferenceSystem(final CommonCRS datum) {
+        ArgumentChecks.ensureNonNull("datum", datum);
+        this.datum = datum;
+    }
+
+    /**
+     * Returns a new object performing conversions between {@code DirectPosition} and MGRS
labels.
+     * The returned object is <strong>not</strong> thread-safe; a new instance
must be created for
+     * each thread, or synchronization must be applied by the caller.
+     *
+     * @return a new object performing conversions between {@link DirectPosition} and MGRS
labels.
+     */
+    public Coder createCoder() {
+        return new Coder();
     }
 
     /**
@@ -85,7 +117,7 @@ public class MilitaryGridReferenceSystem
         /**
          * Creates a new coder initialized to the default precision.
          */
-        public Coder() {
+        protected Coder() {
             digits    = 5;                          // 1 meter precision.
             buffer    = new StringBuilder(12);      // Length of "4QFJ12345678" sample value.
             encoders  = new IdentityHashMap<>();

Modified: sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/referencing/gazetteer/MilitaryGridReferenceSystemTest.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/referencing/gazetteer/MilitaryGridReferenceSystemTest.java?rev=1782972&r1=1782971&r2=1782972&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/referencing/gazetteer/MilitaryGridReferenceSystemTest.java
[UTF-8] (original)
+++ sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/referencing/gazetteer/MilitaryGridReferenceSystemTest.java
[UTF-8] Tue Feb 14 15:06:58 2017
@@ -16,14 +16,15 @@
  */
 package org.apache.sis.referencing.gazetteer;
 
+import org.opengis.referencing.operation.TransformException;
 import org.apache.sis.geometry.DirectPosition2D;
 import org.apache.sis.referencing.CommonCRS;
+import org.apache.sis.test.DependsOnMethod;
 import org.apache.sis.test.DependsOn;
 import org.apache.sis.test.TestCase;
 import org.junit.Test;
 
 import static org.junit.Assert.*;
-import org.opengis.referencing.operation.TransformException;
 
 
 /**
@@ -37,13 +38,60 @@ import org.opengis.referencing.operation
 @DependsOn(MGRSEncoderTest.class)
 public final strictfp class MilitaryGridReferenceSystemTest extends TestCase {
     /**
-     * Tests encoding of coordinates.
+     * Returns a coder instance to test.
+     */
+    private MilitaryGridReferenceSystem.Coder coder() {
+        return new MilitaryGridReferenceSystem().createCoder();
+    }
+
+    /**
+     * Tests encoding of various coordinates.
      *
      * @throws TransformException if an error occurred while computing the MGRS label.
      */
     @Test
     public void testEncoding() throws TransformException {
-        final MilitaryGridReferenceSystem.Coder coder = new MilitaryGridReferenceSystem.Coder();
+        final MilitaryGridReferenceSystem.Coder coder = coder();
+        final DirectPosition2D position = new DirectPosition2D();
+        /*
+         * 41°N 10°E (UTM zone 32)
+         */
+        position.setCoordinateReferenceSystem(CommonCRS.WGS84.UTM(41, 10));
+        position.x =  584102;
+        position.y = 4539239;
+        assertEquals("32TNL8410239239", coder.encode(position));
+        /*
+         * 82°N 10°W (UTM zone 29) — should instantiate a new MGRSEncoder.
+         */
+        position.setCoordinateReferenceSystem(CommonCRS.WGS84.UTM(82, -10));
+        position.x =  484463;
+        position.y = 9104963;
+        assertEquals("29XMM8446304963", coder.encode(position));
+        /*
+         * 41°S 10°E (UTM zone 32) — should reuse the MGRSEncoder created in first test.
+         */
+        position.setCoordinateReferenceSystem(CommonCRS.WGS84.UTM(-41, 10));
+        position.x =  584102;
+        position.y = 5460761;
+        assertEquals("32GNV8410260761", coder.encode(position));
+        /*
+         * 82°N 10°E (UTM zone 32) — in this special case, zone 32 is replaced by zone
33.
+         */
+        position.setCoordinateReferenceSystem(CommonCRS.WGS84.UTM(82, 10));
+        position.x =  515537;
+        position.y = 9104963;
+//      assertEquals("33XVM2240608183", coder.encode(position));
+    }
+
+    /**
+     * Tests encoding of the same coordinate at various precision.
+     *
+     * @throws TransformException if an error occurred while computing the MGRS label.
+     */
+    @Test
+    @DependsOnMethod("testEncoding")
+    public void testPrecision() throws TransformException {
+        final MilitaryGridReferenceSystem.Coder coder = coder();
         final DirectPosition2D position = new DirectPosition2D(CommonCRS.WGS84.UTM(13, 103));
         position.x =  377299;
         position.y = 1483035;



Mime
View raw message