sis-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From desruisse...@apache.org
Subject svn commit: r1785977 - in /sis/branches/JDK8/core/sis-referencing-by-identifiers/src: main/java/org/apache/sis/referencing/gazetteer/MilitaryGridReferenceSystem.java test/java/org/apache/sis/referencing/gazetteer/MilitaryGridReferenceSystemTest.java
Date Wed, 08 Mar 2017 14:54:47 GMT
Author: desruisseaux
Date: Wed Mar  8 14:54:47 2017
New Revision: 1785977

URL: http://svn.apache.org/viewvc?rev=1785977&view=rev
Log:
Add a 'Coder.setClipToValidArea(boolean)' method.

Modified:
    sis/branches/JDK8/core/sis-referencing-by-identifiers/src/main/java/org/apache/sis/referencing/gazetteer/MilitaryGridReferenceSystem.java
    sis/branches/JDK8/core/sis-referencing-by-identifiers/src/test/java/org/apache/sis/referencing/gazetteer/MilitaryGridReferenceSystemTest.java

Modified: sis/branches/JDK8/core/sis-referencing-by-identifiers/src/main/java/org/apache/sis/referencing/gazetteer/MilitaryGridReferenceSystem.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-referencing-by-identifiers/src/main/java/org/apache/sis/referencing/gazetteer/MilitaryGridReferenceSystem.java?rev=1785977&r1=1785976&r2=1785977&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-referencing-by-identifiers/src/main/java/org/apache/sis/referencing/gazetteer/MilitaryGridReferenceSystem.java
[UTF-8] (original)
+++ sis/branches/JDK8/core/sis-referencing-by-identifiers/src/main/java/org/apache/sis/referencing/gazetteer/MilitaryGridReferenceSystem.java
[UTF-8] Wed Mar  8 14:54:47 2017
@@ -371,6 +371,13 @@ public class MilitaryGridReferenceSystem
         private String trimmedSeparator;
 
         /**
+         * Whether the decoded locations should be clipped to the valid area of MGRS cell.
+         *
+         * @see #getClipToValidArea()
+         */
+        private boolean clipToValidArea = true;
+
+        /**
          * Cached information needed for building a MGRS reference from a direct position
in the given CRS.
          */
         private final Map<CoordinateReferenceSystem,Encoder> encoders;
@@ -476,6 +483,29 @@ public class MilitaryGridReferenceSystem
         }
 
         /**
+         * Returns whether the decoded locations should be clipped to the valid area.
+         * The default value is {@code true}.
+         *
+         * @return {@code true} if decoded locations are clipped to the valid area.
+         */
+        public boolean getClipToValidArea() {
+            return clipToValidArea;
+        }
+
+        /**
+         * Sets whether the decoded locations should be clipped to the valid area.
+         * MGRS 100 km squares can actually be smaller than 100 km when the square overlaps
two UTM zones or
+         * two latitude bands. We may have half of a square in a zone and the other half
in the other zone.
+         * By default, the {@link #decode(CharSequence)} method clips the square to the zone
where it belongs.
+         * Invoking this method with the {@code false} value disables this behavior.
+         *
+         * @param clip  whether the decoded locations should be clipped to the valid area.
+         */
+        public void setClipToValidArea(final boolean clip) {
+            clipToValidArea = clip;
+        }
+
+        /**
          * Bridge to {@link MilitaryGridReferenceSystem#datum}
          * for the {@link Encoder} and {@link Decoder} classes.
          */
