sis-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From desruisse...@apache.org
Subject svn commit: r1567790 - in /sis/branches/JDK7/core: sis-metadata/src/main/java/org/apache/sis/internal/metadata/ sis-metadata/src/test/java/org/apache/sis/internal/metadata/ sis-referencing/src/main/java/org/apache/sis/referencing/cs/
Date Wed, 12 Feb 2014 23:09:30 GMT
Author: desruisseaux
Date: Wed Feb 12 23:09:30 2014
New Revision: 1567790

URL: http://svn.apache.org/r1567790
Log:
Partial support of WKT2 CS element.

Modified:
    sis/branches/JDK7/core/sis-metadata/src/main/java/org/apache/sis/internal/metadata/ReferencingUtilities.java
    sis/branches/JDK7/core/sis-metadata/src/test/java/org/apache/sis/internal/metadata/ReferencingUtilitiesTest.java
    sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/cs/AbstractCS.java
    sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/cs/DefaultCartesianCS.java

Modified: sis/branches/JDK7/core/sis-metadata/src/main/java/org/apache/sis/internal/metadata/ReferencingUtilities.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-metadata/src/main/java/org/apache/sis/internal/metadata/ReferencingUtilities.java?rev=1567790&r1=1567789&r2=1567790&view=diff
==============================================================================
--- sis/branches/JDK7/core/sis-metadata/src/main/java/org/apache/sis/internal/metadata/ReferencingUtilities.java
[UTF-8] (original)
+++ sis/branches/JDK7/core/sis-metadata/src/main/java/org/apache/sis/internal/metadata/ReferencingUtilities.java
[UTF-8] Wed Feb 12 23:09:30 2014
@@ -18,6 +18,8 @@ package org.apache.sis.internal.metadata
 
 import java.util.Collection;
 import javax.measure.unit.Unit;
+import org.opengis.annotation.UML;
+import org.opengis.annotation.Specification;
 import org.opengis.parameter.*;
 import org.opengis.referencing.*;
 import org.opengis.referencing.cs.*;
@@ -113,6 +115,47 @@ public final class ReferencingUtilities 
     }
 
     /**
+     * Returns the WKT type of the given interface.
+     *
+     * For {@link CoordinateSystem} base type, the returned value shall be one of
+     * {@code affine}, {@code Cartesian}, {@code cylindrical}, {@code ellipsoidal}, {@code
linear},
+     * {@code parametric}, {@code polar}, {@code spherical}, {@code temporal} or {@code vertical}.
+     *
+     * @param  base The abstract base interface.
+     * @param  type The interface or classes for which to get the WKT type.
+     * @return The WKT type for the given class or interface, or {@code null} if none.
+     */
+    public static String toWKTType(final Class<?> base, final Class<?> type)
{
+        if (type != base) {
+            final UML uml = type.getAnnotation(UML.class);
+            if (uml != null && uml.specification() == Specification.ISO_19111) {
+                String name = uml.identifier();
+                final int length = name.length() - 5; // Length without "CS_" and "CS".
+                if (length >= 1 && name.startsWith("CS_") && name.endsWith("CS"))
{
+                    final StringBuilder buffer = new StringBuilder(length).append(name, 3,
3 + length);
+                    if (!name.regionMatches(3, "Cartesian", 0, 9)) {
+                        buffer.setCharAt(0, Character.toLowerCase(buffer.charAt(0)));
+                    }
+                    name = buffer.toString();
+                    if (name.equals("time")) {
+                        name = "temporal";
+                    }
+                    return name;
+                }
+            }
+            for (final Class<?> c : type.getInterfaces()) {
+                if (base.isAssignableFrom(c)) {
+                    final String name = toWKTType(base, c);
+                    if (name != null) {
+                        return name;
+                    }
+                }
+            }
+        }
+        return null;
+    }
+
+    /**
      * Returns the unit used for all axes in the given coordinate system.
      * If not all axes use the same unit, then this method returns {@code null}.
      *

Modified: sis/branches/JDK7/core/sis-metadata/src/test/java/org/apache/sis/internal/metadata/ReferencingUtilitiesTest.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-metadata/src/test/java/org/apache/sis/internal/metadata/ReferencingUtilitiesTest.java?rev=1567790&r1=1567789&r2=1567790&view=diff
==============================================================================
--- sis/branches/JDK7/core/sis-metadata/src/test/java/org/apache/sis/internal/metadata/ReferencingUtilitiesTest.java
[UTF-8] (original)
+++ sis/branches/JDK7/core/sis-metadata/src/test/java/org/apache/sis/internal/metadata/ReferencingUtilitiesTest.java
[UTF-8] Wed Feb 12 23:09:30 2014
@@ -37,7 +37,7 @@ import static org.apache.sis.internal.me
  */
 public final strictfp class ReferencingUtilitiesTest extends TestCase {
     /**
-     * Tests {@link ReferencingUtilities#toURNType()}.
+     * Tests {@link ReferencingUtilities#toURNType(Class)}.
      */
     @Test
     public void testToURNType() {
@@ -55,4 +55,22 @@ public final strictfp class ReferencingU
         assertEquals("axis",            toURNType(CoordinateSystemAxis.class));
         assertEquals("referenceSystem", toURNType(ReferenceSystem     .class));
     }
+
+    /**
+     * Tests {@link ReferencingUtilities#toWKTType(Class, Class)}.
+     */
+    @Test
+    public void testType() {
+        assertNull  (               toWKTType(CoordinateSystem.class, CoordinateSystem.class));
+        assertEquals("affine",      toWKTType(CoordinateSystem.class, AffineCS        .class));
+        assertEquals("Cartesian",   toWKTType(CoordinateSystem.class, CartesianCS     .class));
+        assertEquals("cylindrical", toWKTType(CoordinateSystem.class, CylindricalCS   .class));
+        assertEquals("ellipsoidal", toWKTType(CoordinateSystem.class, EllipsoidalCS   .class));
+        assertEquals("linear",      toWKTType(CoordinateSystem.class, LinearCS        .class));
+//      assertEquals("parametric",  toWKTType(CoordinateSystem.class, ParametricCS    .class));
+        assertEquals("polar",       toWKTType(CoordinateSystem.class, PolarCS         .class));
+        assertEquals("spherical",   toWKTType(CoordinateSystem.class, SphericalCS     .class));
+        assertEquals("temporal",    toWKTType(CoordinateSystem.class, TimeCS          .class));
+        assertEquals("vertical",    toWKTType(CoordinateSystem.class, VerticalCS      .class));
+    }
 }

