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


The following commit(s) were added to refs/heads/geoapi-4.0 by this push:
     new 4a0ed7a1a3 Add a test case for "Mercator Auxiliary Sphere".
4a0ed7a1a3 is described below

commit 4a0ed7a1a3adc3aaa1a3ddb1575a59b635feae4f
Author: Martin Desruisseaux <[email protected]>
AuthorDate: Thu Apr 28 11:16:20 2022 +0200

    Add a test case for "Mercator Auxiliary Sphere".
    
    https://issues.apache.org/jira/browse/SIS-542
---
 .../provider/MercatorAuxiliarySphere.java          |  2 +-
 .../referencing/operation/projection/Mercator.java | 15 ++++++---
 .../operation/projection/MercatorTest.java         | 36 +++++++++++++++++++++-
 3 files changed, 47 insertions(+), 6 deletions(-)

diff --git 
a/core/sis-referencing/src/main/java/org/apache/sis/internal/referencing/provider/MercatorAuxiliarySphere.java
 
b/core/sis-referencing/src/main/java/org/apache/sis/internal/referencing/provider/MercatorAuxiliarySphere.java
index 0dd127e112..c999996836 100644
--- 
a/core/sis-referencing/src/main/java/org/apache/sis/internal/referencing/provider/MercatorAuxiliarySphere.java
+++ 
b/core/sis-referencing/src/main/java/org/apache/sis/internal/referencing/provider/MercatorAuxiliarySphere.java
@@ -66,7 +66,7 @@ public final class MercatorAuxiliarySphere extends 
AbstractMercator {
         final ParameterBuilder builder = 
builder().setCodeSpace(Citations.ESRI, "ESRI");
         AUXILIARY_SPHERE_TYPE = 
builder.addName("Auxiliary_Sphere_Type").createBounded(0, 3, 0);
 
-        final ParameterDescriptor<?>[] descriptors = 
toArray(MercatorSpherical.PARAMETERS.descriptors(), 1);
+        final ParameterDescriptor<?>[] descriptors = 
toArray(Mercator2SP.PARAMETERS.descriptors(), 1);
         descriptors[descriptors.length - 1] = AUXILIARY_SPHERE_TYPE;
         PARAMETERS = 
builder.addName("Mercator_Auxiliary_Sphere").createGroupForMapProjection(descriptors);
     }
diff --git 
a/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/projection/Mercator.java
 
