sis-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From desruisse...@apache.org
Subject svn commit: r1814306 - in /sis/branches/JDK8/core/sis-referencing/src: main/java/org/apache/sis/internal/referencing/ main/java/org/apache/sis/internal/referencing/provider/ main/java/org/apache/sis/referencing/operation/ test/java/org/apache/sis/refer...
Date Sat, 04 Nov 2017 16:37:12 GMT
Author: desruisseaux
Date: Sat Nov  4 16:37:12 2017
New Revision: 1814306

URL: http://svn.apache.org/viewvc?rev=1814306&view=rev
Log:
When formatting an EPSG operation, include only the EPSG parameters.
The intend is to omit the OGC parameters that are redundant with EPSG ones, or which can be
inferred from the context.

Modified:
    sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/internal/referencing/WKTUtilities.java
    sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/internal/referencing/provider/Molodensky.java
    sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/AbstractCoordinateOperation.java
    sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/referencing/operation/DefaultConcatenatedOperationTest.java

Modified: sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/internal/referencing/WKTUtilities.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/internal/referencing/WKTUtilities.java?rev=1814306&r1=1814305&r2=1814306&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/internal/referencing/WKTUtilities.java
[UTF-8] (original)
+++ sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/internal/referencing/WKTUtilities.java
[UTF-8] Sat Nov  4 16:37:12 2017
@@ -19,9 +19,11 @@ package org.apache.sis.internal.referenc
 import javax.measure.Unit;
 import javax.measure.Quantity;
 import javax.measure.quantity.Angle;
+import org.opengis.metadata.Identifier;
 import org.opengis.parameter.ParameterValue;
 import org.opengis.parameter.ParameterValueGroup;
 import org.opengis.parameter.GeneralParameterValue;
+import org.opengis.parameter.GeneralParameterDescriptor;
 import org.opengis.referencing.IdentifiedObject;
 import org.opengis.referencing.crs.CoordinateReferenceSystem;
 import org.opengis.referencing.cs.CoordinateSystem;
@@ -46,6 +48,7 @@ import org.apache.sis.measure.Units;
 import org.apache.sis.util.Static;
 import org.apache.sis.util.CharSequences;
 import org.apache.sis.util.resources.Vocabulary;
+import org.apache.sis.internal.util.Constants;
 
 
 /**
@@ -246,6 +249,32 @@ public final class WKTUtilities extends
     }
 
     /**
+     * Returns {@code true} if the given parameter is defined in the EPSG code space. We
handle EPSG
+     * parameters in a special way because Apache SIS uses the EPSG geodetic dataset as the
primary
+     * source of coordinate operation definitions.
+     *
+     * <p>We intentionally don't define {@code isEPSG(OperationMethod)} method because
the operation
+     * method may be the inverse of an EPSG method (for example "Inverse of Mercator (variant
A)")
+     * which would not be recognized. Instead, {@code isEPSG(method.getParameters())} should
work.</p>
+     *
+     * @param  descriptor   the parameter or group of parameters to inspect.
+     * @param  ifUndefined  the value to return if the code space is undefined.
+     * @return whether the given parameter is an EPSG parameter.
+     */
+    public static boolean isEPSG(final GeneralParameterDescriptor descriptor, final boolean
ifUndefined) {
+        if (descriptor != null) {
+            final Identifier id = descriptor.getName();
+            if (id != null) {
+                final String cs = id.getCodeSpace();
+                if (cs != null) {
+                    return Constants.EPSG.equalsIgnoreCase(cs);
+                }
+            }
+        }
+        return ifUndefined;
+    }
+
+    /**
      * Returns the WKT type of the given interface.
      *
      * For {@link CoordinateSystem} base type, the returned value shall be one of

Modified: sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/internal/referencing/provider/Molodensky.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/internal/referencing/provider/Molodensky.java?rev=1814306&r1=1814305&r2=1814306&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/internal/referencing/provider/Molodensky.java
[UTF-8] (original)
+++ sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/internal/referencing/provider/Molodensky.java
[UTF-8] Sat Nov  4 16:37:12 2017
@@ -19,6 +19,7 @@ package org.apache.sis.internal.referenc
 import java.util.Map;
 import java.util.Collections;
 import javax.xml.bind.annotation.XmlTransient;
+import javax.measure.Unit;
 import org.opengis.util.FactoryException;
 import org.opengis.parameter.ParameterValueGroup;
 import org.opengis.parameter.ParameterDescriptor;
@@ -34,9 +35,11 @@ import org.apache.sis.referencing.datum.
 import org.apache.sis.referencing.operation.transform.MolodenskyTransform;
 import org.apache.sis.internal.referencing.NilReferencingObject;
 import org.apache.sis.internal.referencing.Formulas;
+import org.apache.sis.internal.system.Loggers;
 import org.apache.sis.internal.util.Constants;
 import org.apache.sis.measure.Units;
 import org.apache.sis.util.resources.Errors;
+import org.apache.sis.util.logging.Logging;
 import org.apache.sis.util.Debug;
 
 
@@ -226,6 +229,7 @@ public final class Molodensky extends Ge
         final Ellipsoid target = new Ellipsoid(name, ta, tb, -Δa, -Δf);
         source.other = target;
         target.other = source;
+        source.computeDifferences(values);
         return MolodenskyTransform.createGeodeticTransformation(factory,
                 source, sourceDimensions >= 3,
                 target, targetDimensions >= 3,
@@ -258,7 +262,7 @@ public final class Molodensky extends Ge
     @SuppressWarnings("serial")
     private static final class Ellipsoid extends DefaultEllipsoid {
         /** The EPSG parameter values, or NaN if unspecified. */
