sis-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From desruisse...@apache.org
Subject svn commit: r1786921 - in /sis/branches/JDK8/core/sis-referencing-by-identifiers/src: main/java/org/apache/sis/referencing/gazetteer/GeohashReferenceSystem.java test/java/org/apache/sis/referencing/gazetteer/GeohashReferenceSystemTest.java
Date Tue, 14 Mar 2017 16:21:27 GMT
Author: desruisseaux
Date: Tue Mar 14 16:21:27 2017
New Revision: 1786921

URL: http://svn.apache.org/viewvc?rev=1786921&view=rev
Log:
More tests for geohash, taking in account coordinate transformations.

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

Modified: sis/branches/JDK8/core/sis-referencing-by-identifiers/src/main/java/org/apache/sis/referencing/gazetteer/GeohashReferenceSystem.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-referencing-by-identifiers/src/main/java/org/apache/sis/referencing/gazetteer/GeohashReferenceSystem.java?rev=1786921&r1=1786920&r2=1786921&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-referencing-by-identifiers/src/main/java/org/apache/sis/referencing/gazetteer/GeohashReferenceSystem.java
[UTF-8] (original)
+++ sis/branches/JDK8/core/sis-referencing-by-identifiers/src/main/java/org/apache/sis/referencing/gazetteer/GeohashReferenceSystem.java
[UTF-8] Tue Mar 14 16:21:27 2017
@@ -233,7 +233,7 @@ public class GeohashReferenceSystem exte
          */
         protected Coder() {
             length = 12;
-            coordinates = denormalize.getMathTransform().isIdentity() ? null : new double[4];
+            coordinates = denormalize.getMathTransform().isIdentity() ? null : new double[8];
         }
 
         /**
@@ -259,11 +259,14 @@ public class GeohashReferenceSystem exte
 
         /**
          * Encodes the given latitude and longitude into a geohash.
+         * This method does <strong>not</strong> take in account the axis order
and units of the coordinate
+         * reference system (CRS) given to the {@link GeohashReferenceSystem} constructor.
For geohashing of
+         * coordinates in different CRS, use {@link #encode(DirectPosition)} instead.
          *
          * @param  φ  latitude to encode,  as decimal degrees in the [-90 … 90]° range.
          * @param  λ  longitude to encode, as decimal degrees in the [-180 … 180]° range.
          * @return geohash encoding of the given longitude and latitude.
-         * @throws TransformException if an error occurred while transforming the given coordinate
to a geohash reference.
+         * @throws TransformException if an error occurred while formatting the given coordinate.
          */
         public String encode(double φ, double λ) throws TransformException {
             φ = Latitude.clamp(φ);

Modified: sis/branches/JDK8/core/sis-referencing-by-identifiers/src/test/java/org/apache/sis/referencing/gazetteer/GeohashReferenceSystemTest.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-referencing-by-identifiers/src/test/java/org/apache/sis/referencing/gazetteer/GeohashReferenceSystemTest.java?rev=1786921&r1=1786920&r2=1786921&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-referencing-by-identifiers/src/test/java/org/apache/sis/referencing/gazetteer/GeohashReferenceSystemTest.java
[UTF-8] (original)
+++ sis/branches/JDK8/core/sis-referencing-by-identifiers/src/test/java/org/apache/sis/referencing/gazetteer/GeohashReferenceSystemTest.java
[UTF-8] Tue Mar 14 16:21:27 2017
@@ -19,8 +19,10 @@ package org.apache.sis.referencing.gazet
 import java.util.Locale;
 import org.opengis.referencing.operation.TransformException;
 import org.opengis.geometry.DirectPosition;
+import org.apache.sis.geometry.DirectPosition2D;
 import org.apache.sis.referencing.CommonCRS;
 import org.apache.sis.test.TestUtilities;
+import org.apache.sis.test.DependsOnMethod;
 import org.apache.sis.test.DependsOn;
 import org.apache.sis.test.TestCase;
 import org.junit.Test;
@@ -86,7 +88,7 @@ public final strictfp class GeohashRefer
     };
 
     /**
-     * Tests the {@link GeohashReferenceSystem#encode(double, double)} method.
+     * Tests the {@link GeohashReferenceSystem.Coder#encode(double, double)} method.
      *
      * @throws TransformException if an exception occurred while formatting the geohash.
      */
@@ -99,18 +101,54 @@ public final strictfp class GeohashRefer
     }
 
     /**
-     * Tests the {@link GeohashReferenceSystem#decode(String)} method.
+     * Tests the {@link GeohashReferenceSystem.Coder#encode(DirectPosition)} method.
+     *
+     * @throws TransformException if an exception occurred while formatting the geohash.
+     */
+    @Test
+    @DependsOnMethod("testEncode")
+    public void testEncodePosition() throws TransformException {
+        final GeohashReferenceSystem.Coder coder = instance().createCoder();
+        final DirectPosition2D position = new DirectPosition2D(CommonCRS.WGS84.geographic());
+        for (final Place place : PLACES) {
+            position.x = place.latitude;
+            position.y = place.longitude;
+            assertEquals(place.name, place.geohash, coder.encode(position));
+        }
+    }
+
+    /**
+     * Tests the {@link GeohashReferenceSystem.Coder#decode(CharSequence)} method.
      *
      * @throws TransformException if an exception occurred while parsing the geohash.
      */
     @Test
     public void testDecode() throws TransformException {
-        final GeohashReferenceSystem.Coder coder = instance().createCoder();
+        testDecode(instance().createCoder(), 0, 1);
+    }
+
+    /**
+     * Tests the {@link GeohashReferenceSystem.Coder#decode(CharSequence)} method
+     * to a different target CRS than the default one.
+     *
+     * @throws TransformException if an exception occurred while parsing the geohash.
+     */
+    @Test
+    @DependsOnMethod("testDecode")
+    public void testDecodeToCRS() throws TransformException {
+        testDecode(new GeohashReferenceSystem(GeohashReferenceSystem.Format.BASE32,
+                        CommonCRS.WGS84.geographic()).createCoder(), 1, 0);
+    }
+
+    /**
+     * Implementation of {@link #testDecode()} and {@link #testDecodeToCRS()}.
+     */
+    private void testDecode(final GeohashReferenceSystem.Coder coder, final int λi, final
int φi) throws TransformException {
         for (final Place place : PLACES) {
             final Location location = coder.decode(place.geohash);
             final DirectPosition result = location.getPosition().getDirectPosition();
-            assertEquals(place.name, place.longitude, result.getOrdinate(0), TOLERANCE);
-            assertEquals(place.name, place.latitude,  result.getOrdinate(1), TOLERANCE);
+            assertEquals(place.name, place.longitude, result.getOrdinate(λi), TOLERANCE);
+            assertEquals(place.name, place.latitude,  result.getOrdinate(φi), TOLERANCE);
         }
     }
 



Mime
View raw message