sis-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From desruisse...@apache.org
Subject svn commit: r1688792 - in /sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/io/wkt: Element.java GeodeticObjectParser.java
Date Thu, 02 Jul 2015 09:18:25 GMT
Author: desruisseaux
Date: Thu Jul  2 09:18:24 2015
New Revision: 1688792

URL: http://svn.apache.org/r1688792
Log:
WKT 2: added support for Derived Vertical CRS and Derived Temporal CRS parsing.

Modified:
    sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/io/wkt/Element.java
    sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/io/wkt/GeodeticObjectParser.java

Modified: sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/io/wkt/Element.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/io/wkt/Element.java?rev=1688792&r1=1688791&r2=1688792&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/io/wkt/Element.java [UTF-8]
(original)
+++ sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/io/wkt/Element.java [UTF-8]
Thu Jul  2 09:18:24 2015
@@ -26,6 +26,7 @@ import java.util.Locale;
 import java.io.PrintWriter;
 import java.text.ParsePosition;
 import java.text.ParseException;
+import org.opengis.referencing.cs.CoordinateSystem;
 import org.apache.sis.util.Debug;
 import org.apache.sis.util.ArraysExt;
 import org.apache.sis.util.Exceptions;
@@ -380,6 +381,30 @@ final class Element {
         return new LocalizedParseException(locale, res, args, offset);
     }
 
+    /**
+     * Returns a {@link ParseException} for an illegal coordinate system.
+     *
+     * <p>The given {@code cs} argument should never be null with Apache SIS implementation
of
+     * {@link org.opengis.referencing.cs.CSFactory}, but could be null with user-supplied
implementation.
+     * But it would be a {@code CSFactory} contract violation, so the user would get a {@link
NullPointerException}
+     * later. For making easier to trace the cause, we throw here an exception with a similar
error message.</p>
+     *
+     * @param  cs The illegal coordinate system.
+     * @return The exception to be thrown.
+     */
+    final ParseException illegalCS(final CoordinateSystem cs) {
+        final short key;
+        final String value;
+        if (cs == null) {
+            key   = Errors.Keys.NullArgument_1;   // See javadoc.
+            value = "coordinateSystem";
+        } else {
+            key   = Errors.Keys.IllegalCoordinateSystem_1;
+            value = cs.getName().getCode();
+        }
+        return new LocalizedParseException(locale, key, new String[] {value}, offset);
+    }
+
 
 
 

Modified: sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/io/wkt/GeodeticObjectParser.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/io/wkt/GeodeticObjectParser.java?rev=1688792&r1=1688791&r2=1688792&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/io/wkt/GeodeticObjectParser.java
[UTF-8] (original)
+++ sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/io/wkt/GeodeticObjectParser.java
[UTF-8] Thu Jul  2 09:18:24 2015
@@ -1447,12 +1447,17 @@ final class GeodeticObjectParser extends
         final String     name   = element.pullString("name");
         final ImageDatum datum  = parseImageDatum(MANDATORY, element);
         final Unit<?>    unit   = parseUnit(element);
+        final CoordinateSystem cs;
         try {
-            final CoordinateSystem cs = parseCoordinateSystem(element, WKTKeywords.Cartesian,
2, false, unit, datum);
-            return crsFactory.createImageCRS(parseMetadataAndClose(element, name, datum),
datum, (CartesianCS) cs);
+            cs = parseCoordinateSystem(element, WKTKeywords.Cartesian, 2, false, unit, datum);
+            final Map<String,?> properties = parseMetadataAndClose(element, name, datum);
+            if (cs instanceof CartesianCS) {
+                return crsFactory.createImageCRS(properties, datum, (CartesianCS) cs);
+            }
         } catch (FactoryException exception) {
             throw element.parseFailed(exception);
         }
+        throw element.illegalCS(cs);
     }
 
     /**
@@ -1541,7 +1546,7 @@ final class GeodeticObjectParser extends
         SingleCRS     baseCRS  = null;
         Conversion    fromBase = null;
         if (!isWKT1 && csType == null) {
-            fromBase = parseDerivingConversion(OPTIONAL, element, WKTKeywords.DerivingConversion,
SI.METRE, angularUnit);
+            fromBase = parseDerivingConversion(OPTIONAL, element, WKTKeywords.DerivingConversion,
null, angularUnit);
             if (fromBase != null) {
                 baseCRS = parseGeodeticCRS(MANDATORY, element, WKTKeywords.ellipsoidal);
             }
@@ -1575,8 +1580,7 @@ final class GeodeticObjectParser extends
         } catch (FactoryException exception) {
             throw element.parseFailed(exception);
         }
-        throw new LocalizedParseException(errorLocale, Errors.Keys.IllegalCoordinateSystem_1,
-                new Object[] {cs.getClass()}, element.offset);
+        throw element.illegalCS(cs);
     }
 
     /**
@@ -1595,7 +1599,7 @@ final class GeodeticObjectParser extends
      * @return The {@code "VerticalCRS"} element as a {@link VerticalCRS} object.
      * @throws ParseException if the {@code "VerticalCRS"} element can not be parsed.
      */
