sis-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From desruisse...@apache.org
Subject svn commit: r1683137 - in /sis/branches/JDK8/core: sis-metadata/src/main/java/org/apache/sis/internal/metadata/ sis-metadata/src/main/java/org/apache/sis/io/wkt/ sis-referencing/src/main/java/org/apache/sis/io/wkt/ sis-referencing/src/main/java/org/apa...
Date Tue, 02 Jun 2015 16:53:06 GMT
Author: desruisseaux
Date: Tue Jun  2 16:53:06 2015
New Revision: 1683137

URL: http://svn.apache.org/r1683137
Log:
Referencing: initial version of a CoordinateSystems.modifyAxes(...) method for changing the
units of a CoordinateSystem.
This is needed for WKT parsing of a GeocentricCRS.

Added:
    sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/cs/AxisFilter.java
  (with props)
Modified:
    sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/internal/metadata/ReferencingServices.java
    sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/io/wkt/MathTransformParser.java
    sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/io/wkt/GeodeticObjectParser.java
    sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/cs/AbstractCS.java
    sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/cs/AxesConvention.java
    sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/cs/CoordinateSystems.java
    sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/cs/DefaultEllipsoidalCS.java
    sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/cs/Normalizer.java
    sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/cs/package-info.java
    sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/referencing/cs/NormalizerTest.java
    sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/internal/util/MetadataServices.java

Modified: sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/internal/metadata/ReferencingServices.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/internal/metadata/ReferencingServices.java?rev=1683137&r1=1683136&r2=1683137&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/internal/metadata/ReferencingServices.java
[UTF-8] (original)
+++ sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/internal/metadata/ReferencingServices.java
[UTF-8] Tue Jun  2 16:53:06 2015
@@ -147,7 +147,7 @@ public class ReferencingServices extends
                                 break;
                             }
                         }
