sis-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From desruisse...@apache.org
Subject svn commit: r1564354 - in /sis/branches/JDK7/core: sis-metadata/src/main/java/org/apache/sis/metadata/iso/extent/ sis-referencing/src/main/java/org/apache/sis/io/wkt/ sis-referencing/src/test/java/org/apache/sis/io/wkt/ sis-referencing/src/test/java/or...
Date Tue, 04 Feb 2014 15:52:15 GMT
Author: desruisseaux
Date: Tue Feb  4 15:52:15 2014
New Revision: 1564354

URL: http://svn.apache.org/r1564354
Log:
Partial support of TIMEEXTENT element. Non-supported aspects are documented in SIS-163.

Modified:
    sis/branches/JDK7/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/extent/Extents.java
    sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/io/wkt/Convention.java
    sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/io/wkt/Formatter.java
    sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/io/wkt/WKTFormat.java
    sis/branches/JDK7/core/sis-referencing/src/test/java/org/apache/sis/io/wkt/FormatterTest.java
    sis/branches/JDK7/core/sis-referencing/src/test/java/org/apache/sis/referencing/crs/HardCodedCRS.java

Modified: sis/branches/JDK7/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/extent/Extents.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/extent/Extents.java?rev=1564354&r1=1564353&r2=1564354&view=diff
==============================================================================
--- sis/branches/JDK7/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/extent/Extents.java
[UTF-8] (original)
+++ sis/branches/JDK7/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/extent/Extents.java
[UTF-8] Tue Feb  4 15:52:15 2014
@@ -30,6 +30,7 @@ import org.opengis.referencing.cs.AxisDi
 import org.opengis.referencing.crs.VerticalCRS;
 import org.apache.sis.measure.Longitude;
 import org.apache.sis.measure.MeasurementRange;
+import org.apache.sis.measure.Range;
 import org.apache.sis.util.resources.Vocabulary;
 import org.apache.sis.util.ArgumentChecks;
 import org.apache.sis.util.Static;
@@ -207,6 +208,39 @@ public final class Extents extends Stati
     }
 
     /**
+     * Returns the union of all time ranges found in the given extent, or {@code null} if
none.
+     *
+     * @param  extent The extent to convert to a time range, or {@code null}.
+     * @return A time range created from the given extent, or {@code null} if none.
+     *
+     * @since 0.4
+     */
+    public static Range<Date> getTimeRange(final Extent extent) {
+        Date min = null;
+        Date max = null;
+        if (extent != null) {
+            for (final TemporalExtent t : extent.getTemporalElements()) {
+                final Date startTime, endTime;
+                if (t instanceof DefaultTemporalExtent) {
+                    final DefaultTemporalExtent dt = (DefaultTemporalExtent) t;
+                    startTime = dt.getStartTime(); // Maybe user has overridden those methods.
+                    endTime   = dt.getEndTime();
+                } else {
+                    final TemporalPrimitive p = t.getExtent();
+                    startTime = DefaultTemporalExtent.getTime(p, true);
+                    endTime   = DefaultTemporalExtent.getTime(p, false);
+                }
+                if (startTime != null && (min == null || startTime.before(min)))
min = startTime;
+                if (  endTime != null && (max == null ||   endTime.after (max)))
max =   endTime;
+            }
+        }
+        if (min == null && max == null) {
+            return null;
+        }
+        return new Range<>(Date.class, min, true, max, true);
+    }
+
+    /**
      * Returns an instant in the {@linkplain Extent#getTemporalElements() temporal elements}
of the given extent,
      * or {@code null} if none. First, this method computes the union of all temporal elements.
Then this method
      * computes the linear interpolation between the start and end time as in the following
pseudo-code:

Modified: sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/io/wkt/Convention.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/io/wkt/Convention.java?rev=1564354&r1=1564353&r2=1564354&view=diff
==============================================================================
--- sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/io/wkt/Convention.java
[UTF-8] (original)
+++ sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/io/wkt/Convention.java
[UTF-8] Tue Feb  4 15:52:15 2014
@@ -73,6 +73,8 @@ public enum Convention {
      *   <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} elements are omitted.</li>
+     *   <li>In {@code VERTICALEXTENT} elements, the {@code UNIT} element is omitted
+     *       if the unit is {@link javax.measure.unit.SI#METRE}.</li>
      * </ul>
      *
      * Those simplifications are allowed by the ISO 19162 standard and do not cause any information
lost.

Modified: sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/io/wkt/Formatter.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/io/wkt/Formatter.java?rev=1564354&r1=1564353&r2=1564354&view=diff
==============================================================================
--- sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/io/wkt/Formatter.java
[UTF-8] (original)
+++ sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/io/wkt/Formatter.java
[UTF-8] Tue Feb  4 15:52:15 2014
@@ -16,9 +16,12 @@
  */
 package org.apache.sis.io.wkt;
 
