sis-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From desruisse...@apache.org
Subject [sis] 01/02: Add tests for GeodeticCalculator.
Date Sun, 12 May 2019 21:07:17 GMT
This is an automated email from the ASF dual-hosted git repository.

desruisseaux pushed a commit to branch geoapi-4.0
in repository https://gitbox.apache.org/repos/asf/sis.git

commit d375961a49872581248b1441af3df9661b61c43e
Author: Martin Desruisseaux <martin.desruisseaux@geomatys.com>
AuthorDate: Sun May 12 23:04:40 2019 +0200

    Add tests for GeodeticCalculator.
---
 .../internal/referencing/PositionTransformer.java  |  1 -
 .../sis/referencing/GeodeticCalculatorTest.java    | 85 +++++++++++++++++++++-
 2 files changed, 84 insertions(+), 2 deletions(-)

diff --git a/core/sis-referencing/src/main/java/org/apache/sis/internal/referencing/PositionTransformer.java
b/core/sis-referencing/src/main/java/org/apache/sis/internal/referencing/PositionTransformer.java
index 1fd3713..6252f80 100644
--- a/core/sis-referencing/src/main/java/org/apache/sis/internal/referencing/PositionTransformer.java
+++ b/core/sis-referencing/src/main/java/org/apache/sis/internal/referencing/PositionTransformer.java
@@ -130,7 +130,6 @@ public final class PositionTransformer extends GeneralDirectPosition {
         super(targetCRS);
         ArgumentChecks.ensureNonNull("targetCRS", targetCRS);
         this.defaultCRS = (defaultCRS != null) ? defaultCRS : targetCRS;
-        this.lastCRS    = defaultCRS;
         this.factory    = (factory != null) ? factory : DefaultFactories.forBuildin(CoordinateOperationFactory.class);
     }
 
diff --git a/core/sis-referencing/src/test/java/org/apache/sis/referencing/GeodeticCalculatorTest.java
b/core/sis-referencing/src/test/java/org/apache/sis/referencing/GeodeticCalculatorTest.java
index cafb080..5163e71 100644
--- a/core/sis-referencing/src/test/java/org/apache/sis/referencing/GeodeticCalculatorTest.java
+++ b/core/sis-referencing/src/test/java/org/apache/sis/referencing/GeodeticCalculatorTest.java
@@ -18,10 +18,14 @@ package org.apache.sis.referencing;
 
 import org.opengis.geometry.DirectPosition;
 import org.opengis.referencing.operation.TransformException;
+import org.apache.sis.internal.referencing.Formulas;
+import org.apache.sis.geometry.DirectPosition2D;
 import org.apache.sis.measure.Units;
+import org.apache.sis.test.DependsOnMethod;
 import org.apache.sis.test.TestCase;
 import org.junit.Test;
 
+import static java.lang.StrictMath.*;
 import static org.junit.Assert.*;
 
 
