sis-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From desruisse...@apache.org
Subject svn commit: r1567671 - in /sis/branches/JDK7/core: sis-metadata/src/main/java/org/apache/sis/io/wkt/ sis-metadata/src/main/java/org/apache/sis/metadata/iso/ sis-referencing/src/test/java/org/apache/sis/referencing/crs/ sis-referencing/src/test/java/org...
Date Wed, 12 Feb 2014 16:15:52 GMT
Author: desruisseaux
Date: Wed Feb 12 16:15:52 2014
New Revision: 1567671

URL: http://svn.apache.org/r1567671
Log:
ISO 19162 compliance: there is restrictions on the places where SCOPE, AREA, REMARKS, etc.
can appear.

Modified:
    sis/branches/JDK7/core/sis-metadata/src/main/java/org/apache/sis/io/wkt/Convention.java
    sis/branches/JDK7/core/sis-metadata/src/main/java/org/apache/sis/io/wkt/Formatter.java
    sis/branches/JDK7/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/ImmutableIdentifier.java
    sis/branches/JDK7/core/sis-referencing/src/test/java/org/apache/sis/referencing/crs/HardCodedCRSTest.java
    sis/branches/JDK7/core/sis-referencing/src/test/java/org/apache/sis/referencing/datum/DefaultGeodeticDatumTest.java
    sis/branches/JDK7/core/sis-referencing/src/test/java/org/apache/sis/referencing/datum/DefaultPrimeMeridianTest.java