b/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/projection/Mercator.java
index 88627c0719..cddb5f0827 100644
--- 
a/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/projection/Mercator.java
+++ 
b/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/projection/Mercator.java
@@ -311,14 +311,21 @@ public class Mercator extends ConformalProjection {
             DoubleDouble ratio = null;
             final int type = 
initializer.getAndStore(MercatorAuxiliarySphere.AUXILIARY_SPHERE_TYPE, 0);
             switch (type) {
-                case 0: break;      // Same as "Popular Visualisation Pseudo 
Mercator".
-                case 1: ratio = initializer.axisLengthRatio(); break;
-                case 2:
-                case 3: ratio = new DoubleDouble(Formulas.getAuthalicRadius(1, 
initializer.axisLengthRatio().value)); break;
                 default: {
                     throw new 
IllegalArgumentException(Errors.format(Errors.Keys.IllegalArgumentValue_2,
                             
MercatorAuxiliarySphere.AUXILIARY_SPHERE_TYPE.getName().getCode(), type));
                 }
+                case 3: {
+                    throw new IllegalArgumentException("Type 3 not yet 
supported.");
+                    /*
+                     * For supporting this case, we need to convert geodetic 
latitude (φ) to authalic latitude (ß)
+                     * using for example the formulas for Lambert Azimuthal 
Equal Area. We could set a flag telling
+                     * that we need to instantiate a subclass. Then we 
fall-through case 2 below.
+                     */
+                }
+                case 2: ratio = new DoubleDouble(Formulas.getAuthalicRadius(1, 
initializer.axisLengthRatio().value)); break;
+                case 1: ratio = initializer.axisLengthRatio(); break;
+                case 0: break;      // Same as "Popular Visualisation Pseudo 
Mercator".
             }
             denormalize.convertAfter(0, ratio, null);
             denormalize.convertAfter(1, ratio, null);
diff --git 
a/core/sis-referencing/src/test/java/org/apache/sis/referencing/operation/projection/MercatorTest.java
 
b/core/sis-referencing/src/test/java/org/apache/sis/referencing/operation/projection/MercatorTest.java
index 5e6b4c2920..45739da80b 100644
--- 
a/core/sis-referencing/src/test/java/org/apache/sis/referencing/operation/projection/MercatorTest.java
+++ 
b/core/sis-referencing/src/test/java/org/apache/sis/referencing/operation/projection/MercatorTest.java
@@ -19,14 +19,18 @@ package org.apache.sis.referencing.operation.projection;
 import org.opengis.util.FactoryException;
 import org.opengis.referencing.operation.TransformException;
 import org.opengis.referencing.operation.NoninvertibleTransformException;
+import org.apache.sis.internal.util.Constants;
 import org.apache.sis.internal.referencing.Formulas;
 import org.apache.sis.internal.referencing.provider.Mercator1SP;
 import org.apache.sis.internal.referencing.provider.Mercator2SP;
 import org.apache.sis.internal.referencing.provider.MercatorSpherical;
+import org.apache.sis.internal.referencing.provider.MercatorAuxiliarySphere;
 import org.apache.sis.internal.referencing.provider.PseudoMercator;
 import org.apache.sis.internal.referencing.provider.MillerCylindrical;
 import org.apache.sis.internal.referencing.provider.RegionalMercator;
 import org.apache.sis.referencing.operation.transform.CoordinateDomain;
+import org.apache.sis.referencing.operation.transform.MathTransformFactoryMock;
+import org.apache.sis.parameter.Parameters;
 import org.apache.sis.test.DependsOnMethod;
 import org.apache.sis.test.DependsOn;
 import org.junit.Test;
@@ -43,7 +47,7 @@ import static 
org.apache.sis.referencing.operation.projection.ConformalProjectio
  * @author  Martin Desruisseaux (Geomatys)
  * @author  Simon Reynard (Geomatys)
  * @author  Rémi Maréchal (Geomatys)
- * @version 0.8
+ * @version 1.2
  * @since   0.6
  * @module
  */
@@ -263,6 +267,36 @@ public final strictfp class MercatorTest extends 
MapProjectionTestCase {
         createGeoApiTest(new MillerCylindrical()).testMiller();
     }
 
+    /**
+     * Tests the <cite>"Mercator Auxiliary Sphere"</cite> case.
+     * For the sphere type 0, which is the default, this is equivalent to 
pseudo-Mercator.
+     *
+     * @throws FactoryException if an error occurred while creating the map 
projection.
+     * @throws TransformException if an error occurred while projecting a 
coordinate.
+     */
+    @Test
+    @DependsOnMethod("testPseudoMercator")
+    public void testMercatorAuxiliarySphere() throws FactoryException, 
TransformException {
+        final MercatorAuxiliarySphere provider = new MercatorAuxiliarySphere();
+        tolerance = Formulas.LINEAR_TOLERANCE;
+        for (int type = 0; type <= 2; type++) {
+            final Parameters values = 
Parameters.castOrWrap(provider.getParameters().createValue());
+            values.parameter(Constants.SEMI_MAJOR).setValue(WGS84_A);
+            values.parameter(Constants.SEMI_MINOR).setValue(WGS84_B);
+            values.parameter("Auxiliary_Sphere_Type").setValue(type);
+            transform = new 
MathTransformFactoryMock(provider).createParameterizedTransform(values);
+            validate();
+            final double expected;
+            switch (type) {
+                case 0: expected = WGS84_A;    break;   // 6378137
+                case 1: expected = WGS84_B;    break;   // 6356752.31
+                case 2: expected = 6371007.18; break;   // Authalic radius
+                default: throw new AssertionError(type);
+            }
+            verifyTransform(new double[] {180/Math.PI, 0, 0, 0}, new double[] 
{expected, 0, 0, 0});
+        }
+    }
+
     /**
      * Performs the same tests than {@link #testSpecialLatitudes()} and {@link 
#testDerivative()},
      * but using spherical formulas.

Reply via email to