-        private final double Δa, Δf;
+        private double Δa, Δf;
 
         /** The ellipsoid for which Δa and Δf are valid. */
         Ellipsoid other;
@@ -270,6 +274,45 @@ public final class Molodensky extends Ge
             this.Δf = Δf;
         }
 
+        /**
+         * Computes Δa and Δf now if not already done and tries to store the result in
the given parameters.
+         * The parameters are set in order to complete them when the user specified the OGC
parameters (axis
+         * lengths) and not the EPSG ones (axis and flattening differences).
+         */
+        void computeDifferences(final Parameters values) {
+            if (Double.isNaN(Δa)) {
+                Δa = super.semiMajorAxisDifference(other);
+                setIfPresent(values, AXIS_LENGTH_DIFFERENCE, Δa, getAxisUnit());
+            }
+            if (Double.isNaN(Δf)) {
+                Δf = super.flatteningDifference(other);
+                setIfPresent(values, FLATTENING_DIFFERENCE, Δf, Units.UNITY);
+            }
+        }
+
+        /**
+         * Tries to set the given parameter values. This method should be invoked only when
completing parameters
+         * without explicit values. This approach complete the work done in {@code DefaultMathTransformFactory},
+         * which already completed the {@code src_semi_major}, {@code src_semi_minor}, {@code
tgt_semi_major} and
+         * {@code tgt_semi_minor} parameters.
+         *
+         * @param  values     the group in which to set the parameter values.
+         * @param  parameter  descriptor of the parameter to set.
+         * @param  value      the new value.
+         * @param  unit       unit of measurement for the new value.
+         */
+        private static void setIfPresent(final Parameters values, final ParameterDescriptor<Double>
parameter,
+                final double value, final Unit<?> unit)
+        {
+            try {
+                values.getOrCreate(parameter).setValue(value, unit);
+            } catch (ParameterNotFoundException | InvalidParameterValueException e) {
+                // Nonn-fatal since this attempt was only for information purpose.
+                Logging.recoverableException(Logging.getLogger(Loggers.COORDINATE_OPERATION),
+                        Molodensky.class, "createMathTransform", e);
+            }
+        }
+
         /** Returns Δa as specified in the parameters if possible, or compute it otherwise.
*/
         @Override public double semiMajorAxisDifference(final org.opengis.referencing.datum.Ellipsoid
target) {
             return (target == other && !Double.isNaN(Δa)) ? Δa : super.semiMajorAxisDifference(target);

Modified: sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/AbstractCoordinateOperation.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/AbstractCoordinateOperation.java?rev=1814306&r1=1814305&r2=1814306&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/AbstractCoordinateOperation.java
[UTF-8] (original)
+++ sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/AbstractCoordinateOperation.java
[UTF-8] Sat Nov  4 16:37:12 2017
@@ -53,6 +53,7 @@ import org.apache.sis.util.collection.Co
 import org.apache.sis.util.UnsupportedImplementationException;
 import org.apache.sis.util.logging.Logging;
 import org.apache.sis.parameter.Parameterized;
+import org.apache.sis.metadata.iso.citation.Citations;
 import org.apache.sis.referencing.cs.CoordinateSystems;
 import org.apache.sis.referencing.AbstractIdentifiedObject;
 import org.apache.sis.referencing.operation.transform.MathTransforms;
@@ -64,6 +65,7 @@ import org.apache.sis.internal.referenci
 import org.apache.sis.internal.referencing.WKTUtilities;
 import org.apache.sis.internal.metadata.WKTKeywords;
 import org.apache.sis.internal.metadata.MetadataUtilities;
+import org.apache.sis.internal.util.Constants;
 import org.apache.sis.internal.util.CollectionsExt;
 import org.apache.sis.internal.util.UnmodifiableArrayList;
 import org.apache.sis.internal.system.Semaphores;
@@ -963,10 +965,27 @@ check:      for (int isTarget=0; ; isTar
                 parameters = null;
             }
             if (parameters != null) {
+                /*
+                 * Format the parameter values. Apache SIS uses the EPSG geodetic dataset
as the main source of
+                 * parameter definitions. When a parameter is defined by both OGC and EPSG
with different names,
+                 * the Formatter class is responsible for choosing an appropriate name. But
when the difference
+                 * is more fundamental, we may have duplication. For example in the "Molodensky"
operation, OGC
+                 * uses source and target axis lengths while EPSG uses only difference between
those lengths.
+                 * In this case, OGC and EPSG parameters are defined separately and are redundant.
To simplify
+                 * the CoordinateOperation WKT, we omit non-EPSG parameters when we have
determined that we are
+                 * about to describe an EPSG operation. We could generalize this filtering
to any authority, but
+                 * we don't because few authorities are as complete as EPSG, so other authorities
are more likely
+                 * to mix EPSG or someone else components with their own. Note also that
we don't apply filtering
+                 * on MathTransform WKT neither for more reliable debugging.
+                 */
+                final boolean filter = WKTUtilities.isEPSG(parameters.getDescriptor(), false)
&&   // NOT method.getName()
+                        Constants.EPSG.equalsIgnoreCase(Citations.getCodeSpace(formatter.getNameAuthority()));
                 formatter.newLine();
                 formatter.indent(+1);
                 for (final GeneralParameterValue param : parameters.values()) {
-                    WKTUtilities.append(param, formatter);
+                    if (!filter || WKTUtilities.isEPSG(param.getDescriptor(), true)) {
+                        WKTUtilities.append(param, formatter);
+                    }
                 }
                 formatter.indent(-1);
             }

Modified: sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/referencing/operation/DefaultConcatenatedOperationTest.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/referencing/operation/DefaultConcatenatedOperationTest.java?rev=1814306&r1=1814305&r2=1814306&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/referencing/operation/DefaultConcatenatedOperationTest.java
[UTF-8] (original)
+++ sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/referencing/operation/DefaultConcatenatedOperationTest.java
[UTF-8] Sat Nov  4 16:37:12 2017
@@ -43,7 +43,7 @@ import static org.apache.sis.test.TestUt
  * Tests the {@link DefaultConcatenatedOperation} class.
  *
  * @author  Martin Desruisseaux (Geomatys)
- * @version 0.7
+ * @version 0.8
  * @since   0.7
  * @module
  */
@@ -114,9 +114,7 @@ public final strictfp class DefaultConca
                 "      Axis[“Latitude (B)”, north, Unit[“degree”, 0.017453292519943295]],\n"
+
                 "      Axis[“Ellipsoidal height (h)”, up, Unit[“metre”, 1]]]],\n"
+
                 "  CoordinateOperationStep[“Geographic to geocentric”,\n" +
-                "    Method[“Geographic/geocentric conversions”],\n" +
-                "      Parameter[“semi_major”, 6377397.155, Unit[“metre”, 1]],\n"
+
-                "      Parameter[“semi_minor”, 6356078.962818189, Unit[“metre”, 1]]],\n"
+
+                "    Method[“Geographic/geocentric conversions”]],\n" +         // Omit
non-EPSG parameters for EPSG method.
                 "  CoordinateOperationStep[“Tokyo to JGD2000 (GSI)”,\n" +
                 "    Method[“Geocentric translations”],\n" +
                 "      Parameter[“X-axis translation”, -146.414],\n" +



Mime
View raw message