@@ -34,6 +38,65 @@ import static org.junit.Assert.*;
  */
 public final strictfp class GeodeticCalculatorTest extends TestCase {
     /**
+     * Returns the calculator to use for testing purpose.
+     * This classes uses calculator for a sphere.
+     */
+    private static GeodeticCalculator create() {
+        return new GeodeticCalculator(CommonCRS.SPHERE.geographic());
+    }
+
+    /**
+     * Tests some simple azimuth directions. The expected directions are approximately North,
East,
+     * South and West, but not exactly because of Earth curvature. The test verify merely
that the
+     * azimuths are approximately correct.
+     */
+    @Test
+    public void testCardinalAzimuths() {
+        final GeodeticCalculator c = create();
+        final double EPS = 0.2;
+        c.setStartPoint(20, 12);
+        c.setEndPoint(20, 13);  assertEquals("East",   90, c.getStartingAzimuth(), EPS);
+        c.setEndPoint(21, 12);  assertEquals("North",   0, c.getStartingAzimuth(), EPS);
+        c.setEndPoint(20, 11);  assertEquals("West",  -90, c.getStartingAzimuth(), EPS);
+        c.setEndPoint(19, 12);  assertEquals("South", 180, c.getStartingAzimuth(), EPS);
+    }
+
+    /**
+     * Tests azimuths at poles.
+     */
+    @Test
+    public void testPoles() {
+        final GeodeticCalculator c = create();
+        final double EPS = 0.2;
+        c.setStartPoint( 90,  30);
+        c.setEndPoint  ( 20,  20);  assertEquals(-170, c.getStartingAzimuth(), EPS);
+        c.setEndPoint  ( 20,  40);  assertEquals( 170, c.getStartingAzimuth(), EPS);
+        c.setEndPoint  ( 20,  30);  assertEquals( 180, c.getStartingAzimuth(), EPS);
+        c.setEndPoint  (-20,  30);  assertEquals( 180, c.getStartingAzimuth(), EPS);
+        c.setEndPoint  (-90,  30);  assertEquals( 180, c.getStartingAzimuth(), EPS);
+
+        c.setStartPoint( 90,   0);
+        c.setEndPoint  ( 20,  20);  assertEquals( 160, c.getStartingAzimuth(), EPS);
+        c.setEndPoint  ( 20, -20);  assertEquals(-160, c.getStartingAzimuth(), EPS);
+        c.setEndPoint  ( 20,   0);  assertEquals( 180, c.getStartingAzimuth(), EPS);
+        c.setEndPoint  (-90,   0);  assertEquals( 180, c.getStartingAzimuth(), EPS);
+    }
+
+    /**
+     * Tests geodesic distances on the equator.
+     */
+    @Test
+    public void testEquator() {
+        final GeodeticCalculator c = create();
+        final double r = c.ellipsoid.getSemiMajorAxis() * (PI / 180);
+        c.setStartPoint(0, 0);
+        for (double x=170; x<=180; x+=0.125) {
+            c.setEndPoint(0, x);
+            assertEquals(x * r, c.getGeodesicDistance(), Formulas.LINEAR_TOLERANCE);
+        }
+    }
+
+    /**
      * Tests spherical formulas with the example given in Wikipedia.
      * This computes the great circle route from Valparaíso (33°N 71.6W) to Shanghai (31.4°N
121.8°E).
      *
@@ -41,7 +104,7 @@ public final strictfp class GeodeticCalculatorTest extends TestCase {
      */
     @Test
     public void testWikipediaExample() throws TransformException {
-        final GeodeticCalculator c = new GeodeticCalculator(CommonCRS.SPHERE.geographic());
+        final GeodeticCalculator c = create();
         c.setStartPoint(-33.0, -71.6);          // Valparaíso
         c.setEndPoint  ( 31.4, 121.8);          // Shanghai
         /*
@@ -80,4 +143,24 @@ public final strictfp class GeodeticCalculatorTest extends TestCase {
         assertEquals("φ", φ, p.getOrdinate(0), ε);
         assertEquals("λ", λ, p.getOrdinate(1), ε);
     }
+
+    /**
+     * Tests geodetic calculator involving a coordinate operation.
+     * This test uses a simple CRS with only the axis order interchanged.
+     * The coordinates are the same than {@link #testWikipediaExample()}.
+     *
+     * @throws TransformException if an error occurred while transforming coordinates.
+     */
+    @Test
+    @DependsOnMethod("testWikipediaExample")
+    public void testUsingTransform() throws TransformException {
+        final GeodeticCalculator c = new GeodeticCalculator(CommonCRS.SPHERE.normalizedGeographic());
+        final double φ = -33.0;
+        final double λ = -71.6;
+        c.setStartPoint(new DirectPosition2D(λ, φ));
+        assertPositionEquals(λ, φ, c.getStartPoint(), Formulas.ANGULAR_TOLERANCE);
+
+        c.setDirection(-94.41, 18743000);
+        assertPositionEquals(121.8, 31.4, c.getEndPoint(), 0.01);
+    }
 }


Mime
View raw message