+import java.util.Date;
 import java.util.Locale;
 import java.util.Collection;
 import java.text.NumberFormat;
+import java.text.DateFormat;
+import java.text.SimpleDateFormat;
 import java.text.FieldPosition;
 import java.lang.reflect.Array;
 import java.math.RoundingMode;
@@ -56,6 +59,7 @@ import org.apache.sis.util.CharSequences
 import org.apache.sis.util.ArgumentChecks;
 import org.apache.sis.util.resources.Errors;
 import org.apache.sis.internal.util.Citations;
+import org.apache.sis.measure.Range;
 import org.apache.sis.measure.MeasurementRange;
 import org.apache.sis.metadata.iso.extent.Extents;
 import org.apache.sis.referencing.IdentifiedObjects;
@@ -162,6 +166,11 @@ public class Formatter {
     private final NumberFormat numberFormat;
 
     /**
+     * The object to use for formatting dates.
+     */
+    private final DateFormat dateFormat;
+
+    /**
      * The object to use for formatting unit symbols.
      */
     private final UnitFormat unitFormat;
@@ -263,6 +272,7 @@ public class Formatter {
         this.symbols      = symbols.immutable();
         this.indentation  = (byte) indentation;
         this.numberFormat = symbols.createNumberFormat();
+        this.dateFormat   = new SimpleDateFormat(WKTFormat.DATE_PATTERN, symbols.getLocale());
         this.unitFormat   = UnitFormat.getInstance(symbols.getLocale());
         this.buffer       = new StringBuffer();
     }
@@ -271,13 +281,16 @@ public class Formatter {
      * Constructor for private use by {@link WKTFormat#getFormatter()} only. This allows
to use the number
      * format created by {@link WKTFormat#createFormat(Class)}, which may be overridden by
the user.
      */
-    Formatter(final Locale locale, final Symbols symbols, final NumberFormat numberFormat,
final UnitFormat unitFormat) {
+    Formatter(final Locale locale, final Symbols symbols, final NumberFormat numberFormat,
+            final DateFormat dateFormat, final UnitFormat unitFormat)
+    {
         this.locale       = locale;
         this.convention   = Convention.DEFAULT;
         this.authority    = Convention.DEFAULT.getNameAuthority();
         this.symbols      = symbols;
         this.indentation  = WKTFormat.DEFAULT_INDENTATION;
         this.numberFormat = numberFormat; // No clone needed.
+        this.dateFormat   = dateFormat;   // No clone needed.
         this.unitFormat   = unitFormat;   // No clone needed.
         // Do not set the buffer. It will be set by WKTFormat.format(…).
     }
@@ -601,7 +614,20 @@ public class Formatter {
                 setColor(ElementKind.EXTENT);
                 append(range.getMinDouble());
                 append(range.getMaxDouble());
-                append(range.unit());
+                final Unit<?> unit = range.unit();
+                if (!convention.isSimple() || !SI.METRE.equals(unit)) {
+                    requestNewLine = false;
+                    append(unit); // Unit are optional if they are metres.
+                }
+                resetColor();
+                closeElement();
+            }
+            final Range<Date> timeRange = Extents.getTimeRange(area);
+            if (timeRange != null) {
+                openElement("TIMEEXTENT");
+                setColor(ElementKind.EXTENT);
+                append(timeRange.getMinValue());
+                append(timeRange.getMaxValue());
                 resetColor();
                 closeElement();
             }
@@ -897,6 +923,19 @@ public class Formatter {
     }
 
     /**
+     * Appends a date.
+     * The {@linkplain Symbols#getSeparator() element separator} will be written before the
date if needed.
+     *
+     * @param date The date to append to the WKT, or {@code null} if none.
+     */
+    public void append(final Date date) {
+        if (date != null) {
+            appendSeparator(false);
+            dateFormat.format(date, buffer, dummy);
+        }
+    }
+
+    /**
      * Appends an integer value.
      * The {@linkplain Symbols#getSeparator() element separator} will be written before the
number if needed.
      *

Modified: sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/io/wkt/WKTFormat.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/io/wkt/WKTFormat.java?rev=1564354&r1=1564353&r2=1564354&view=diff
==============================================================================
--- sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/io/wkt/WKTFormat.java
[UTF-8] (original)
+++ sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/io/wkt/WKTFormat.java
[UTF-8] Tue Feb  4 15:52:15 2014
@@ -19,12 +19,12 @@ package org.apache.sis.io.wkt;
 import java.util.Date;
 import java.util.Locale;
 import java.util.TimeZone;
+import java.io.IOException;
 import java.text.Format;
 import java.text.NumberFormat;
-import java.text.ParsePosition;
-import java.io.IOException;
 import java.text.DateFormat;
 import java.text.SimpleDateFormat;
+import java.text.ParsePosition;
 import javax.measure.unit.Unit;
 import javax.measure.unit.UnitFormat;
 import org.opengis.metadata.citation.Citation;
@@ -102,6 +102,13 @@ public class WKTFormat extends CompoundF
     static final byte DEFAULT_INDENTATION = 2;
 
     /**
+     * The pattern of dates.
+     *
+     * @see #createFormat(Class)
+     */
+    static final String DATE_PATTERN = "yyyy-MM-dd";
+
+    /**
      * The symbols to use for this formatter.
      * The same object is also referenced in the {@linkplain #parser} and {@linkplain #formatter}.
      * It appears here for serialization purpose.
@@ -369,6 +376,7 @@ public class WKTFormat extends CompoundF
         if (formatter == null) {
             formatter = new Formatter(getLocale(), symbols,
                     (NumberFormat) getFormat(Number.class),
+                    (DateFormat)   getFormat(Date.class),
                     (UnitFormat)   getFormat(Unit.class));
             updateFormatter(formatter);
             this.formatter = formatter;
@@ -426,7 +434,7 @@ public class WKTFormat extends CompoundF
             return UnitFormat.getInstance(symbols.getLocale());
         }
         if (valueType == Date.class) {
-            final DateFormat format = new SimpleDateFormat("yyyy-MM-dd", symbols.getLocale());
+            final DateFormat format = new SimpleDateFormat(DATE_PATTERN, symbols.getLocale());
             format.setTimeZone(getTimeZone());
             return format;
         }

Modified: sis/branches/JDK7/core/sis-referencing/src/test/java/org/apache/sis/io/wkt/FormatterTest.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-referencing/src/test/java/org/apache/sis/io/wkt/FormatterTest.java?rev=1564354&r1=1564353&r2=1564354&view=diff
==============================================================================
--- sis/branches/JDK7/core/sis-referencing/src/test/java/org/apache/sis/io/wkt/FormatterTest.java
[UTF-8] (original)
+++ sis/branches/JDK7/core/sis-referencing/src/test/java/org/apache/sis/io/wkt/FormatterTest.java
[UTF-8] Tue Feb  4 15:52:15 2014
@@ -16,16 +16,22 @@
  */
 package org.apache.sis.io.wkt;
 
-import org.opengis.referencing.IdentifiedObject;
+import java.util.Map;
+import java.util.HashMap;
 import org.opengis.referencing.operation.Matrix;
-import org.apache.sis.referencing.AbstractIdentifiedObject;
+import org.apache.sis.metadata.iso.extent.DefaultExtent;
+import org.apache.sis.metadata.iso.extent.DefaultVerticalExtent;
+import org.apache.sis.metadata.iso.extent.DefaultTemporalExtent;
+import org.apache.sis.metadata.iso.extent.DefaultGeographicBoundingBox;
+import org.apache.sis.referencing.AbstractReferenceSystem;
 import org.apache.sis.referencing.operation.matrix.Matrix4;
+import org.apache.sis.referencing.crs.HardCodedCRS;
 import org.apache.sis.internal.util.X364;
 import org.apache.sis.test.DependsOn;
 import org.apache.sis.test.TestCase;
 import org.junit.Test;
 
-import static java.util.Collections.singletonMap;
+import static org.opengis.referencing.ReferenceSystem.*;
 import static org.apache.sis.referencing.Assert.*;
 
 
@@ -49,13 +55,28 @@ public final strictfp class FormatterTes
     }
 
     /**
-     * Tests {@link Formatter#append(IdentifiedObject)} with a name that contains the quote
character.
-     * We test that the closing quote character is doubled.
+     * Tests {@link Formatter#append(IdentifiedObject)} with a name that contains the quote
character
+     * and optional information. We test that the closing quote character is doubled and
the optional
+     * information properly formatted.
      */
     @Test
     public void testAppendIdentifiedObject() {
-        assertWktEquals("IdentifiedObject[“My “object””.”]",
-                new AbstractIdentifiedObject(singletonMap(IdentifiedObject.NAME_KEY, "My
“object”.")));
+        final Map<String,Object> properties = new HashMap<>(8);
+        assertNull(properties.put(NAME_KEY, "My “object”."));
+        assertNull(properties.put(SCOPE_KEY, "Large scale topographic mapping and cadastre."));
+        assertNull(properties.put(REMARKS_KEY, "注です。"));
+        assertNull(properties.put(DOMAIN_OF_VALIDITY_KEY, new DefaultExtent("Netherlands
offshore.",
+                new DefaultGeographicBoundingBox(2.54, 6.40, 51.43, 55.77),
+                new DefaultVerticalExtent(10, 1000, HardCodedCRS.DEPTH),
+                new DefaultTemporalExtent()))); // TODO: needs sis-temporal module for testing
that one.
+        assertWktEquals(
+                "ReferenceSystem[“My “object””.”,\n" +
+                "  SCOPE[“Large scale topographic mapping and cadastre.”],\n" +
+                "  AREA[“Netherlands offshore.”],\n" +
+                "  BBOX[51.43, 2.54, 55.77, 6.40],\n" +
+                "  VERTICALEXTENT[-1000.0, -10.0, LENGTHUNIT[“metre”, 1.0]],\n" +
+                "  REMARKS[“注です。”]]",
+                new AbstractReferenceSystem(properties));
     }
 
     /**

Modified: sis/branches/JDK7/core/sis-referencing/src/test/java/org/apache/sis/referencing/crs/HardCodedCRS.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-referencing/src/test/java/org/apache/sis/referencing/crs/HardCodedCRS.java?rev=1564354&r1=1564353&r2=1564354&view=diff
==============================================================================
--- sis/branches/JDK7/core/sis-referencing/src/test/java/org/apache/sis/referencing/crs/HardCodedCRS.java
[UTF-8] (original)
+++ sis/branches/JDK7/core/sis-referencing/src/test/java/org/apache/sis/referencing/crs/HardCodedCRS.java
[UTF-8] Tue Feb  4 15:52:15 2014
@@ -131,6 +131,12 @@ public final strictfp class HardCodedCRS
             getProperties(HardCodedCS.GRAVITY_RELATED_HEIGHT), HardCodedDatum.MEAN_SEA_LEVEL,
HardCodedCS.GRAVITY_RELATED_HEIGHT);
 
     /**
+     * A vertical coordinate reference system using Mean Sea Level datum.
+     */
+    public static final DefaultVerticalCRS DEPTH = new DefaultVerticalCRS(
+            getProperties(HardCodedCS.DEPTH), HardCodedDatum.MEAN_SEA_LEVEL, HardCodedCS.DEPTH);
+
+    /**
      * A temporal coordinate reference system for time in days elapsed since the Unix epoch.
      */
     public static final DefaultTemporalCRS TIME = new DefaultTemporalCRS(



Mime
View raw message