-                        Logging.unexpectedException(Logging.getLogger(logger),
+                        Logging.recoverableException(Logging.getLogger(logger),
                                 ReferencingServices.class, "getInstance", exception);
                         c = new ReferencingServices();
                     } catch (ReflectiveOperationException exception) {

Modified: sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/io/wkt/MathTransformParser.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/io/wkt/MathTransformParser.java?rev=1683137&r1=1683136&r2=1683137&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/io/wkt/MathTransformParser.java
[UTF-8] (original)
+++ sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/io/wkt/MathTransformParser.java
[UTF-8] Tue Jun  2 16:53:06 2015
@@ -312,7 +312,7 @@ class MathTransformParser extends Parser
     final OperationMethod getOperationMethod() {
         if (lastMethod == null) {
             /*
-             * Safety in case come MathTransformFactory implementation do not support
+             * Safety in case some MathTransformFactory implementations do not support
              * getLastMethod(). Performs a slower and less robust check as a fallback.
              */
             if (classification != null) {

Modified: sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/io/wkt/GeodeticObjectParser.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/io/wkt/GeodeticObjectParser.java?rev=1683137&r1=1683136&r2=1683137&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/io/wkt/GeodeticObjectParser.java
[UTF-8] (original)
+++ sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/io/wkt/GeodeticObjectParser.java
[UTF-8] Tue Jun  2 16:53:06 2015
@@ -60,6 +60,8 @@ import org.apache.sis.internal.referenci
 import org.apache.sis.internal.referencing.VerticalDatumTypes;
 import org.apache.sis.internal.system.DefaultFactories;
 import org.apache.sis.referencing.AbstractIdentifiedObject;
+import org.apache.sis.referencing.cs.CoordinateSystems;
+import org.apache.sis.referencing.cs.AxisFilter;
 import org.apache.sis.util.iso.Types;
 
 import static java.util.Collections.singletonMap;
@@ -695,6 +697,7 @@ final class GeodeticObjectParser extends
         final PrimeMeridian meridian   = parsePrimem(element, NonSI.DEGREE_ANGLE);
         final GeodeticDatum datum      = parseDatum (element, meridian);
         final Unit<Length>  linearUnit = parseUnit  (element, SI.METRE);
+        CartesianCS cs;
         CoordinateSystemAxis axis0, axis1 = null, axis2 = null;
         axis0 = parseAxis(element, linearUnit, false);
         try {
@@ -702,16 +705,20 @@ final class GeodeticObjectParser extends
                 axis1 = parseAxis(element, linearUnit, true);
                 axis2 = parseAxis(element, linearUnit, true);
             }
-            if (axis0 == null || isAxisIgnored) {
-                // Those default values are part of WKT specification.
-                // TODO: use CommonCRS.
-                axis0 = createAxis("X", AxisDirection.OTHER, linearUnit);
-                axis1 = createAxis("Y", AxisDirection.EAST,  linearUnit);
-                axis2 = createAxis("Z", AxisDirection.NORTH, linearUnit);
-            }
             final Map<String,?> properties = parseAuthorityAndClose(element, name);
-            CartesianCS cs = csFactory.createCartesianCS(properties, axis0, axis1, axis2);
-            cs = Legacy.forGeocentricCRS(cs, false);
+            if (axis0 != null && !isAxisIgnored) {
+                cs = csFactory.createCartesianCS(properties, axis0, axis1, axis2);
+                cs = Legacy.forGeocentricCRS(cs, false);
+            } else {
+                cs = (CartesianCS) CommonCRS.WGS84.geocentric().getCoordinateSystem();
+                if (!SI.METRE.equals(linearUnit)) {
+                    cs = (CartesianCS) CoordinateSystems.modifyAxes(cs, new AxisFilter()
{
+                        @Override public Unit<?> getUnitReplacement(final Unit<?>
unit) {
+                            return linearUnit;
+                        }
+                    });
+                }
+            }
             return crsFactory.createGeocentricCRS(properties, datum, cs);
         } catch (FactoryException exception) {
             throw element.parseFailed(exception);

Modified: sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/cs/AbstractCS.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/cs/AbstractCS.java?rev=1683137&r1=1683136&r2=1683137&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/cs/AbstractCS.java
[UTF-8] (original)
+++ sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/cs/AbstractCS.java
[UTF-8] Tue Jun  2 16:53:06 2015
@@ -65,7 +65,7 @@ import static org.apache.sis.util.Utilit
  *
  * @author  Martin Desruisseaux (IRD, Geomatys)
  * @since   0.4
- * @version 0.5
+ * @version 0.6
  * @module
  *
  * @see DefaultCoordinateSystemAxis
@@ -224,7 +224,7 @@ public class AbstractCS extends Abstract
     protected AbstractCS(final CoordinateSystem cs) {
         super(cs);
         if (cs instanceof AbstractCS) {
-            axes = ((AbstractCS) cs).axes; // Share the array.
+            axes = ((AbstractCS) cs).axes;  // Share the array.
         } else {
             axes = new CoordinateSystemAxis[cs.getDimension()];
             for (int i=0; i<axes.length; i++) {
@@ -341,12 +341,15 @@ public class AbstractCS extends Abstract
         AbstractCS cs = derived.get(convention);
         if (cs == null) {
             switch (convention) {
-                case NORMALIZED:              cs = Normalizer.normalize(this, true,  true);
 break;
-                case CONVENTIONALLY_ORIENTED: cs = Normalizer.normalize(this, true,  false);
break;
-                case RIGHT_HANDED:            cs = Normalizer.normalize(this, false, false);
break;
-                case POSITIVE_RANGE:          cs = Normalizer.shiftAxisRange(this);     
    break;
+                case NORMALIZED:              // Fall through
+                case CONVENTIONALLY_ORIENTED: cs = Normalizer.normalize(this, convention,
true); break;
+                case RIGHT_HANDED:            cs = Normalizer.normalize(this, null, true);
break;
+                case POSITIVE_RANGE:          cs = Normalizer.shiftAxisRange(this); break;
                 default: throw new AssertionError(convention);
             }
+            if (cs == null) {
+                cs = this;  // This coordinate system is already normalized.
+            }
             for (final AbstractCS existing : derived.values()) {
                 if (cs.equals(existing)) {
                     cs = existing;

Modified: sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/cs/AxesConvention.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/cs/AxesConvention.java?rev=1683137&r1=1683136&r2=1683137&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/cs/AxesConvention.java
[UTF-8] (original)
+++ sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/cs/AxesConvention.java
[UTF-8] Tue Jun  2 16:53:06 2015
@@ -16,8 +16,13 @@
  */
 package org.apache.sis.referencing.cs;
 
-import org.opengis.referencing.cs.AxisDirection;    // For javadoc
+import javax.measure.unit.Unit;
+import javax.measure.unit.SI;
+import javax.measure.unit.NonSI;
+import org.opengis.referencing.cs.AxisDirection;
 import org.opengis.referencing.cs.CoordinateSystem; // For javadoc
+import org.apache.sis.internal.referencing.AxisDirections;
+import org.apache.sis.measure.Units;
 
 
 /**
@@ -102,13 +107,13 @@ import org.opengis.referencing.cs.Coordi
  *
  * @author  Martin Desruisseaux (Geomatys)
  * @since   0.4
- * @version 0.5
+ * @version 0.6
  * @module
  *
  * @see AbstractCS#forConvention(AxesConvention)
  * @see org.apache.sis.referencing.crs.AbstractCRS#forConvention(AxesConvention)
  */
-public enum AxesConvention {
+public enum AxesConvention implements AxisFilter {
     /**
      * Axes order, direction and units of measure are forced to commonly used pre-defined
values.
      * This enum represents the following changes to apply on a coordinate system:
@@ -140,7 +145,27 @@ public enum AxesConvention {
      * @see CoordinateSystems#normalize(CoordinateSystem)
      * @see org.apache.sis.referencing.CommonCRS#normalizedGeographic()
      */
-    NORMALIZED,
+    NORMALIZED {
+        @Override
+        public Unit<?> getUnitReplacement(Unit<?> unit) {
+            if (Units.isLinear(unit)) {
+                unit = SI.METRE;
+            } else if (Units.isAngular(unit)) {
+                unit = NonSI.DEGREE_ANGLE;
+            } else if (Units.isTemporal(unit)) {
+                unit = NonSI.DAY;
+            }
+            return unit;
+        }
+
+        /*
+         * Same policy than AxesConvention.CONVENTIONALLY_ORIENTATED.
+         */
+        @Override
+        public AxisDirection getDirectionReplacement(final AxisDirection direction) {
+            return AxisDirections.isIntercardinal(direction) ? direction : AxisDirections.absolute(direction);
+        }
+    },
 
     /**
      * Axes are oriented toward conventional directions and ordered for a {@linkplain #RIGHT_HANDED
right-handed}
@@ -189,7 +214,16 @@ public enum AxesConvention {
      *
      * @since 0.5
      */
-    CONVENTIONALLY_ORIENTED,
+    CONVENTIONALLY_ORIENTED {
+        /*
+         * For now we do not touch to inter-cardinal directions (e.g. "North-East")
+         * because it is not clear which normalization policy would match common usage.
+         */
+        @Override
+        public AxisDirection getDirectionReplacement(final AxisDirection direction) {
+            return AxisDirections.isIntercardinal(direction) ? direction : AxisDirections.absolute(direction);
+        }
+    },
 
     /**
      * Axes are ordered for a <cite>right-handed</cite> coordinate system. Axis
directions, ranges or ordinate values

Added: sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/cs/AxisFilter.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/cs/AxisFilter.java?rev=1683137&view=auto
==============================================================================
--- sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/cs/AxisFilter.java
(added)
+++ sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/cs/AxisFilter.java
[UTF-8] Tue Jun  2 16:53:06 2015
@@ -0,0 +1,52 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.sis.referencing.cs;
+
+import org.opengis.referencing.cs.AxisDirection;
+import javax.measure.unit.Unit;
+
+
+/**
+ * Modifications to apply on the axes of a coordinate system in order to produce a new coordinate
system.
+ * Possible modifications include changes of axis unit direction.
+ *
+ * @author  Martin Desruisseaux (Geomatys)
+ * @since   0.6
+ * @version 0.6
+ * @module
+ */
+public interface AxisFilter {
+    /**
+     * Returns a replacement for the given axis direction.
+     *
+     * @param  direction The original axis direction.
+     * @return The new axis direction, or {@code direction} if there is no change.
+     */
+    default AxisDirection getDirectionReplacement(AxisDirection direction) {
+        return direction;
+    }
+
+    /**
+     * Returns a replacement for the given axis unit.
+     *
+     * @param  unit The original axis unit.
+     * @return The new axis unit, or {@code unit} if there is no change.
+     */
+    default Unit<?> getUnitReplacement(Unit<?> unit) {
+        return unit;
+    }
+}

Propchange: sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/cs/AxisFilter.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/cs/AxisFilter.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain;charset=UTF-8

Modified: sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/cs/CoordinateSystems.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/cs/CoordinateSystems.java?rev=1683137&r1=1683136&r2=1683137&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/cs/CoordinateSystems.java
[UTF-8] (original)
+++ sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/cs/CoordinateSystems.java
[UTF-8] Tue Jun  2 16:53:06 2015
@@ -300,6 +300,26 @@ public final class CoordinateSystems ext
     }
 
     /**
+     * Returns a coordinate system with axes modified according the given filter.
+     *
+     * @param  cs     The coordinate system.
+     * @param  filter The modifications to apply on coordinate system axes.
+     * @return The modified coordinate system, or {@code cs} if no change was needed.
+     *
+     * @since 0.6
+     */
+    public static CoordinateSystem modifyAxes(final CoordinateSystem cs, final AxisFilter
filter) {
+        ensureNonNull("filter", filter);
+        if (cs != null) {
+            final CoordinateSystem newCS = Normalizer.normalize(cs, filter, false);
+            if (newCS != null) {
+                return newCS;
+            }
+        }
+        return cs;
+    }
+
+    /**
      * Returns a coordinate system with {@linkplain AxesConvention#NORMALIZED normalized}
axis order and units.
      * This method is typically used together with {@link #swapAndScaleAxes swapAndScaleAxes}
for the creation
      * of a transformation step before some
@@ -317,7 +337,7 @@ public final class CoordinateSystems ext
      * description of map projection package}.
      *
      * @param  cs The coordinate system.
-     * @return A constant similar to the specified {@code cs} with normalized axes.
+     * @return A coordinate system similar to the specified {@code cs} with normalized axes.
      * @throws IllegalArgumentException if the specified coordinate system can not be normalized.
      *
      * @see AxesConvention#NORMALIZED
@@ -325,13 +345,17 @@ public final class CoordinateSystems ext
      * @since 0.6
      */
     public static CoordinateSystem normalize(final CoordinateSystem cs) throws IllegalArgumentException
{
-        if (cs == null) {
-            return null;
-        } else if (cs instanceof AbstractCS) {
-            // User may have overridden the 'forConvention' method.
-            return ((AbstractCS) cs).forConvention(AxesConvention.NORMALIZED);
-        } else {
-            return Normalizer.normalize(cs);
+        if (cs != null) {
+            if (cs instanceof AbstractCS) {
+                // User may have overridden the 'forConvention' method.
+                return ((AbstractCS) cs).forConvention(AxesConvention.NORMALIZED);
+            } else {
+                final CoordinateSystem newCS = Normalizer.normalize(cs, AxesConvention.NORMALIZED,
true);
+                if (newCS != null) {
+                    return newCS;
+                }
+            }
         }
+        return cs;
     }
 }

Modified: sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/cs/DefaultEllipsoidalCS.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/cs/DefaultEllipsoidalCS.java?rev=1683137&r1=1683136&r2=1683137&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/cs/DefaultEllipsoidalCS.java
[UTF-8] (original)
+++ sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/cs/DefaultEllipsoidalCS.java
[UTF-8] Tue Jun  2 16:53:06 2015
@@ -75,6 +75,7 @@ public class DefaultEllipsoidalCS extend
      */
     private DefaultEllipsoidalCS(final Map<String,?> properties, final CoordinateSystemAxis[]
axes) {
         super(properties, axes);
+        validateAxes(properties);
     }
 
     /**
@@ -121,13 +122,7 @@ public class DefaultEllipsoidalCS extend
                                 final CoordinateSystemAxis axis1)
     {
         super(properties, axis0, axis1);
-        for (int i=0; i<2; i++) {
-            final AxisDirection direction = super.getAxis(i).getDirection();
-            if (AxisDirections.isVertical(direction)) {
-                throw new IllegalArgumentException(Errors.getResources(properties).getString(
-                        Errors.Keys.IllegalAxisDirection_2, "EllipdoicalCS (2D)", direction));
-            }
-        }
+        validateAxes(properties);
     }
 
     /**
@@ -146,6 +141,7 @@ public class DefaultEllipsoidalCS extend
                                 final CoordinateSystemAxis axis2)
     {
         super(properties, axis0, axis1, axis2);
+        validateAxes(properties);
     }
 
     /**
@@ -202,6 +198,23 @@ public class DefaultEllipsoidalCS extend
     }
 
     /**
+     * Validates the set of axes after the validation of each individual axis.
+     *
+     * @param properties The properties given at construction time.
+     */
+    private void validateAxes(final Map<String,?> properties) {
+        int i = super.getDimension();
+        int n = i - 2; // Number of vertical axes allowed.
+        while (--i >= 0) {
+            final AxisDirection direction = super.getAxis(i).getDirection();
+            if (AxisDirections.isVertical(direction) && --n < 0) {
+                throw new IllegalArgumentException(Errors.getResources(properties).getString(
+                        Errors.Keys.IllegalAxisDirection_2, EllipsoidalCS.class, direction));
+            }
+        }
+    }
+
+    /**
      * Returns the GeoAPI interface implemented by this class.
      * The SIS implementation returns {@code EllipsoidalCS.class}.
      *

Modified: sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/cs/Normalizer.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/cs/Normalizer.java?rev=1683137&r1=1683136&r2=1683137&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/cs/Normalizer.java
[UTF-8] (original)
+++ sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/cs/Normalizer.java
[UTF-8] Tue Jun  2 16:53:06 2015
@@ -20,8 +20,6 @@ import java.util.Map;
 import java.util.HashMap;
 import java.util.Arrays;
 import javax.measure.unit.Unit;
-import javax.measure.unit.SI;
-import javax.measure.unit.NonSI;
 import javax.measure.converter.UnitConverter;
 import javax.measure.converter.ConversionException;
 import org.opengis.referencing.cs.RangeMeaning;
@@ -32,7 +30,6 @@ import org.apache.sis.internal.referenci
 import org.apache.sis.referencing.IdentifiedObjects;
 import org.apache.sis.util.resources.Errors;
 import org.apache.sis.util.CharSequences;
-import org.apache.sis.measure.Units;
 
 import static java.util.Collections.singletonMap;
 import static org.opengis.referencing.IdentifiedObject.NAME_KEY;
@@ -127,44 +124,22 @@ final class Normalizer implements Compar
      * Returns a new axis with the same properties (except identifiers) than given axis,
      * but with normalized axis direction and unit of measurement.
      *
-     * @param  axis The axis to normalize.
-     * @param  normalizeUnits {@code true} for normalizing units.
-     * @return An axis using normalized direction unit, or {@code axis} if the given axis
already uses the given unit.
+     * @param  axis    The axis to normalize.
+     * @param  changes The change to apply on axis direction and units.
+     * @return An axis using normalized direction and units, or {@code axis} if there is
no change.
      */
-    static CoordinateSystemAxis normalize(final CoordinateSystemAxis axis, final boolean
normalizeUnits) {
-        /*
-         * Normalize the axis direction. For now we do not touch to inter-cardinal directions
(e.g. "North-East")
-         * because it is not clear which normalization policy would match common usage.
-         */
+    static CoordinateSystemAxis normalize(final CoordinateSystemAxis axis, final AxisFilter
changes) {
+        final Unit<?>       unit      = axis.getUnit();
         final AxisDirection direction = axis.getDirection();
-        AxisDirection newDir = direction;
-        if (!AxisDirections.isIntercardinal(direction)) {
-            newDir = AxisDirections.absolute(direction);
-        }
-        final boolean sameDirection = newDir.equals(direction);
-        /*
-         * Normalize unit of measurement.
-         */
-        final Unit<?> unit = axis.getUnit(), newUnit;
-        if (normalizeUnits) {
-            if (Units.isLinear(unit)) {
-                newUnit = SI.METRE;
-            } else if (Units.isAngular(unit)) {
-                newUnit = NonSI.DEGREE_ANGLE;
-            } else if (Units.isTemporal(unit)) {
-                newUnit = NonSI.DAY;
-            } else {
-                newUnit = unit;
-            }
-        } else {
-            newUnit = unit;
-        }
+        final Unit<?>       newUnit   = changes.getUnitReplacement(unit);
+        final AxisDirection newDir    = changes.getDirectionReplacement(direction);
         /*
          * Reuse some properties (name, remarks, etc.) from the existing axis. If the direction
changed,
          * then the axis name may need change too (e.g. "Westing" → "Easting"). The new
axis name may be
          * set to "Unnamed", but the caller will hopefully be able to replace the returned
instance by
          * an instance from the EPSG database with appropriate name.
          */
+        final boolean sameDirection = newDir.equals(direction);
         if (sameDirection && newUnit.equals(unit)) {
             return axis;
         }
@@ -208,71 +183,42 @@ final class Normalizer implements Compar
     }
 
     /**
-     * Reorders the axes in an attempt to get a right-handed system.
-     * If no axis change is needed, then this method returns {@code cs} unchanged.
-     *
-     * @param  cs The coordinate system to normalize.
-     * @return The normalized coordinate system.
-     */
-    static CoordinateSystem normalize(final CoordinateSystem cs) {
-        final CoordinateSystemAxis[] axes = normalizeAxes(cs, true, true);
-        return (axes != null) ? createSameType(AbstractCS.castOrCopy(cs), axes) : cs;
-    }
-
-    /**
-     * Reorders the axes in an attempt to get a right-handed system.
-     * If no axis change is needed, then this method returns {@code cs} unchanged.
+     * Optionally normalizes and reorders the axes in an attempt to get a right-handed system.
+     * If no axis change is needed, then this method returns {@code null}.
      *
-     * @param  cs The coordinate system to normalize.
-     * @param  normalizeAxes  {@code true} for normalizing axis directions.
-     * @param  normalizeUnits {@code true} for normalizing units (currently ignored if {@code
normalizeAxes} is {@code false}).
-     * @return The normalized coordinate system.
+     * @param  cs      The coordinate system to normalize.
+     * @param  changes The change to apply on axis direction and units.
+     * @param  reorder {@code true} for reordering the axis for a right-handed coordinate
system.
+     * @return The normalized coordinate system, or {@code null} if no normalization is needed.
      */
-    static AbstractCS normalize(final AbstractCS cs, final boolean normalizeAxes, final boolean
normalizeUnits) {
-        final CoordinateSystemAxis[] axes = normalizeAxes(cs, normalizeAxes, normalizeUnits);
-        return (axes != null) ? createSameType(cs, axes) : cs;
-    }
-
-    /**
-     * Returns the normalized set of axes for the given coordinate system,
-     * or {@code null} if its axes were already normalized.
-     *
-     * @param  cs The coordinate system to normalize.
-     * @param  normalizeAxes  {@code true} for normalizing axis directions.
-     * @param  normalizeUnits {@code true} for normalizing units (currently ignored if {@code
normalizeAxes} is {@code false}).
-     * @return The normalized set of coordinate system axes.
-     */
-    private static CoordinateSystemAxis[] normalizeAxes(final CoordinateSystem cs,
-            final boolean normalizeAxes, final boolean normalizeUnits)
-    {
+    static AbstractCS normalize(final CoordinateSystem cs, final AxisFilter changes, final
boolean reorder) {
         boolean changed = false;
         final int dimension = cs.getDimension();
         final CoordinateSystemAxis[] axes = new CoordinateSystemAxis[dimension];
         for (int i=0; i<dimension; i++) {
             CoordinateSystemAxis axis = cs.getAxis(i);
-            if (normalizeAxes) {
-                changed |= (axis != (axis = normalize(axis, normalizeUnits)));
+            if (changes != null) {
+                changed |= (axis != (axis = normalize(axis, changes)));
             }
             axes[i] = axis;
         }
         /*
-         * Sorts the axis in an attempt to create a right-handed system.
-         * Caller will create a new Coordinate System only if at least one axis changed.
+         * Sort the axes in an attempt to create a right-handed system.
+         * If nothing changed, return the given Coordinate System as-is.
          */
-        changed |= sort(axes);
-        return changed ? axes : null;
-    }
-
-    /**
-     * Creates a new coordinate system of the same type than the given one, but with the
given axes.
-     *
-     * @param  cs   The coordinate system to copy.
-     * @param  axes The set of axes to give to the new coordinate system.
-     * @return A new coordinate system of the same type than {@code cs}, but using the given
axes.
-     */
-    private static AbstractCS createSameType(final AbstractCS cs, final CoordinateSystemAxis[]
axes) {
-        final StringBuilder buffer = (StringBuilder) CharSequences.camelCaseToSentence(cs.getInterface().getSimpleName());
-        return cs.createSameType(singletonMap(AbstractCS.NAME_KEY, DefaultCompoundCS.createName(buffer,
axes)), axes);
+        if (reorder) {
+            changed |= sort(axes);
+        }
+        if (!changed) {
+            return null;
+        }
+        /*
+         * Create a new coordinate system of the same type than the given one, but with the
given axes.
+         * We need to change the Coordinate System name, since it is likely to not be valid
anymore.
+         */
+        final AbstractCS impl = (cs instanceof AbstractCS) ? (AbstractCS) cs : AbstractCS.castOrCopy(cs);
+        final StringBuilder buffer = (StringBuilder) CharSequences.camelCaseToSentence(impl.getInterface().getSimpleName());
+        return impl.createSameType(singletonMap(AbstractCS.NAME_KEY, DefaultCompoundCS.createName(buffer,
axes)), axes);
     }
 
     /**

Modified: sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/cs/package-info.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/cs/package-info.java?rev=1683137&r1=1683136&r2=1683137&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/cs/package-info.java
[UTF-8] (original)
+++ sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/cs/package-info.java
[UTF-8] Tue Jun  2 16:53:06 2015
@@ -30,7 +30,7 @@
  *
  * @author  Martin Desruisseaux (IRD, Geomatys)
  * @since   0.4
- * @version 0.4
+ * @version 0.6
  * @module
  */
 @XmlSchema(elementFormDefault = XmlNsForm.QUALIFIED, namespace = Namespaces.GML, xmlns =
{

Modified: sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/referencing/cs/NormalizerTest.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/referencing/cs/NormalizerTest.java?rev=1683137&r1=1683136&r2=1683137&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/referencing/cs/NormalizerTest.java
[UTF-8] (original)
+++ sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/referencing/cs/NormalizerTest.java
[UTF-8] Tue Jun  2 16:53:06 2015
@@ -36,7 +36,7 @@ import static org.apache.sis.test.Refere
  *
  * @author  Martin Desruisseaux (IRD, Geomatys)
  * @since   0.4
- * @version 0.5
+ * @version 0.6
  * @module
  */
 @DependsOn({
@@ -162,31 +162,38 @@ public final strictfp class NormalizerTe
     }
 
     /**
+     * Asserts that a collection of pre-defined axes is not modified by the given {@link
AxesConvention}.
+     */
+    private static void assertSameAfterNormalization(final AxisFilter changes) {
+        assertSame(HardCodedAxes.GEODETIC_LATITUDE,  Normalizer.normalize(HardCodedAxes.GEODETIC_LATITUDE,
changes));
+        assertSame(HardCodedAxes.GEODETIC_LONGITUDE, Normalizer.normalize(HardCodedAxes.GEODETIC_LONGITUDE,
changes));
+        assertSame(HardCodedAxes.EASTING,            Normalizer.normalize(HardCodedAxes.EASTING,
changes));
+        assertSame(HardCodedAxes.NORTHING,           Normalizer.normalize(HardCodedAxes.NORTHING,
changes));
+        assertSame(HardCodedAxes.ALTITUDE,           Normalizer.normalize(HardCodedAxes.ALTITUDE,
changes));
+        assertSame(HardCodedAxes.TIME,               Normalizer.normalize(HardCodedAxes.TIME,
changes));
+    }
+
+    /**
      * Tests {@link Normalizer#normalize(CoordinateSystemAxis)}.
      */
     @Test
     public void testNormalizeAxis() {
-        boolean normalizeUnits = false;
-        do { // Executed twice, first without units normalization, then with units normalization.
-            assertSame(HardCodedAxes.GEODETIC_LATITUDE,  Normalizer.normalize(HardCodedAxes.GEODETIC_LATITUDE,
normalizeUnits));
-            assertSame(HardCodedAxes.GEODETIC_LONGITUDE, Normalizer.normalize(HardCodedAxes.GEODETIC_LONGITUDE,
normalizeUnits));
-            assertSame(HardCodedAxes.EASTING,            Normalizer.normalize(HardCodedAxes.EASTING,
normalizeUnits));
-            assertSame(HardCodedAxes.NORTHING,           Normalizer.normalize(HardCodedAxes.NORTHING,
normalizeUnits));
-            assertSame(HardCodedAxes.ALTITUDE,           Normalizer.normalize(HardCodedAxes.ALTITUDE,
normalizeUnits));
-            assertSame(HardCodedAxes.TIME,               Normalizer.normalize(HardCodedAxes.TIME,
normalizeUnits));
-        } while ((normalizeUnits = !normalizeUnits) == true);
+        // Execute twice, first without units normalization, then with units normalization.
+        assertSameAfterNormalization(AxesConvention.CONVENTIONALLY_ORIENTED);
+        assertSameAfterNormalization(AxesConvention.NORMALIZED);
         /*
          * Test a change of unit from centimetre to metre.
          */
-        assertSame(HardCodedAxes.HEIGHT_cm, Normalizer.normalize(HardCodedAxes.HEIGHT_cm,
false));
+        assertSame(HardCodedAxes.HEIGHT_cm, Normalizer.normalize(HardCodedAxes.HEIGHT_cm,
+                AxesConvention.CONVENTIONALLY_ORIENTED));   // Do not change unit.
         assertAxisEquals("Height", "h", AxisDirection.UP,
             Double.NEGATIVE_INFINITY, Double.POSITIVE_INFINITY, SI.METRE, null,
-            Normalizer.normalize(HardCodedAxes.HEIGHT_cm, true));
+            Normalizer.normalize(HardCodedAxes.HEIGHT_cm, AxesConvention.NORMALIZED));
         /*
          * Test a change of direction from West to East.
          */
         assertAxisEquals(Vocabulary.format(Vocabulary.Keys.Unnamed), "E",
             AxisDirection.EAST, Double.NEGATIVE_INFINITY, Double.POSITIVE_INFINITY, SI.METRE,
null,
-            Normalizer.normalize(HardCodedAxes.WESTING, true));
+            Normalizer.normalize(HardCodedAxes.WESTING, AxesConvention.NORMALIZED));
     }
 }

Modified: sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/internal/util/MetadataServices.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/internal/util/MetadataServices.java?rev=1683137&r1=1683136&r2=1683137&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/internal/util/MetadataServices.java
[UTF-8] (original)
+++ sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/internal/util/MetadataServices.java
[UTF-8] Tue Jun  2 16:53:06 2015
@@ -78,7 +78,7 @@ public class MetadataServices extends Sy
                     try {
                         c = (MetadataServices) Class.forName("org.apache.sis.internal.metadata.ServicesForUtility").newInstance();
                     } catch (ClassNotFoundException exception) {
-                        Logging.unexpectedException(Logging.getLogger(Modules.UTILITIES),
+                        Logging.recoverableException(Logging.getLogger(Modules.UTILITIES),
                                 MetadataServices.class, "getInstance", exception);
                         c = new MetadataServices();
                     } catch (ReflectiveOperationException exception) {



Mime
View raw message