-    private VerticalCRS parseVerticalCRS(final int mode, final Element parent, final boolean
isBaseCRS)
+    private SingleCRS parseVerticalCRS(final int mode, final Element parent, final boolean
isBaseCRS)
             throws ParseException
     {
         final Element element = parent.pullElement(mode,
@@ -1608,33 +1612,58 @@ final class GeodeticObjectParser extends
         }
         final boolean isWKT1 = element.getKeywordIndex() == 2;  // Index of "Vert_CS" above.
         final String  name   = element.pullString("name");
-        VerticalDatum datum  = parseVerticalDatum(MANDATORY, element, isWKT1);
         final Unit<?> unit   = parseUnit(element);
+        /*
+         * A VerticalCRS can be either a "normal" one (with a non-null datum), or a DerivedCRS
of kind VerticalCRS.
+         * In the later case, the datum is null and we have instead DerivingConversion element
from a BaseVertCRS.
+         */
+        VerticalDatum datum    = null;
+        SingleCRS     baseCRS  = null;
+        Conversion    fromBase = null;
+        if (!isWKT1 && !isBaseCRS) {
+            @SuppressWarnings("unchecked")
+            final Unit<Length> linearUnit = Units.isLinear(unit) ? (Unit<Length>)
unit : null;
+            fromBase = parseDerivingConversion(OPTIONAL, element, WKTKeywords.DerivingConversion,
linearUnit, null);
+            if (fromBase != null) {
+                baseCRS = parseVerticalCRS(MANDATORY, element, true);
+            }
+        }
+        if (baseCRS == null) {  // The most usual case.
+            datum = parseVerticalDatum(MANDATORY, element, isWKT1);
+        }
+        final CoordinateSystem cs;
         try {
-            final CoordinateSystem cs = parseCoordinateSystem(element, WKTKeywords.vertical,
1, isWKT1, unit, datum);
-            /*
-             * The 'parseVerticalDatum(…)' method may have been unable to resolve the datum
type.
-             * But sometime the axis (which was not available when we created the datum)
provides
-             * more information. Verify if we can have a better type now, and if so rebuild
the datum.
-             */
-            if (VerticalDatumType.OTHER_SURFACE.equals(datum.getVerticalDatumType())) {
-                final VerticalDatumType type = VerticalDatumTypes.guess(datum.getName().getCode(),
datum.getAlias(), cs.getAxis(0));
-                if (!VerticalDatumType.OTHER_SURFACE.equals(type)) {
-                    datum = datumFactory.createVerticalDatum(referencing.getProperties(datum),
type);
+            cs = parseCoordinateSystem(element, WKTKeywords.vertical, 1, isWKT1, unit, datum);
+            final Map<String,?> properties = parseMetadataAndClose(element, name, datum);
+            if (cs instanceof VerticalCS) {
+                if (baseCRS != null) {
+                    return crsFactory.createDerivedCRS(properties, baseCRS, fromBase, cs);
                 }
+                /*
+                 * The 'parseVerticalDatum(…)' method may have been unable to resolve the
datum type.
+                 * But sometime the axis (which was not available when we created the datum)
provides
+                 * more information. Verify if we can have a better type now, and if so rebuild
the datum.
+                 */
+                if (VerticalDatumType.OTHER_SURFACE.equals(datum.getVerticalDatumType()))
{
+                    final VerticalDatumType type = VerticalDatumTypes.guess(datum.getName().getCode(),
datum.getAlias(), cs.getAxis(0));
+                    if (!VerticalDatumType.OTHER_SURFACE.equals(type)) {
+                        datum = datumFactory.createVerticalDatum(referencing.getProperties(datum),
type);
+                    }
+                }
+                verticalCRS = crsFactory.createVerticalCRS(properties, datum, (VerticalCS)
cs);
+                /*
+                 * Some DefaultVerticalExtent objects may be waiting for the VerticalCRS
before to complete
+                 * their construction. If this is the case, try to complete them now.
+                 */
+                if (verticalElements != null) {
+                    verticalElements = verticalElements.resolve(verticalCRS);
+                }
+                return verticalCRS;
             }
-            verticalCRS = crsFactory.createVerticalCRS(parseMetadataAndClose(element, name,
datum), datum, (VerticalCS) cs);
-            /*
-             * Some DefaultVerticalExtent objects may be waiting for the VerticalCRS before
to complete
-             * their construction. If this is the case, try to complete them now.
-             */
-            if (verticalElements != null) {
-                verticalElements = verticalElements.resolve(verticalCRS);
-            }
-            return verticalCRS;
         } catch (FactoryException exception) {
             throw element.parseFailed(exception);
         }
+        throw element.illegalCS(cs);
     }
 
     /**
@@ -1646,22 +1675,45 @@ final class GeodeticObjectParser extends
      * @return The {@code "TimeCRS"} element as a {@link TemporalCRS} object.
      * @throws ParseException if the {@code "TimeCRS"} element can not be parsed.
      */
-    private TemporalCRS parseTimeCRS(final int mode, final Element parent, final boolean
isBaseCRS)
+    private SingleCRS parseTimeCRS(final int mode, final Element parent, final boolean isBaseCRS)
             throws ParseException
     {
         final Element element = parent.pullElement(mode, isBaseCRS ? WKTKeywords.BaseTimeCRS
: WKTKeywords.TimeCRS);
         if (element == null) {
             return null;
         }
-        final String         name     = element.pullString("name");
-        final TemporalDatum  datum    = parseTimeDatum(MANDATORY, element);
-        final Unit<Duration> timeUnit = parseScaledUnit(element, WKTKeywords.TimeUnit,
SI.SECOND);
+        final String         name = element.pullString("name");
+        final Unit<Duration> unit = parseScaledUnit(element, WKTKeywords.TimeUnit,
SI.SECOND);
+        /*
+         * A TemporalCRS can be either a "normal" one (with a non-null datum), or a DerivedCRS
of kind TemporalCRS.
+         * In the later case, the datum is null and we have instead DerivingConversion element
from a BaseTimeCRS.
+         */
+        TemporalDatum datum    = null;
+        SingleCRS     baseCRS  = null;
+        Conversion    fromBase = null;
+        if (!isBaseCRS) {
+            fromBase = parseDerivingConversion(OPTIONAL, element, WKTKeywords.DerivingConversion,
null, null);
+            if (fromBase != null) {
+                baseCRS = parseTimeCRS(MANDATORY, element, true);
+            }
+        }
+        if (baseCRS == null) {  // The most usual case.
+            datum = parseTimeDatum(MANDATORY, element);
+        }
+        final CoordinateSystem cs;
         try {
-            final CoordinateSystem cs = parseCoordinateSystem(element, WKTKeywords.temporal,
1, false, timeUnit, datum);
-            return crsFactory.createTemporalCRS(parseMetadataAndClose(element, name, datum),
datum, (TimeCS) cs);
+            cs = parseCoordinateSystem(element, WKTKeywords.temporal, 1, false, unit, datum);
+            final Map<String,?> properties = parseMetadataAndClose(element, name, datum);
+            if (cs instanceof TimeCS) {
+                if (baseCRS != null) {
+                    return crsFactory.createDerivedCRS(properties, baseCRS, fromBase, cs);
+                }
+                return crsFactory.createTemporalCRS(properties, datum, (TimeCS) cs);
+            }
         } catch (FactoryException exception) {
             throw element.parseFailed(exception);
         }
+        throw element.illegalCS(cs);
     }
 
     /**
@@ -1710,10 +1762,13 @@ final class GeodeticObjectParser extends
         try {
             cs = parseCoordinateSystem(element, WKTKeywords.Cartesian, 2, isWKT1, linearUnit,
geoCRS.getDatum());
             final Map<String,?> properties = parseMetadataAndClose(element, name, conversion);
-            return crsFactory.createProjectedCRS(properties, (GeographicCRS) geoCRS, conversion,
(CartesianCS) cs);
+            if (cs instanceof CartesianCS) {
+                return crsFactory.createProjectedCRS(properties, (GeographicCRS) geoCRS,
conversion, (CartesianCS) cs);
+            }
         } catch (FactoryException exception) {
             throw element.parseFailed(exception);
         }
+        throw element.illegalCS(cs);
     }
 
     /**



Mime
View raw message