Modified: sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/cs/AbstractCS.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/cs/AbstractCS.java?rev=1567790&r1=1567789&r2=1567790&view=diff
==============================================================================
--- sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/cs/AbstractCS.java
[UTF-8] (original)
+++ sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/cs/AbstractCS.java
[UTF-8] Wed Feb 12 23:09:30 2014
@@ -33,6 +33,7 @@ import org.opengis.referencing.cs.AxisDi
 import org.opengis.referencing.cs.CoordinateSystem;
 import org.opengis.referencing.cs.CoordinateSystemAxis;
 import org.apache.sis.referencing.AbstractIdentifiedObject;
+import org.apache.sis.internal.metadata.ReferencingUtilities;
 import org.apache.sis.internal.referencing.AxisDirections;
 import org.apache.sis.io.wkt.Formatter;
 import org.apache.sis.util.ComparisonMode;
@@ -414,18 +415,26 @@ public class AbstractCS extends Abstract
 
     /**
      * Formats the inner part of a <cite>Well Known Text</cite> (WKT) element.
-     * Note that WKT version 1 does not define any keyword for coordinate system.
+     *
+     * {@example <blockquote><pre>CS[ellipsoidal,3],
+     *    AXIS["latitude",north,ORDER[1],ANGLEUNIT["degree",0.0174532925199433]],
+     *    AXIS["longitude",east,ORDER[2],ANGLEUNIT["degree",0.0174532925199433]]</pre></blockquote>
+     * }
+     *
+     * This is supported only for version 2 of WKT.
      *
      * @param  formatter The formatter to use.
-     * @return The WKT element name.
+     * @return The WKT element name, which is {@code "CS"}.
      */
     @Override
     protected String formatTo(final Formatter formatter) {
-        final String keyword = super.formatTo(formatter);
+        formatter.append(ReferencingUtilities.toWKTType(CoordinateSystem.class, getInterface()),
null);
+        formatter.append(getDimension());
+        // TODO: Axes need to be formatted outside CS.
         for (final CoordinateSystemAxis axe : axes) {
             formatter.newLine();
             formatter.append(axe);
         }
-        return keyword;
+        return "CS";
     }
 }

Modified: sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/cs/DefaultCartesianCS.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/cs/DefaultCartesianCS.java?rev=1567790&r1=1567789&r2=1567790&view=diff
==============================================================================
--- sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/cs/DefaultCartesianCS.java
[UTF-8] (original)
+++ sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/cs/DefaultCartesianCS.java
[UTF-8] Wed Feb 12 23:09:30 2014
@@ -27,7 +27,7 @@ import org.apache.sis.measure.Angle;
 
 
 /**
- * A 1-, 2-, or 3-dimensional Cartesian coordinate system made of straight orthogonal axes.
+ * A 2-, or 3-dimensional Cartesian coordinate system made of straight orthogonal axes.
  * All axes shall have the same linear unit of measure.
  *
  * <table class="sis"><tr>
@@ -84,21 +84,6 @@ public class DefaultCartesianCS extends 
     }
 
     /**
-     * Constructs a one-dimensional coordinate system from a set of properties.
-     * The properties map is given unchanged to the
-     * {@linkplain AbstractCS#AbstractCS(Map,CoordinateSystemAxis[]) super-class constructor}.
-     *
-     * @param properties The properties to be given to the identified object.
-     * @param axis The axis.
-     */
-    public DefaultCartesianCS(final Map<String,?>   properties,
-                              final CoordinateSystemAxis axis)
-    {
-        super(properties, new CoordinateSystemAxis[] {axis});
-        ensurePerpendicularAxis();
-    }
-
-    /**
      * Constructs a two-dimensional coordinate system from a set of properties.
      * The properties map is given unchanged to the
      * {@linkplain AbstractCS#AbstractCS(Map,CoordinateSystemAxis[]) super-class constructor}.



Mime
View raw message