sis-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From desruisse...@apache.org
Subject svn commit: r1677692 - in /sis/branches/JDK8/core: sis-metadata/src/main/java/org/apache/sis/io/wkt/ sis-referencing/src/main/java/org/apache/sis/referencing/crs/ sis-referencing/src/main/java/org/apache/sis/referencing/operation/ sis-referencing/src/t...
Date Mon, 04 May 2015 21:30:42 GMT
Author: desruisseaux
Date: Mon May  4 21:30:41 2015
New Revision: 1677692

URL: http://svn.apache.org/r1677692
Log:
Referencing: partial support of WKT 2 formatting for DerivedCRS.
This work implies a change of strategy in the way we handle "baseCRS" formatting,
because almost all CRS can be used as "baseCRS". We also restrict the 'sourceCRS'
and 'targetCRS' types allowed in 'Projection' in order to reduce the risk of errors.

Modified:
    sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/io/wkt/Formatter.java
    sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/crs/AbstractCRS.java
    sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/crs/AbstractDerivedCRS.java
    sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/crs/DefaultDerivedCRS.java
    sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/crs/DefaultEngineeringCRS.java
    sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/crs/DefaultGeocentricCRS.java
    sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/crs/DefaultGeodeticCRS.java
    sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/crs/DefaultGeographicCRS.java
    sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/crs/DefaultImageCRS.java
    sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/crs/DefaultProjectedCRS.java
    sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/crs/DefaultTemporalCRS.java
    sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/crs/DefaultVerticalCRS.java
    sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/DefaultConicProjection.java
    sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/DefaultCylindricalProjection.java
    sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/DefaultPlanarProjection.java
    sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/DefaultProjection.java
    sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/referencing/crs/DefaultCompoundCRSTest.java
    sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/referencing/crs/DefaultGeocentricCRSTest.java
    sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/referencing/crs/DefaultGeographicCRSTest.java
    sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/referencing/crs/DefaultProjectedCRSTest.java