Modified: sis/branches/JDK7/core/sis-metadata/src/main/java/org/apache/sis/io/wkt/Convention.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-metadata/src/main/java/org/apache/sis/io/wkt/Convention.java?rev=1567671&r1=1567670&r2=1567671&view=diff
==============================================================================
--- sis/branches/JDK7/core/sis-metadata/src/main/java/org/apache/sis/io/wkt/Convention.java
[UTF-8] (original)
+++ sis/branches/JDK7/core/sis-metadata/src/main/java/org/apache/sis/io/wkt/Convention.java
[UTF-8] Wed Feb 12 16:15:52 2014
@@ -70,17 +70,15 @@ public enum Convention {
      * to the {@link #WKT2} convention except for the following aspects:
      *
      * <ul>
-     *   <li>{@code ANGLEUNIT}, {@code LENGTHUNIT}, {@code SCALEUNIT}, {@code PARAMETRICUNIT}
and
-     *       {@code TIMEUNIT} are formatted as plain {@code UNIT} elements.</li>
-     *   <li>In {@code AXIS} elements, the {@code ORDER} sub-element is omitted.</li>
-     *   <li>In {@code VERTICALEXTENT} elements, the {@code UNIT} sub-element is omitted
+     *   <li>{@code AXIS} element omits the {@code ORDER} sub-element.</li>
+     *   <li>{@code VERTICALEXTENT} element omits the {@code UNIT} sub-element
      *       if the unit is {@link javax.measure.unit.SI#METRE}.</li>
-     *   <li>{@code ID} elements are formatted for child elements in addition to the
root one.</li>
+     *   <li>{@code ANGLEUNIT}, {@code LENGTHUNIT}, {@code SCALEUNIT}, {@code PARAMETRICUNIT}
+     *       and {@code TIMEUNIT} are formatted as plain {@code UNIT} elements.</li>
+     *   <li>{@code ID} is formatted only for the root element
+     *       (omit parameters and operation methods {@code ID}).</li>
      * </ul>
      *
-     * {@note The additional <code>ID[…]</code> elements apparently go against
the simplification goal,
-     *        but are often helpful information when using Apache SIS.}
-     *
      * Those modifications are allowed by the ISO 19162 standard and do not cause any information
lost.
      * The omitted elements are not needed by Apache SIS WKT parser and often distractive
for the human reader.
      *
@@ -136,10 +134,14 @@ public enum Convention {
      * with the following differences:
      *
      * <ul>
-     *   <li>In {@code ID[…]} elements, the {@code URI[…]} sub-element is omitted
if the sub-element
-     *       was derived by Apache SIS from the other {@code ID[…]} properties.</li>
      *   <li>Map projections are shown as SIS stores them internally, i.e. with the
separation between
      *       linear and non-linear steps, rather than as a single operation.</li>
+     *   <li>{@code ID} elements are formatted for child elements in addition to the
root one.</li>
+     *   <li>{@code ID} element omits the {@code URI} sub-element if the later is derived
by Apache SIS
+     *       from the {@code ID} properties.</li>
+     *   <li>{@code REMARKS} element is formatted for all
+     *       {@linkplain org.apache.sis.referencing.AbstractIdentifiedObject identified objects},
+     *       not only CRS or coordinate operations.</li>
      * </ul>
      *
      * This convention is used only for debugging purpose.

Modified: sis/branches/JDK7/core/sis-metadata/src/main/java/org/apache/sis/io/wkt/Formatter.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-metadata/src/main/java/org/apache/sis/io/wkt/Formatter.java?rev=1567671&r1=1567670&r2=1567671&view=diff
==============================================================================
--- sis/branches/JDK7/core/sis-metadata/src/main/java/org/apache/sis/io/wkt/Formatter.java
[UTF-8] (original)
+++ sis/branches/JDK7/core/sis-metadata/src/main/java/org/apache/sis/io/wkt/Formatter.java
[UTF-8] Wed Feb 12 16:15:52 2014
@@ -21,6 +21,7 @@ import java.util.IdentityHashMap;
 import java.util.List;
 import java.util.ArrayList;
 import java.util.Collection;
+import java.util.Collections;
 import java.util.Locale;
 import java.util.Date;
 import java.text.DateFormat;
@@ -41,10 +42,12 @@ import org.opengis.util.InternationalStr
 import org.opengis.metadata.citation.Citation;
 import org.opengis.metadata.extent.Extent;
 import org.opengis.metadata.extent.GeographicBoundingBox;
+import org.opengis.parameter.GeneralParameterDescriptor;
 import org.opengis.referencing.IdentifiedObject;
 import org.opengis.referencing.ReferenceIdentifier;
 import org.opengis.referencing.ReferenceSystem;
 import org.opengis.referencing.datum.Datum;
+import org.opengis.referencing.operation.OperationMethod;
 import org.opengis.referencing.operation.CoordinateOperation;
 import org.opengis.referencing.operation.MathTransform;
 import org.opengis.referencing.operation.Matrix;
@@ -389,33 +392,6 @@ public class Formatter implements Locali
     }
 
     /**
-     * Returns the preferred identifier for the specified object.
-     * If the specified object contains an identifier from the preferred authority, then
this identifier is returned.
-     * Otherwise, the first identifier is returned.
-     * If the specified object contains no identifier, then this method returns {@code null}.
-     *
-     * @param  info The object to look for a preferred identifier, or {@code null} if none.
-     * @return The preferred identifier, or {@code null} if none.
-     */
-    private ReferenceIdentifier getIdentifier(final IdentifiedObject info) {
-        ReferenceIdentifier first = null;
-        if (info != null) {
-            final Collection<ReferenceIdentifier> identifiers = info.getIdentifiers();
-            if (identifiers != null) {
-                for (final ReferenceIdentifier id : identifiers) {
-                    if (Citations.identifierMatches(authority, id.getAuthority())) {
-                        return id;
-                    }
-                    if (first == null) {
-                        first = id;
-                    }
-                }
-            }
-        }
-        return first;
-    }
-
-    /**
      * Appends in the {@linkplain #buffer} the ANSI escape sequence for the given kind of
element.
      * This method does nothing unless syntax coloring has been explicitly enabled.
      */
@@ -517,13 +493,17 @@ public class Formatter implements Locali
      * <ul>
      *   <li>Invoke <code>formattable.{@linkplain FormattableObject#formatTo(Formatter)
formatTo}(this)</code>.</li>
      *   <li>Prepend the keyword returned by the above method call (e.g. {@code "GEOCS"}).</li>
-     *   <li>Append the {@code SCOPE[…]} element, if any (WKT 2 only).</li>
-     *   <li>Append the {@code AREA[…]} element, if any (WKT 2 only).</li>
-     *   <li>Append the {@code BBOX[…]} element, if any (WKT 2 only).</li>
-     *   <li>Append the {@code VERTICALEXTENT[…]} element, if any (WKT 2 only).</li>
-     *   <li>Append the {@code TIMEEXTENT[…]} element, if any (WKT 2 only).</li>
-     *   <li>Append the {@code ID[…]} (WKT 2) or {@code AUTHORITY[…]}} (WKT 1)
element, if any.</li>
-     *   <li>Append the {@code REMARKS[…]} element, if any (WKT 2 only).</li>
+     *   <li>If the given object is an instance of {@link IdentifiedObject}, then append
complementary information:
+     *     <ul>
+     *       <li>{@code SCOPE[…]} (WKT 2 only)</li>
+     *       <li>{@code AREA[…]}  (WKT 2 only)</li>
+     *       <li>{@code BBOX[…]}  (WKT 2 only)</li>
+     *       <li>{@code VERTICALEXTENT[…]} (WKT 2 only)</li>
+     *       <li>{@code TIMEEXTENT[…]} (WKT 2 only)</li>
+     *       <li>{@code ID[…]} (WKT 2) or {@code AUTHORITY[…]}} (WKT 1)</li>
+     *       <li>{@code REMARKS[…]} ({@link ReferenceSystem} and {@link CoordinateOperation}
in WKT 2 only)</li>
+     *     </ul>
+     *   </li>
      * </ul>
      *
      * @param object The formattable object to append to the WKT, or {@code null} if none.
@@ -601,7 +581,7 @@ public class Formatter implements Locali
      *
      * <p>The {@code ID[<name>,<code>,…]} element is written only for
the root element, unless the convention are
      * INTERNAL. If formatted, the ID element will be on the same line than the enclosing
one if no line separator
-     * were requested (e.g. SPHEROID["Clarke 1866", …, ID["EPSG", 7008]]), or on a new
line otherwise. Example:
+     * were requested (e.g. SPHEROID["Clarke 1866", …, ID["EPSG", 7008]]), or on a new
line otherwise. Example:</p>
      *
      * {@preformat text
      *   PROJCS["NAD27 / Idaho Central",
@@ -609,21 +589,72 @@ public class Formatter implements Locali
      *     ...etc...
      *     ID["EPSG", 26769]]
      * }
+     *
+     * For non-internal conventions, all elements other than {@code ID[…]} are formatted
+     * only for {@link CoordinateOperation} and {@link ReferenceSystem} types.
+     * In the later case, we also require that the CRS is not the base of a derived CRS.
+     * Those restrictions are our interpretation of the following ISO 19162 requirement:
+     *
+     * <blockquote>(…snip…) {@code <scope extent identifier remark>} is a
collection of four optional attributes
+     * which may be applied to a coordinate reference system, a coordinate operation or a
boundCRS. (…snip…)
+     * Identifier (…snip…) may also be utilised for components of these objects although
this is not recommended
+     * except for coordinate operation methods (including map projections) and parameters.
(…snip…)
+     * A {@code <remark>} can be included within the descriptions of source and target
CRS embedded within
+     * a coordinate transformation as well as within the coordinate transformation itself.</blockquote>
      */
     private void appendComplement(final IdentifiedObject object, final boolean isRoot) {
         isComplement = true;
-        final boolean isWKT1 = convention.isWKT1();
-        if (!isWKT1) {
+        final boolean showIDs;      // Whether to format ID[…] elements.
+        final boolean filterID;     // Whether we shall limit to a single ID[…] element.
+        final boolean showOthers;   // Whether to format any element other than ID[…].
+        if (convention == Convention.INTERNAL) {
+            showIDs    = true;
+            filterID   = false;
+            showOthers = true;
+        } else {
+            if (convention == Convention.WKT2_SIMPLIFIED) {
+                showIDs = isRoot;
+            } else {
+                showIDs = isRoot || (object instanceof OperationMethod) || (object instanceof
GeneralParameterDescriptor);
+            }
+            if (convention.isWKT1()) {
+                filterID   = true;
+                showOthers = false;
+            } else {
+                filterID = !isRoot;
+                if (object instanceof CoordinateOperation) {
+                    showOthers = true;
+                } else if (object instanceof ReferenceSystem) {
+                    showOthers = !(getEnclosingElement(1) instanceof ReferenceSystem);
+                } else {
+                    showOthers = false; // Mandated by ISO 19162.
+                }
+            }
+    }
+        if (showOthers) {
             appendScopeAndArea(object);
         }
-        if (isRoot || convention.showIdentifiers()) {
-            ReferenceIdentifier id = getIdentifier(object);
-            if (!(id instanceof FormattableObject)) {
-                id = ImmutableIdentifier.castOrCopy(id);
+        if (showIDs) {
+            Collection<ReferenceIdentifier> identifiers = object.getIdentifiers();
+            if (identifiers != null) { // Paranoiac check
+                if (filterID) {
+                    for (ReferenceIdentifier id : identifiers) {
+                        if (Citations.identifierMatches(authority, id.getAuthority())) {
+                            identifiers = Collections.singleton(id);
+                            break;
+                        }
+                    }
+                }
+                for (ReferenceIdentifier id : identifiers) {
+                    if (!(id instanceof FormattableObject)) {
+                        id = ImmutableIdentifier.castOrCopy(id);
+                    }
+                    append((FormattableObject) id);
+                    if (filterID) break;
+                }
             }
-            append((FormattableObject) id);
         }
-        if (!isWKT1) {
+        if (showOthers) {
             appendOnNewLine("REMARKS", object.getRemarks(), ElementKind.REMARKS);
         }
         isComplement = false;
@@ -1298,6 +1329,7 @@ public class Formatter implements Locali
         }
         enclosingElements.clear();
         units.clear();
+        elementStart   = 0;
         colorApplied   = 0;
         margin         = 0;
         requestNewLine = false;

Modified: sis/branches/JDK7/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/ImmutableIdentifier.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/ImmutableIdentifier.java?rev=1567671&r1=1567670&r2=1567671&view=diff
==============================================================================
--- sis/branches/JDK7/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/ImmutableIdentifier.java
[UTF-8] (original)
+++ sis/branches/JDK7/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/ImmutableIdentifier.java
[UTF-8] Wed Feb 12 16:15:52 2014
@@ -575,15 +575,9 @@ public class ImmutableIdentifier extends
                     /*
                      * Do not format the optional URI element for internal convention,
                      * because this property is currently computed rather than stored.
-                     * Simplified convention formats only for the ID of root element.
+                     * Other conventions format only for the ID[…] of root element.
                      */
-                    final boolean showURI;
-                    switch (convention) {
-                        default:              showURI = true;  break;
-                        case INTERNAL:        showURI = false; break;
-                        case WKT2_SIMPLIFIED: showURI = formatter.getEnclosingElement(2)
== null; break;
-                    }
-                    if (showURI) {
+                    if (convention != Convention.INTERNAL && formatter.getEnclosingElement(2)
== null) {
                         final FormattableObject parent = formatter.getEnclosingElement(1);
                         if (parent != null && ReferencingUtilities.usesURN(codeSpace))
{
                             final String type = ReferencingUtilities.toURNType(parent.getClass());

Modified: sis/branches/JDK7/core/sis-referencing/src/test/java/org/apache/sis/referencing/crs/HardCodedCRSTest.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-referencing/src/test/java/org/apache/sis/referencing/crs/HardCodedCRSTest.java?rev=1567671&r1=1567670&r2=1567671&view=diff
==============================================================================
--- sis/branches/JDK7/core/sis-referencing/src/test/java/org/apache/sis/referencing/crs/HardCodedCRSTest.java
[UTF-8] (original)
+++ sis/branches/JDK7/core/sis-referencing/src/test/java/org/apache/sis/referencing/crs/HardCodedCRSTest.java
[UTF-8] Wed Feb 12 16:15:52 2014
@@ -98,9 +98,8 @@ public final strictfp class HardCodedCRS
         assertWktEquals(Convention.WKT2_SIMPLIFIED,
                 "GEOGCS[“WGS 84”,\n" +
                 "  DATUM[“World Geodetic System 1984”,\n" +
-                "    SPHEROID[“WGS84”, 6378137.0, 298.257223563],\n" +
-                "    ID[“EPSG”, 6326]],\n" +
-                "  PRIMEM[“Greenwich”, 0.0, ID[“EPSG”, 8901]],\n" +
+                "    SPHEROID[“WGS84”, 6378137.0, 298.257223563]],\n" +
+                "  PRIMEM[“Greenwich”, 0.0],\n" +
                 "  UNIT[“degree”, 0.017453292519943295],\n" +
                 "  AXIS[“Geodetic longitude”, EAST],\n" +
                 "  AXIS[“Geodetic latitude”, NORTH],\n" +

Modified: sis/branches/JDK7/core/sis-referencing/src/test/java/org/apache/sis/referencing/datum/DefaultGeodeticDatumTest.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-referencing/src/test/java/org/apache/sis/referencing/datum/DefaultGeodeticDatumTest.java?rev=1567671&r1=1567670&r2=1567671&view=diff
==============================================================================
--- sis/branches/JDK7/core/sis-referencing/src/test/java/org/apache/sis/referencing/datum/DefaultGeodeticDatumTest.java
[UTF-8] (original)
+++ sis/branches/JDK7/core/sis-referencing/src/test/java/org/apache/sis/referencing/datum/DefaultGeodeticDatumTest.java
[UTF-8] Wed Feb 12 16:15:52 2014
@@ -266,13 +266,8 @@ public final strictfp class DefaultGeode
 
         assertWktEquals(Convention.WKT2,
                 "DATUM[“World Geodetic System 1984”,\n" +
-                "  SPHEROID[“WGS 84”, 6378137.0, 298.257223563,\n" +
-                "    REMARKS[“Defining parameters cited in EPSG database.”]],\n" +
-                "  SCOPE[“Satellite navigation.”],\n" +
-                "  AREA[“World.”],\n" +
-                "  BBOX[-90.00, -180.00, 90.00, 180.00],\n" +
-                "  ID[“EPSG”, 6326, URI[“urn:ogc:def:datum:EPSG::6326”]],\n" +
-                "  REMARKS[“No distinction between the original and subsequent WGS 84 frames.”]]",
+                "  SPHEROID[“WGS 84”, 6378137.0, 298.257223563],\n" +
+                "  ID[“EPSG”, 6326, URI[“urn:ogc:def:datum:EPSG::6326”]]]",
                 datum);
 
         assertWktEquals(Convention.INTERNAL,

Modified: sis/branches/JDK7/core/sis-referencing/src/test/java/org/apache/sis/referencing/datum/DefaultPrimeMeridianTest.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-referencing/src/test/java/org/apache/sis/referencing/datum/DefaultPrimeMeridianTest.java?rev=1567671&r1=1567670&r2=1567671&view=diff
==============================================================================
--- sis/branches/JDK7/core/sis-referencing/src/test/java/org/apache/sis/referencing/datum/DefaultPrimeMeridianTest.java
[UTF-8] (original)
+++ sis/branches/JDK7/core/sis-referencing/src/test/java/org/apache/sis/referencing/datum/DefaultPrimeMeridianTest.java
[UTF-8] Wed Feb 12 16:15:52 2014
@@ -25,6 +25,7 @@ import org.apache.sis.xml.Namespaces;
 import org.apache.sis.xml.MarshallerPool;
 import org.apache.sis.util.CharSequences;
 import org.apache.sis.internal.jaxb.LegacyNamespaces;
+import org.apache.sis.io.wkt.Convention;
 import org.apache.sis.test.XMLTestCase;
 import org.apache.sis.test.DependsOnMethod;
 import org.apache.sis.test.DependsOn;
@@ -147,7 +148,9 @@ public final strictfp class DefaultPrime
         assertEquals("Equivalent to 2°20′14.025″.", pm.getRemarks().toString());
         assertNull("name.codeSpace", pm.getName().getCodeSpace());
         assertWktEquals(
-                "PRIMEM[“Paris”, 2.33722917, ID[“EPSG”, 8903, URI[“urn:ogc:def:meridian:EPSG::8903”]],\n"
+
+                "PRIMEM[“Paris”, 2.33722917, ID[“EPSG”, 8903, URI[“urn:ogc:def:meridian:EPSG::8903”]]]",
pm);
+        assertWktEquals(Convention.INTERNAL,
+                "PRIMEM[“Paris”, 2.33722917, ID[“EPSG”, 8903],\n" +
                 "  REMARKS[“Equivalent to 2°20′14.025″.”]]", pm);
         assertXmlEquals(
                 "<gml:PrimeMeridian xmlns:gml=\"" + Namespaces.GML + "\">\n" +



Mime
View raw message