@@ -1283,7 +1313,7 @@ parse:                  switch (part) {
                  * MGRS reference. If the cell is valid, we can now check for cells that
are on a zone border.
                  * Those cells will be clipped to the zone valid area.
                  */
-                if (isValid) {
+                if (isValid && owner.getClipToValidArea()) {
                     final boolean changed;
                     if (zone != 0) {
                         double width = ZONER.width;

Modified: sis/branches/JDK8/core/sis-referencing-by-identifiers/src/test/java/org/apache/sis/referencing/gazetteer/MilitaryGridReferenceSystemTest.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-referencing-by-identifiers/src/test/java/org/apache/sis/referencing/gazetteer/MilitaryGridReferenceSystemTest.java?rev=1785977&r1=1785976&r2=1785977&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-referencing-by-identifiers/src/test/java/org/apache/sis/referencing/gazetteer/MilitaryGridReferenceSystemTest.java
[UTF-8] (original)
+++ sis/branches/JDK8/core/sis-referencing-by-identifiers/src/test/java/org/apache/sis/referencing/gazetteer/MilitaryGridReferenceSystemTest.java
[UTF-8] Wed Mar  8 14:54:47 2017
@@ -313,36 +313,72 @@ public final strictfp class MilitaryGrid
     public void testDecodeLimitCases() throws TransformException {
         final MilitaryGridReferenceSystem.Coder coder = coder();
         DirectPosition position;
+        ProjectedCRS crs;
         /*
          * Cell on the West border of a UTM zone in the South hemisphere.
-         * The Easting value would be 250000 if the cell was not clipped.
+         * Easting value before clipping: 250000
+         * Easting value after  clipping: 251256
          */
+        coder.setClipToValidArea(false);
         position = decode(coder, "19JBK");                                            //
South hemisphere
-        assertSame("crs", CommonCRS.WGS84.universal(-10, -69), position.getCoordinateReferenceSystem());
+        crs = CommonCRS.WGS84.universal(-10, -69);
+        assertSame("crs", crs, position.getCoordinateReferenceSystem());
+        assertEquals("Easting",   250000, position.getOrdinate(0), 1);
+        assertEquals("Northing", 6950000, position.getOrdinate(1), STRICT);
+
+        coder.setClipToValidArea(true);
+        position = decode(coder, "19JBK");
+        assertSame("crs", crs, position.getCoordinateReferenceSystem());
         assertEquals("Easting",   251256, position.getOrdinate(0), 1);
         assertEquals("Northing", 6950000, position.getOrdinate(1), STRICT);
         /*
          * Easting range before clipping is [300000 … 400000] metres.
-         * The east boung become 343828 metres after clipping.
-         * The easting value would be 350000 if the cell was not clipped.
+         * The east bound become 343828 metres after clipping.
+         * Easting value before clipping: 350000
+         * Easting value after  clipping: 371914
          */
+        coder.setClipToValidArea(false);
         position = decode(coder, "1VCK");                                // North of Norway
latitude band
-        assertSame("crs", CommonCRS.WGS84.universal(62, -180), position.getCoordinateReferenceSystem());
+        crs = CommonCRS.WGS84.universal(62, -180);
+        assertSame("crs", crs, position.getCoordinateReferenceSystem());
+        assertEquals("Easting",   350000, position.getOrdinate(0), 1);
+        assertEquals("Northing", 6950000, position.getOrdinate(1), STRICT);
+
+        coder.setClipToValidArea(true);
+        position = decode(coder, "1VCK");
+        assertSame("crs", crs, position.getCoordinateReferenceSystem());
         assertEquals("Easting",   371914, position.getOrdinate(0), 1);
         assertEquals("Northing", 6950000, position.getOrdinate(1), STRICT);
         /*
-         * Northing value would be 7350000 if the cell was not clipped.
+         * Northing value before clipping: 7350000
+         * Northing value after  clipping: 7371306
          */
+        coder.setClipToValidArea(false);
         position = decode(coder, "57KTP");
-        assertSame("crs", CommonCRS.WGS84.universal(-24, 156), position.getCoordinateReferenceSystem());
+        crs = CommonCRS.WGS84.universal(-24, 156);
+        assertSame("crs", crs, position.getCoordinateReferenceSystem());
+        assertEquals("Easting",   250000, position.getOrdinate(0), STRICT);
+        assertEquals("Northing", 7350000, position.getOrdinate(1), 1);
+
+        coder.setClipToValidArea(true);
+        position = decode(coder, "57KTP");
+        assertSame("crs", crs, position.getCoordinateReferenceSystem());
         assertEquals("Easting",   250000, position.getOrdinate(0), STRICT);
         assertEquals("Northing", 7371306, position.getOrdinate(1), 1);
         /*
-         * Easting  value would be  650000 if the cell was not clipped.
-         * Northing value would be 6250000 if the cell was not clipped.
+         * Easting and northing values before clipping:  650000   6250000
+         * Easting and northing values after  clipping:  643536   6253618
          */
+        coder.setClipToValidArea(false);
+        position = decode(coder, "56VPH");
+        crs = CommonCRS.WGS84.universal(55, 154);
+        assertSame("crs", crs, position.getCoordinateReferenceSystem());
+        assertEquals("Easting",   650000, position.getOrdinate(0), 1);
+        assertEquals("Northing", 6250000, position.getOrdinate(1), 1);
+
+        coder.setClipToValidArea(true);
         position = decode(coder, "56VPH");
-        assertSame("crs", CommonCRS.WGS84.universal(55, 154), position.getCoordinateReferenceSystem());
+        assertSame("crs", crs, position.getCoordinateReferenceSystem());
         assertEquals("Easting",   643536, position.getOrdinate(0), 1);
         assertEquals("Northing", 6253618, position.getOrdinate(1), 1);
     }



Mime
View raw message