Modified: sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/io/wkt/Formatter.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/io/wkt/Formatter.java?rev=1677692&r1=1677691&r2=1677692&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/io/wkt/Formatter.java [UTF-8] (original)
+++ sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/io/wkt/Formatter.java [UTF-8] Mon May  4 21:30:41 2015
@@ -1375,22 +1375,21 @@ public class Formatter implements Locali
      * Applications can test {@link #isInvalidWKT()} later for checking WKT validity.
      *
      * <p>If any {@code setInvalidWKT(…)} method is invoked more than once during formatting,
-     * then only information about the first failure will be retained.</p>
+     * then only information about the last failure will be retained. The reason is that the
+     * last failure is typically the enclosing element.</p>
      *
      * @param unformattable The object that can not be formatted,
      * @param cause The cause for the failure to format, or {@code null} if the cause is not an exception.
      */
     public void setInvalidWKT(final IdentifiedObject unformattable, final Exception cause) {
         ArgumentChecks.ensureNonNull("unformattable", unformattable);
-        if (invalidElement == null) {
-            String name;
-            final Identifier id = unformattable.getName();
-            if (id == null || (name = id.getCode()) == null) {
-                name = getName(unformattable.getClass());
-            }
-            invalidElement = name;
-            errorCause     = cause;
+        String name;
+        final Identifier id = unformattable.getName();
+        if (id == null || (name = id.getCode()) == null) {
+            name = getName(unformattable.getClass());
         }
+        invalidElement = name;
+        errorCause     = cause;
         highlightError = true;
     }
 

Modified: sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/crs/AbstractCRS.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/crs/AbstractCRS.java?rev=1677692&r1=1677691&r2=1677692&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/crs/AbstractCRS.java [UTF-8] (original)
+++ sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/crs/AbstractCRS.java [UTF-8] Mon May  4 21:30:41 2015
@@ -28,6 +28,7 @@ import org.opengis.referencing.cs.Affine
 import org.opengis.referencing.cs.CartesianCS;
 import org.opengis.referencing.cs.CoordinateSystem;
 import org.opengis.referencing.crs.SingleCRS;
+import org.opengis.referencing.crs.GeneralDerivedCRS;
 import org.opengis.referencing.crs.CoordinateReferenceSystem;
 import org.apache.sis.internal.referencing.ReferencingUtilities;
 import org.apache.sis.referencing.AbstractReferenceSystem;
@@ -79,7 +80,7 @@ import java.util.Objects;
  *
  * @author  Martin Desruisseaux (IRD, Geomatys)
  * @since   0.4
- * @version 0.5
+ * @version 0.6
  * @module
  *
  * @see AbstractCS
@@ -462,18 +463,38 @@ public class AbstractCRS extends Abstrac
         formatter.newLine();
         formatter.append(toFormattable(getDatum()));
         formatter.newLine();
-        formatCS(formatter, getCoordinateSystem(), formatter.getConvention().majorVersion() == 1);
+        final boolean isWKT1 = formatter.getConvention().majorVersion() == 1;
+        if (isWKT1 || !isBaseCRS(formatter)) {
+            formatCS(formatter, getCoordinateSystem(), isWKT1);
+        }
         return keyword;
     }
 
     /**
+     * Returns {@code true} if the given formatter is in the process of formatting the base CRS of a
+     * {@link AbstractDerivedCRS}. In such case, the coordinate system axes shall not be formatted.
+     *
+     * <p>This method should be invoked for WKT 2 formatting only.</p>
+     */
+    static boolean isBaseCRS(final Formatter formatter) {
+        return formatter.getEnclosingElement(1) instanceof GeneralDerivedCRS;
+    }
+
+    /**
      * Formats the given coordinate system.
      *
+     * <p>In WKT 2 format, this method should not be invoked if {@link #isBaseCRS(Formatter)} returned {@code true}
+     * because ISO 19162 excludes the coordinate system definition in base CRS. Note however that WKT 1 includes the
+     * coordinate systems.</p>
+     *
      * @param formatter The formatter where to append the coordinate system.
      * @param cs        The coordinate system to append.
      * @param isWKT1    {@code true} if formatting WKT 1, or {@code false} for WKT 2.
      */
     final void formatCS(final Formatter formatter, final CoordinateSystem cs, final boolean isWKT1) {
+        assert (formatter.getConvention().majorVersion() == 1) == isWKT1 : isWKT1;
+        assert isWKT1 || !isBaseCRS(formatter) : isWKT1;    // Condition documented in javadoc.
+
         final Unit<?> unit    = ReferencingUtilities.getUnit(cs);
         final Unit<?> oldUnit = formatter.addContextualUnit(unit);
         if (isWKT1) { // WKT 1 writes unit before axes, while WKT 2 writes them after axes.

Modified: sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/crs/AbstractDerivedCRS.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/crs/AbstractDerivedCRS.java?rev=1677692&r1=1677691&r2=1677692&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/crs/AbstractDerivedCRS.java [UTF-8] (original)
+++ sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/crs/AbstractDerivedCRS.java [UTF-8] Mon May  4 21:30:41 2015
@@ -26,15 +26,12 @@ import org.opengis.referencing.crs.Singl
 import org.opengis.referencing.crs.GeneralDerivedCRS;
 import org.opengis.referencing.cs.CoordinateSystem;
 import org.opengis.referencing.operation.Conversion;
-import org.opengis.geometry.MismatchedDimensionException;
 import org.opengis.referencing.operation.MathTransform;
-import org.opengis.referencing.operation.NoninvertibleTransformException;
+import org.opengis.geometry.MismatchedDimensionException;
 import org.apache.sis.referencing.operation.DefaultConversion;
-import org.apache.sis.internal.referencing.WKTUtilities;
 import org.apache.sis.internal.system.Semaphores;
 import org.apache.sis.util.ArgumentChecks;
 import org.apache.sis.util.ComparisonMode;
-import org.apache.sis.io.wkt.Formatter;
 
 import static org.apache.sis.util.Utilities.deepEquals;
 
@@ -54,7 +51,7 @@ import static org.apache.sis.util.Utilit
 @XmlSeeAlso({
     DefaultProjectedCRS.class
 })
-class AbstractDerivedCRS extends AbstractCRS implements GeneralDerivedCRS {
+abstract class AbstractDerivedCRS extends AbstractCRS implements GeneralDerivedCRS {
     /**
      * Serial number for inter-operability with different versions.
      */
@@ -150,7 +147,7 @@ class AbstractDerivedCRS extends Abstrac
      */
     @Override
     public SingleCRS getBaseCRS() {
-        return (SingleCRS) conversionFromBase.getSourceCRS();
+        return (SingleCRS) getConversionFromBase().getSourceCRS();
     }
 
     /**
@@ -214,27 +211,4 @@ class AbstractDerivedCRS extends Abstrac
                + 31 * conversionFromBase.getSourceCRS().hashCode()
                + 37 * conversionFromBase.getMathTransform().hashCode();
     }
-
-    /**
-     * Formats the inner part of the <cite>Well Known Text</cite> (WKT) representation of this CRS.
-     *
-     * @return {@code "Fitted_CS"} (WKT 1).
-     */
-    @Override
-    protected String formatTo(final Formatter formatter) {
-        WKTUtilities.appendName(this, formatter, null);
-        final Conversion conversionFromBase = getConversionFromBase();  // Gives to users a chance to override.
-        MathTransform inverse = conversionFromBase.getMathTransform();
-        try {
-            inverse = inverse.inverse();
-        } catch (NoninvertibleTransformException exception) {
-            // TODO: provide a more accurate error message.
-            throw new IllegalStateException(exception.getLocalizedMessage(), exception);
-        }
-        formatter.newLine();
-        formatter.append(inverse);
-        formatter.newLine();
-        formatter.append(WKTUtilities.toFormattable(getBaseCRS()));
-        return "Fitted_CS";
-    }
 }

Modified: sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/crs/DefaultDerivedCRS.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/crs/DefaultDerivedCRS.java?rev=1677692&r1=1677691&r2=1677692&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/crs/DefaultDerivedCRS.java [UTF-8] (original)
+++ sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/crs/DefaultDerivedCRS.java [UTF-8] Mon May  4 21:30:41 2015
@@ -18,11 +18,19 @@ package org.apache.sis.referencing.crs;
 
 import java.util.Map;
 import javax.xml.bind.annotation.XmlTransient;
+import org.opengis.parameter.GeneralParameterValue;
+import org.opengis.referencing.datum.Datum;
 import org.opengis.referencing.crs.SingleCRS;
 import org.opengis.referencing.crs.DerivedCRS;
 import org.opengis.referencing.cs.CoordinateSystem;
 import org.opengis.referencing.operation.Conversion;
+import org.opengis.referencing.operation.MathTransform;
+import org.opengis.referencing.operation.NoninvertibleTransformException;
 import org.opengis.geometry.MismatchedDimensionException;
+import org.apache.sis.referencing.operation.DefaultOperationMethod;
+import org.apache.sis.internal.referencing.WKTUtilities;
+import org.apache.sis.io.wkt.FormattableObject;
+import org.apache.sis.io.wkt.Formatter;
 
 
 /**
@@ -166,4 +174,110 @@ public class DefaultDerivedCRS extends A
     public Class<? extends DerivedCRS> getInterface() {
         return DerivedCRS.class;
     }
+
+    /**
+     * Returns the datum of the {@linkplain #getBaseCRS() base CRS}.
+     *
+     * @return The datum of the base CRS.
+     */
+    @Override
+    public Datum getDatum() {
+        return super.getDatum();
+    }
+
+    /**
+     * Returns the {@linkplain org.apache.sis.referencing.operation.DefaultConversion#getSourceCRS() source}
+     * of the {@linkplain #getConversionFromBase() conversion from base}.
+     *
+     * @return The base coordinate reference system.
+     */
+    @Override
+    public SingleCRS getBaseCRS() {
+        return super.getBaseCRS();
+    }
+
+    /**
+     * Returns the conversion from the {@linkplain #getBaseCRS() base CRS} to this CRS.
+     * In Apache SIS, the conversion source and target CRS are set to the following values:
+     *
+     * <ul>
+     *   <li>The conversion {@linkplain org.apache.sis.referencing.operation.DefaultConversion#getSourceCRS()
+     *       source CRS} defines the {@linkplain #getBaseCRS() base CRS} of {@code this} CRS.</li>
+     *   <li>The conversion {@linkplain org.apache.sis.referencing.operation.DefaultConversion#getTargetCRS()
+     *       target CRS} is {@code this} CRS.
+     * </ul>
+     *
+     * <div class="note"><b>Note:</b>
+     * This is different than ISO 19111, which allows source and target CRS to be {@code null}.</div>
+     *
+     * @return The conversion to this CRS.
+     */
+    @Override
+    public Conversion getConversionFromBase() {
+        return super.getConversionFromBase();
+    }
+
+    /**
+     * Formats the inner part of the <cite>Well Known Text</cite> (WKT) representation of this CRS.
+     *
+     * @return {@code "Fitted_CS"} (WKT 1) or a type-dependent keyword (WKT 2).
+     */
+    @Override
+    protected String formatTo(final Formatter formatter) {
+        WKTUtilities.appendName(this, formatter, null);
+        final boolean isWKT1 = (formatter.getConvention().majorVersion() == 1);
+        final Conversion conversionFromBase = getConversionFromBase();  // Gives to users a chance to override.
+        /*
+         * Both WKT 1 and WKT 2 format the base CRS. But WKT 1 formats the MathTransform before the base CRS,
+         * while WKT 2 formats the conversion method and parameter values after the base CRS.
+         */
+        if (isWKT1) {
+            MathTransform inverse = conversionFromBase.getMathTransform();
+            try {
+                inverse = inverse.inverse();
+            } catch (NoninvertibleTransformException exception) {
+                formatter.setInvalidWKT(this, exception);
+                inverse = null;
+            }
+            formatter.newLine();
+            formatter.append(inverse);
+        }
+        formatter.newLine();
+        formatter.append(WKTUtilities.toFormattable(getBaseCRS()));
+        if (isWKT1) {
+            return "Fitted_CS";
+        } else {
+            formatter.append(new Parameters(this));    // Format inside a "DefiningConversion" element.
+            if (!isBaseCRS(formatter)) {
+                formatCS(formatter, getCoordinateSystem(), isWKT1);
+            }
+            return "EngineeringCRS"; // TODO: may be GeodeticCRS, VerticalCRS, etc.
+        }
+    }
+
+    /**
+     * Temporary object for formatting the conversion method and parameters inside a
+     * a {@code DerivingConversion} element. This is used in WKT 2 formatting only.
+     */
+    private static final class Parameters extends FormattableObject {
+        /** The conversion which specify the operation method and parameters. */
+        private final Conversion conversion;
+
+        /** Creates a new temporary {@code DerivingConversion} elements for the parameters of the given CRS. */
+        Parameters(final AbstractDerivedCRS crs) {
+            conversion = crs.getConversionFromBase();
+        }
+
+        /** Formats this {@code Conversion} element. */
+        @Override protected String formatTo(final Formatter formatter) {
+            WKTUtilities.appendName(conversion, formatter, null);
+            formatter.newLine();
+            formatter.append(DefaultOperationMethod.castOrCopy(conversion.getMethod()));
+            formatter.newLine();
+            for (final GeneralParameterValue param : conversion.getParameterValues().values()) {
+                WKTUtilities.append(param, formatter);
+            }
+            return "DerivingConversion";
+        }
+    }
 }

Modified: sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/crs/DefaultEngineeringCRS.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/crs/DefaultEngineeringCRS.java?rev=1677692&r1=1677691&r2=1677692&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/crs/DefaultEngineeringCRS.java [UTF-8] (original)
+++ sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/crs/DefaultEngineeringCRS.java [UTF-8] Mon May  4 21:30:41 2015
@@ -62,7 +62,7 @@ import static org.apache.sis.util.Argume
  *
  * @author  Martin Desruisseaux (IRD, Geomatys)
  * @since   0.4
- * @version 0.4
+ * @version 0.6
  * @module
  */
 @XmlType(name = "EngineeringCRSType", propOrder = {
@@ -260,6 +260,7 @@ public class DefaultEngineeringCRS exten
     @Override
     protected String formatTo(final Formatter formatter) {
         super.formatTo(formatter);
-        return (formatter.getConvention().majorVersion() == 1) ? "Local_CS" : "EngineeringCRS";
+        return (formatter.getConvention().majorVersion() == 1) ? "Local_CS"
+               : isBaseCRS(formatter) ? "BaseEngCRS" : "EngineeringCRS";
     }
 }

Modified: sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/crs/DefaultGeocentricCRS.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/crs/DefaultGeocentricCRS.java?rev=1677692&r1=1677691&r2=1677692&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/crs/DefaultGeocentricCRS.java [UTF-8] (original)
+++ sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/crs/DefaultGeocentricCRS.java [UTF-8] Mon May  4 21:30:41 2015
@@ -245,7 +245,7 @@ public class DefaultGeocentricCRS extend
      *   GEOCCS["Geocentric",
      *     DATUM["World Geodetic System 1984",
      *       SPHEROID["WGS84", 6378137.0, 298.257223563]],
-     *     PRIMEM["Greenwich", 0.0],
+     *       PRIMEM["Greenwich", 0.0],
      *     UNIT["metre", 1],
      *     AXIS["X", OTHER],
      *     AXIS["Y", EAST],

Modified: sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/crs/DefaultGeodeticCRS.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/crs/DefaultGeodeticCRS.java?rev=1677692&r1=1677691&r2=1677692&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/crs/DefaultGeodeticCRS.java [UTF-8] (original)
+++ sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/crs/DefaultGeodeticCRS.java [UTF-8] Mon May  4 21:30:41 2015
@@ -168,66 +168,81 @@ class DefaultGeodeticCRS extends Abstrac
 
     /**
      * Formats this CRS as a <cite>Well Known Text</cite> {@code GeodeticCRS[…]} element.
+     * More information about the WKT format is documented in subclasses.
      *
      * @return {@code "GeodeticCRS"} (WKT 2) or {@code "GeogCS"}/{@code "GeocCS"} (WKT 1).
      */
     @Override
     protected String formatTo(final Formatter formatter) {
         WKTUtilities.appendName(this, formatter, null);
-        final boolean isWKT1 = (formatter.getConvention().majorVersion() == 1);
-        formatDatum(formatter, getDatum(), isWKT1);
+        final Convention convention = formatter.getConvention();
+        final boolean isWKT1 = (convention.majorVersion() == 1);
+        /*
+         * Unconditionally format the datum element, followed by the prime meridian.
+         * The prime meridian is part of datum according ISO 19111, but is formatted
+         * as a sibling (rather than a child) element in WKT for historical reasons.
+         */
+        final GeodeticDatum datum = getDatum();     // Gives subclasses a chance to override.
+        formatter.newLine();
+        formatter.append(toFormattable(datum));
+        formatter.newLine();
+        final PrimeMeridian pm = datum.getPrimeMeridian();
+        if (convention != Convention.WKT2_SIMPLIFIED ||
+                ReferencingUtilities.getGreenwichLongitude(pm, NonSI.DEGREE_ANGLE) != 0)
+        {
+            formatter.indent(1);
+            formatter.append(toFormattable(pm));
+            formatter.indent(-1);
+            formatter.newLine();
+        }
+        /*
+         * Get the coordinate system to format. This will also determine the units to write and the keyword to
+         * return in WKT 1 format. Note that for the WKT 1 format, we need to replace the coordinate system by
+         * an instance conform to the legacy conventions.
+         *
+         * We can not delegate the work below to subclasses,  because XML unmarshalling of a geodetic CRS will
+         * NOT create an instance of a subclass (because the distinction between geographic and geocentric CRS
+         * is not anymore in ISO 19111:2007).
+         */
         CoordinateSystem cs = getCoordinateSystem();
+        final boolean isBaseCRS;
         if (isWKT1) {
-            /*
-             * Replaces the given coordinate system by an instance conform to the conventions used in WKT 1.
-             * Note that we can not delegate this task to subclasses, because XML unmarshalling of a geodetic
-             * CRS will NOT create an instance of a subclass (because the distinction between geographic and
-             * geocentric CRS is not anymore in ISO 19111:2007).
-             */
             if (!(cs instanceof EllipsoidalCS)) { // Tested first because this is the most common case.
                 if (cs instanceof CartesianCS) {
                     cs = Legacy.forGeocentricCRS((CartesianCS) cs, true);
                 } else {
-                    formatter.setInvalidWKT(cs, null);
+                    formatter.setInvalidWKT(cs, null);  // SphericalCS was not supported in WKT 1.
                 }
             }
+            isBaseCRS = false;
+        } else {
+            isBaseCRS = isBaseCRS(formatter);
         }
-        formatCS(formatter, cs, isWKT1);
-        if (!isWKT1) {
-            return "GeodeticCRS";
+        /*
+         * Format the coordinate system, except if this CRS is the base CRS of an AbstractDerivedCRS in WKT 2 format.
+         * This is because ISO 19162 omits the coordinate system definition of enclosed base CRS in order to simplify
+         * the WKT. The 'formatCS(…)' method may write axis unit before or after the axes depending on whether we are
+         * formatting WKT version 1 or 2 respectively.
+         *
+         * Note that even if we do not format the CS, we may still write the units if we are formatting in "simplified"
+         * mode (as opposed to the more verbose mode). This looks like the opposite of what we would expect, but this is
+         * because formatting the unit here allow us to avoid repeating the unit in projection parameters when this CRS
+         * is part of a ProjectedCRS.
+         */
+        if (!isBaseCRS) {
+            formatCS(formatter, cs, isWKT1);    // Will also format the axis unit.
+        } else if (convention.isSimplified()) {
+            formatter.append(formatter.toContextualUnit(ReferencingUtilities.getAngularUnit(cs)));
         }
         /*
-         * For WKT1, the keyword depends on the subclass: "GeogCS" for GeographicCRS,
-         * or 'GeocCS" for GeocentricCRS. However we can not rely on the subclass for
-         * choosing the keyword, because in some situations (after XML unmarhaling)
-         * we only have a GeodeticCRS. We need to make the choice here. The CS type
-         * is a sufficient criterion.
+         * For WKT 1, the keyword depends on the subclass: "GeogCS" for GeographicCRS or "GeocCS" for GeocentricCRS.
+         * However we can not rely on the subclass for choosing the keyword, because after XML unmarhaling we only
+         * have a GeodeticCRS. We need to make the choice in this base class. The CS type is a sufficient criterion.
          */
-        return (cs instanceof EllipsoidalCS) ? "GeogCS" : "GeocCS";
-    }
-
-    /**
-     * Formats the given geodetic datum to the given formatter. This is part of the WKT formatting
-     * for a geodetic CRS, either standalone or as part of a projected CRS.
-     *
-     * @param formatter Where to format the datum.
-     * @param datum     The datum to format.
-     * @param isWKT1    {@code true} if formatting WKT 1, or {@code false} for WKT 2.
-     *
-     * @see #formatCS(Formatter, CoordinateSystem, boolean)
-     */
-    static void formatDatum(final Formatter formatter, final GeodeticDatum datum, final boolean isWKT1) {
-        formatter.newLine();
-        formatter.append(toFormattable(datum));
-        formatter.newLine();
-        formatter.indent(isWKT1 ? 0 : +1);
-        final PrimeMeridian pm = datum.getPrimeMeridian();
-        if (formatter.getConvention() != Convention.WKT2_SIMPLIFIED ||
-                ReferencingUtilities.getGreenwichLongitude(pm, NonSI.DEGREE_ANGLE) != 0)
-        {
-            formatter.append(toFormattable(pm));
+        if (isWKT1) {
+            return (cs instanceof EllipsoidalCS) ? "GeogCS" : "GeocCS";
+        } else {
+            return isBaseCRS ? "BaseGeodCRS" : "GeodeticCRS";
         }
-        formatter.indent(isWKT1 ? 0 : -1);
-        formatter.newLine();
     }
 }

Modified: sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/crs/DefaultGeographicCRS.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/crs/DefaultGeographicCRS.java?rev=1677692&r1=1677691&r2=1677692&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/crs/DefaultGeographicCRS.java [UTF-8] (original)
+++ sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/crs/DefaultGeographicCRS.java [UTF-8] Mon May  4 21:30:41 2015
@@ -282,18 +282,18 @@ public class DefaultGeographicCRS extend
      *        AngleUnit["degree", 0.017453292519943295],
      *      Area["World"],
      *      BBox[-90.00, -180.00, 90.00, 180.00],
-     *      Scope["Used by GPS satellite navigation system."]
+     *      Scope["Used by GPS satellite navigation system."],
      *      Id["EPSG", 4326, Citation["IOGP"], URI["urn:ogc:def:crs:EPSG::4326"]]]
      * }
      *
      * <p>Same coordinate reference system using WKT 1.</p>
      *
      * {@preformat wkt
-     *   GEOGCS["WGS 84"
-     *      DATUM["World Geodetic System 1984"
-     *        SPHEROID["WGS84", 6378137.0, 298.257223563]]
-     *      PRIMEM["Greenwich", 0.0]
-     *      UNIT["degree", 0.017453292519943295]
+     *   GEOGCS["WGS 84",
+     *      DATUM["World Geodetic System 1984",
+     *        SPHEROID["WGS84", 6378137.0, 298.257223563]],
+     *        PRIMEM["Greenwich", 0.0],
+     *      UNIT["degree", 0.017453292519943295],
      *      AXIS["Latitude", NORTH],
      *      AXIS["Longitude", EAST],
      *      AUTHORITY["EPSG", "4326"]]

Modified: sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/crs/DefaultImageCRS.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/crs/DefaultImageCRS.java?rev=1677692&r1=1677691&r2=1677692&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/crs/DefaultImageCRS.java [UTF-8] (original)
+++ sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/crs/DefaultImageCRS.java [UTF-8] Mon May  4 21:30:41 2015
@@ -264,12 +264,10 @@ public class DefaultImageCRS extends Abs
      */
     @Override
     protected String formatTo(final Formatter formatter) {
-        /*
-         * Note: super.formatTo(formatter) will usually format a DefaultImageDatum instance,
-         * which will declare this WKT has invalid if the formatter convention is a WKT 1 one.
-         * So we do not redo this check here.
-         */
         super.formatTo(formatter);
+        if (formatter.getConvention().majorVersion() == 1) {
+            formatter.setInvalidWKT(this, null);
+        }
         return "ImageCRS";
     }
 }

Modified: sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/crs/DefaultProjectedCRS.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/crs/DefaultProjectedCRS.java?rev=1677692&r1=1677691&r2=1677692&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/crs/DefaultProjectedCRS.java [UTF-8] (original)
+++ sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/crs/DefaultProjectedCRS.java [UTF-8] Mon May  4 21:30:41 2015
@@ -201,22 +201,34 @@ public class DefaultProjectedCRS extends
      */
     @Override
     public GeodeticDatum getDatum() {
-        return (GeodeticDatum) super.getDatum();
+        return getBaseCRS().getDatum();
     }
 
     /**
-     * Returns the base coordinate reference system, which must be geographic.
+     * Returns the {@linkplain org.apache.sis.referencing.operation.DefaultConversion#getSourceCRS() source}
+     * of the {@linkplain #getConversionFromBase() conversion from base}.
      *
-     * @return The base CRS.
+     * @return The base coordinate reference system, which must be geographic.
      */
     @Override
     @XmlElement(name = "baseGeodeticCRS", required = true)  // Note: older GML version used "baseGeographicCRS".
     public GeographicCRS getBaseCRS() {
-        return (GeographicCRS) super.getBaseCRS();
+        return (GeographicCRS) getConversionFromBase().getSourceCRS();
     }
 
     /**
      * Returns the map projection from the {@linkplain #getBaseCRS() base CRS} to this CRS.
+     * In Apache SIS, the conversion source and target CRS are set to the following values:
+     *
+     * <ul>
+     *   <li>The conversion {@linkplain org.apache.sis.referencing.operation.DefaultConversion#getSourceCRS()
+     *       source CRS} defines the {@linkplain #getBaseCRS() base CRS} of {@code this} CRS.</li>
+     *   <li>The conversion {@linkplain org.apache.sis.referencing.operation.DefaultConversion#getTargetCRS()
+     *       target CRS} is {@code this} CRS.
+     * </ul>
+     *
+     * <div class="note"><b>Note:</b>
+     * This is different than ISO 19111, which allows source and target CRS to be {@code null}.</div>
      *
      * @return The map projection from base CRS to this CRS.
      */
@@ -244,6 +256,53 @@ public class DefaultProjectedCRS extends
     /**
      * Formats the inner part of the <cite>Well Known Text</cite> (WKT) representation of this CRS.
      *
+     * <div class="note"><b>Example:</b> Well-Known Text (version 2)
+     * of a projected coordinate reference system using the Lambert Conformal method.
+     *
+     * {@preformat wkt
+     *   ProjectedCRS[“NTF (Paris) / Lambert zone II”,
+     *     BaseGeodCRS[“NTF (Paris)”,
+     *       Datum[“Nouvelle Triangulation Francaise”,
+     *         Ellipsoid[“NTF”, 6378249.2, 293.4660212936269, LengthUnit[“metre”, 1]]],
+     *         PrimeMeridian[“Paris”, 2.5969213, AngleUnit[“grade”, 0.015707963267948967]]],
+     *     Conversion[“Lambert zone II”,
+     *       Method[“Lambert Conic Conformal (1SP)”, Id[“EPSG”, 9801, Citation[“IOGP”]]],
+     *       Parameter[“Latitude of natural origin”, 52.0, AngleUnit[“grade”, 0.015707963267948967], Id[“EPSG”, 8801]],
+     *       Parameter[“Longitude of natural origin”, 0.0, AngleUnit[“degree”, 0.017453292519943295], Id[“EPSG”, 8802]],
+     *       Parameter[“Scale factor at natural origin”, 0.99987742, ScaleUnit[“unity”, 1], Id[“EPSG”, 8805]],
+     *       Parameter[“False easting”, 600000.0, LengthUnit[“metre”, 1], Id[“EPSG”, 8806]],
+     *       Parameter[“False northing”, 2200000.0, LengthUnit[“metre”, 1], Id[“EPSG”, 8807]]],
+     *     CS[“Cartesian”, 2],
+     *       Axis[“Easting (E)”, east, Order[1]],
+     *       Axis[“Northing (N)”, north, Order[2]],
+     *       LengthUnit[“metre”, 1],
+     *     Id[“EPSG”, 27572, Citation[“IOGP”], URI[“urn:ogc:def:crs:EPSG::27572”]]]
+     * }
+     *
+     * <p>Same coordinate reference system using WKT 1.</p>
+     *
+     * {@preformat wkt
+     *   PROJCS[“NTF (Paris) / Lambert zone II”,
+     *     GEOGCS[“NTF (Paris)”,
+     *       DATUM[“Nouvelle Triangulation Francaise”,
+     *         SPHEROID[“NTF”, 6378249.2, 293.4660212936269]],
+     *         PRIMEM[“Paris”, 2.33722917],
+     *       UNIT[“degree”, 0.017453292519943295],
+     *       AXIS[“Longitude”, EAST],
+     *       AXIS[“Latitude”, NORTH]],
+     *     PROJECTION[“Lambert_Conformal_Conic_1SP”, AUTHORITY[“EPSG”, “9801”]],
+     *     PARAMETER[“latitude_of_origin”, 46.8],
+     *     PARAMETER[“central_meridian”, 0.0],
+     *     PARAMETER[“scale_factor”, 0.99987742],
+     *     PARAMETER[“false_easting”, 600000.0],
+     *     PARAMETER[“false_northing”, 2200000.0],
+     *     UNIT[“metre”, 1],
+     *     AXIS[“Easting”, EAST],
+     *     AXIS[“Northing”, NORTH],
+     *     AUTHORITY[“EPSG”, “27572”]]
+     * }
+     * </div>
+     *
      * @return {@code "ProjectedCRS"} (WKT 2) or {@code "ProjCS"} (WKT 1).
      */
     @Override
@@ -254,62 +313,34 @@ public class DefaultProjectedCRS extends
         final GeographicCRS baseCRS    = getBaseCRS();
         final Unit<Angle>   unit       = ReferencingUtilities.getAngularUnit(baseCRS.getCoordinateSystem());
         final Unit<Angle>   oldUnit    = formatter.addContextualUnit(unit);
+        /*
+         * Format the enclosing base CRS. Note that WKT 1 formats a full GeographicCRS while WKT 2 formats only
+         * the datum with the prime meridian (no coordinate system) and uses a different keyword ("BaseGeodCRS"
+         * instead of "GeodeticCRS"). The DefaultGeodeticCRS.formatTo(Formatter) method detects when the CRS to
+         * format is part of an enclosing ProjectedCRS and will adapt accordingly.
+         */
         formatter.newLine();
-        if (isWKT1) {
-            formatter.append(toFormattable(baseCRS));
-        } else {
-            /*
-             * WKT 1 (above case) formatted a full GeographicCRS while WKT 2 (this case) formats
-             * only the datum and the prime meridian.  It does not format the coordinate system,
-             * and uses a different keyword ("BaseGeodCRS" instead of "GeogCS").
-             *
-             * Note that we format the unit in "simplified" mode, not in verbose mode. This looks
-             * like the opposite of what we would expect, but this is because formatting the unit
-             * here allow us to avoid repeating the unit in many projection parameters.
-             */
-            formatter.append(new BaseCRS(baseCRS, isWKT1, convention.isSimplified() ? unit : null));
-        }
+        formatter.append(toFormattable(baseCRS));
         formatter.newLine();
         final Parameters p = new Parameters(this);
+        final boolean isBaseCRS;
         if (isWKT1) {
             p.append(formatter);    // Format outside of any "Conversion" element.
+            isBaseCRS = false;
         } else {
             formatter.append(p);    // Format inside a "Conversion" element.
+            isBaseCRS = isBaseCRS(formatter);
+        }
+        /*
+         * In WKT 2 format, the coordinate system axes are written only if this projected CRS is not the base CRS
+         * of another derived CRS.
+         */
+        if (!isBaseCRS) {
+            formatCS(formatter, getCoordinateSystem(), isWKT1);
         }
-        formatCS(formatter, getCoordinateSystem(), isWKT1);
         formatter.removeContextualUnit(unit);
         formatter.addContextualUnit(oldUnit);
-        return isWKT1 ? "ProjCS" : "ProjectedCRS";
-    }
-
-    /**
-     * Temporary object for formatting the {@code BaseGeodCRS} element inside a {@code ProjectedCRS} element.
-     */
-    private static final class BaseCRS extends FormattableObject {
-        /** The base CRS. */
-        private final GeographicCRS baseCRS;
-
-        /** {@code true} for WKT 1 formatting, or {@code false} for WKT 2. */
-        private final boolean isWKT1;
-
-        /** Coordinate axis units. */
-        private final Unit<Angle> angularUnit;
-
-        /** Creates a new temporary {@code BaseGeodCRS} element. */
-        BaseCRS(final GeographicCRS baseCRS, final boolean isWKT1, final Unit<Angle> angularUnit) {
-            this.baseCRS     = baseCRS;
-            this.isWKT1      = isWKT1;
-            this.angularUnit = angularUnit;
-        }
-
-        /** Formats this {@code BaseGeodCRS} element. */
-        @Override protected String formatTo(final Formatter formatter) {
-            WKTUtilities.appendName(baseCRS, formatter, null);
-            DefaultGeodeticCRS.formatDatum(formatter, baseCRS.getDatum(), isWKT1);
-            formatter.append(angularUnit);  // May be null.
-            formatter.newLine();
-            return "BaseGeodCRS";
-        }
+        return isWKT1 ? "ProjCS" : isBaseCRS ? "BaseProjCRS" : "ProjectedCRS";
     }
 
     /**

Modified: sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/crs/DefaultTemporalCRS.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/crs/DefaultTemporalCRS.java?rev=1677692&r1=1677691&r2=1677692&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/crs/DefaultTemporalCRS.java [UTF-8] (original)
+++ sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/crs/DefaultTemporalCRS.java [UTF-8] Mon May  4 21:30:41 2015
@@ -55,7 +55,7 @@ import static org.apache.sis.util.Argume
  *
  * @author  Martin Desruisseaux (IRD, Geomatys)
  * @since   0.4
- * @version 0.4
+ * @version 0.6
  * @module
  *
  * @see org.apache.sis.referencing.datum.DefaultTemporalDatum
@@ -307,12 +307,10 @@ public class DefaultTemporalCRS extends
      */
     @Override
     protected String formatTo(final Formatter formatter) {
-        /*
-         * Note: super.formatTo(formatter) will usually format a DefaultTemporalDatum instance,
-         * which will declare this WKT has invalid if the formatter convention is a WKT 1 one.
-         * So we do not redo this check here.
-         */
         super.formatTo(formatter);
-        return "TimeCRS";
+        if (formatter.getConvention().majorVersion() == 1) {
+            formatter.setInvalidWKT(this, null);
+        }
+        return isBaseCRS(formatter) ? "BaseTimeCRS" : "TimeCRS";
     }
 }

Modified: sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/crs/DefaultVerticalCRS.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/crs/DefaultVerticalCRS.java?rev=1677692&r1=1677691&r2=1677692&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/crs/DefaultVerticalCRS.java [UTF-8] (original)
+++ sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/crs/DefaultVerticalCRS.java [UTF-8] Mon May  4 21:30:41 2015
@@ -47,7 +47,7 @@ import static org.apache.sis.util.Argume
  *
  * @author  Martin Desruisseaux (IRD, Geomatys)
  * @since   0.4
- * @version 0.4
+ * @version 0.6
  * @module
  *
  * @see org.apache.sis.referencing.datum.DefaultVerticalDatum
@@ -238,6 +238,7 @@ public class DefaultVerticalCRS extends
     @Override
     protected String formatTo(final Formatter formatter) {
         super.formatTo(formatter);
-        return (formatter.getConvention().majorVersion() == 1) ? "Vert_CS" : "VerticalCRS";
+        return (formatter.getConvention().majorVersion() == 1) ? "Vert_CS"
+               : isBaseCRS(formatter) ? "BaseVertCRS" : "VerticalCRS";
     }
 }

Modified: sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/DefaultConicProjection.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/DefaultConicProjection.java?rev=1677692&r1=1677691&r2=1677692&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/DefaultConicProjection.java [UTF-8] (original)
+++ sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/DefaultConicProjection.java [UTF-8] Mon May  4 21:30:41 2015
@@ -49,9 +49,9 @@ final class DefaultConicProjection exten
      * @param sourceCRS  The source CRS.
      * @param targetCRS  The target CRS.
      */
-    public DefaultConicProjection(final Conversion                definition,
-                                  final CoordinateReferenceSystem sourceCRS,
-                                  final CoordinateReferenceSystem targetCRS)
+    DefaultConicProjection(final Conversion                definition,
+                           final CoordinateReferenceSystem sourceCRS,
+                           final CoordinateReferenceSystem targetCRS)
     {
         super(definition, sourceCRS, targetCRS);
     }

Modified: sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/DefaultCylindricalProjection.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/DefaultCylindricalProjection.java?rev=1677692&r1=1677691&r2=1677692&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/DefaultCylindricalProjection.java [UTF-8] (original)
+++ sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/DefaultCylindricalProjection.java [UTF-8] Mon May  4 21:30:41 2015
@@ -49,9 +49,9 @@ final class DefaultCylindricalProjection
      * @param sourceCRS  The source CRS.
      * @param targetCRS  The target CRS.
      */
-    public DefaultCylindricalProjection(final Conversion                definition,
-                                        final CoordinateReferenceSystem sourceCRS,
-                                        final CoordinateReferenceSystem targetCRS)
+    DefaultCylindricalProjection(final Conversion                definition,
+                                 final CoordinateReferenceSystem sourceCRS,
+                                 final CoordinateReferenceSystem targetCRS)
     {
         super(definition, sourceCRS, targetCRS);
     }

Modified: sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/DefaultPlanarProjection.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/DefaultPlanarProjection.java?rev=1677692&r1=1677691&r2=1677692&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/DefaultPlanarProjection.java [UTF-8] (original)
+++ sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/DefaultPlanarProjection.java [UTF-8] Mon May  4 21:30:41 2015
@@ -49,9 +49,9 @@ final class DefaultPlanarProjection exte
      * @param sourceCRS  The source CRS.
      * @param targetCRS  The target CRS.
      */
-    public DefaultPlanarProjection(final Conversion                definition,
-                                   final CoordinateReferenceSystem sourceCRS,
-                                   final CoordinateReferenceSystem targetCRS)
+    DefaultPlanarProjection(final Conversion                definition,
+                            final CoordinateReferenceSystem sourceCRS,
+                            final CoordinateReferenceSystem targetCRS)
     {
         super(definition, sourceCRS, targetCRS);
     }

Modified: sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/DefaultProjection.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/DefaultProjection.java?rev=1677692&r1=1677691&r2=1677692&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/DefaultProjection.java [UTF-8] (original)
+++ sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/DefaultProjection.java [UTF-8] Mon May  4 21:30:41 2015
@@ -19,7 +19,10 @@ package org.apache.sis.referencing.opera
 import javax.xml.bind.annotation.XmlTransient;
 import org.opengis.referencing.operation.Conversion;
 import org.opengis.referencing.operation.Projection;
+import org.opengis.referencing.crs.ProjectedCRS;
+import org.opengis.referencing.crs.GeographicCRS;
 import org.opengis.referencing.crs.CoordinateReferenceSystem;
+import org.apache.sis.util.ArgumentChecks;
 
 
 /**
@@ -61,11 +64,13 @@ class DefaultProjection extends DefaultC
      * @param sourceCRS  The source CRS.
      * @param targetCRS  The target CRS.
      */
-    public DefaultProjection(final Conversion                definition,
-                             final CoordinateReferenceSystem sourceCRS,
-                             final CoordinateReferenceSystem targetCRS)
+    DefaultProjection(final Conversion                definition,
+                      final CoordinateReferenceSystem sourceCRS,
+                      final CoordinateReferenceSystem targetCRS)
     {
         super(definition, sourceCRS, targetCRS);
+        ArgumentChecks.ensureCanCast("sourceCRS", GeographicCRS.class, sourceCRS);
+        ArgumentChecks.ensureCanCast("targetCRS", ProjectedCRS .class, targetCRS);
     }
 
     /**
@@ -92,4 +97,20 @@ class DefaultProjection extends DefaultC
     public Class<? extends Projection> getInterface() {
         return Projection.class;
     }
+
+    /**
+     * Returns the source CRS, which must be geographic or {@code null}.
+     */
+    @Override
+    public final GeographicCRS getSourceCRS() {
+        return (GeographicCRS) super.getSourceCRS();
+    }
+
+    /**
+     * Returns the target CRS, which must be projected or {@code null}.
+     */
+    @Override
+    public final ProjectedCRS getTargetCRS() {
+        return (ProjectedCRS) super.getTargetCRS();
+    }
 }

Modified: sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/referencing/crs/DefaultCompoundCRSTest.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/referencing/crs/DefaultCompoundCRSTest.java?rev=1677692&r1=1677691&r2=1677692&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/referencing/crs/DefaultCompoundCRSTest.java [UTF-8] (original)
+++ sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/referencing/crs/DefaultCompoundCRSTest.java [UTF-8] Mon May  4 21:30:41 2015
@@ -153,7 +153,7 @@ public final strictfp class DefaultCompo
                 "  GEOGCS[“WGS 84”,\n" +
                 "    DATUM[“World Geodetic System 1984”,\n" +
                 "      SPHEROID[“WGS84”, 6378137.0, 298.257223563]],\n" +
-                "    PRIMEM[“Greenwich”, 0.0],\n" +
+                "      PRIMEM[“Greenwich”, 0.0],\n" +
                 "    UNIT[“degree”, 0.017453292519943295],\n" +
                 "    AXIS[“Longitude”, EAST],\n" +
                 "    AXIS[“Latitude”, NORTH]],\n" +

Modified: sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/referencing/crs/DefaultGeocentricCRSTest.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/referencing/crs/DefaultGeocentricCRSTest.java?rev=1677692&r1=1677691&r2=1677692&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/referencing/crs/DefaultGeocentricCRSTest.java [UTF-8] (original)
+++ sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/referencing/crs/DefaultGeocentricCRSTest.java [UTF-8] Mon May  4 21:30:41 2015
@@ -46,7 +46,7 @@ public final strictfp class DefaultGeoce
                 "GEOCCS[“Geocentric”,\n" +
                 "  DATUM[“World Geodetic System 1984”,\n" +
                 "    SPHEROID[“WGS84”, 6378137.0, 298.257223563]],\n" +
-                "  PRIMEM[“Greenwich”, 0.0],\n" +
+                "    PRIMEM[“Greenwich”, 0.0],\n" +
                 "  UNIT[“metre”, 1],\n" +
                 "  AXIS[“X”, OTHER],\n" +
                 "  AXIS[“Y”, EAST],\n" +

Modified: sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/referencing/crs/DefaultGeographicCRSTest.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/referencing/crs/DefaultGeographicCRSTest.java?rev=1677692&r1=1677691&r2=1677692&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/referencing/crs/DefaultGeographicCRSTest.java [UTF-8] (original)
+++ sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/referencing/crs/DefaultGeographicCRSTest.java [UTF-8] Mon May  4 21:30:41 2015
@@ -143,7 +143,7 @@ public final strictfp class DefaultGeogr
                 "GEOGCS[“WGS 84”,\n" +
                 "  DATUM[“World Geodetic System 1984”,\n" +
                 "    SPHEROID[“WGS84”, 6378137.0, 298.257223563]],\n" +
-                "  PRIMEM[“Greenwich”, 0.0],\n" +
+                "    PRIMEM[“Greenwich”, 0.0],\n" +
                 "  UNIT[“degree”, 0.017453292519943295],\n" +
                 "  AXIS[“Longitude”, EAST],\n" +
                 "  AXIS[“Latitude”, NORTH]]",

Modified: sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/referencing/crs/DefaultProjectedCRSTest.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/referencing/crs/DefaultProjectedCRSTest.java?rev=1677692&r1=1677691&r2=1677692&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/referencing/crs/DefaultProjectedCRSTest.java [UTF-8] (original)
+++ sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/referencing/crs/DefaultProjectedCRSTest.java [UTF-8] Mon May  4 21:30:41 2015
@@ -86,7 +86,7 @@ public final strictfp class DefaultProje
                 "  GEOGCS[“NTF (Paris)”,\n" +
                 "    DATUM[“Nouvelle Triangulation Francaise”,\n" +
                 "      SPHEROID[“NTF”, 6378249.2, 293.4660212936269]],\n" +
-                "    PRIMEM[“Paris”, 2.33722917],\n" +                      // Note the conversion from 2.5969213 grades.
+                "      PRIMEM[“Paris”, 2.33722917],\n" +                    // Note the conversion from 2.5969213 grades.
                 "    UNIT[“degree”, 0.017453292519943295],\n" +
                 "    AXIS[“Longitude”, EAST],\n" +
                 "    AXIS[“Latitude”, NORTH]],\n" +



Mime
View raw message