sis-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From desruisse...@apache.org
Subject svn commit: r1467795 - in /sis/branches/JDK7: sis-referencing/src/main/java/org/apache/sis/geometry/ sis-referencing/src/test/java/org/apache/sis/geometry/ sis-utility/src/main/java/org/apache/sis/util/ sis-utility/src/main/java/org/apache/sis/util/res...
Date Sun, 14 Apr 2013 15:51:15 GMT
Author: desruisseaux
Date: Sun Apr 14 15:51:15 2013
New Revision: 1467795

URL: http://svn.apache.org/r1467795
Log:
Partial port of the Envelopes static utilities.

Added:
    sis/branches/JDK7/sis-referencing/src/main/java/org/apache/sis/geometry/Envelopes.java
  (with props)
    sis/branches/JDK7/sis-referencing/src/test/java/org/apache/sis/geometry/EnvelopesTest.java
  (with props)
Modified:
    sis/branches/JDK7/sis-referencing/src/main/java/org/apache/sis/geometry/AbstractDirectPosition.java
    sis/branches/JDK7/sis-referencing/src/main/java/org/apache/sis/geometry/AbstractEnvelope.java
    sis/branches/JDK7/sis-referencing/src/main/java/org/apache/sis/geometry/ArrayEnvelope.java
    sis/branches/JDK7/sis-referencing/src/main/java/org/apache/sis/geometry/Envelope2D.java
    sis/branches/JDK7/sis-referencing/src/main/java/org/apache/sis/geometry/GeneralEnvelope.java
    sis/branches/JDK7/sis-referencing/src/main/java/org/apache/sis/geometry/ImmutableEnvelope.java
    sis/branches/JDK7/sis-referencing/src/test/java/org/apache/sis/geometry/GeneralEnvelopeTest.java
    sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/util/Static.java
    sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/util/resources/Errors.java
    sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/util/resources/Errors.properties
    sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/util/resources/Errors_fr.properties

Modified: sis/branches/JDK7/sis-referencing/src/main/java/org/apache/sis/geometry/AbstractDirectPosition.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/sis-referencing/src/main/java/org/apache/sis/geometry/AbstractDirectPosition.java?rev=1467795&r1=1467794&r2=1467795&view=diff
==============================================================================
--- sis/branches/JDK7/sis-referencing/src/main/java/org/apache/sis/geometry/AbstractDirectPosition.java
[UTF-8] (original)
+++ sis/branches/JDK7/sis-referencing/src/main/java/org/apache/sis/geometry/AbstractDirectPosition.java
[UTF-8] Sun Apr 14 15:51:15 2013
@@ -214,7 +214,7 @@ public abstract class AbstractDirectPosi
     }
 
     /**
-     * Implementation of the public {@link #toString()} and {@link Envelope2D#toString()}
methods
+     * Implementation of the public {@link #toString()} and {@link DirectPosition2D#toString()}
methods
      * for formatting a {@code POINT} element from a direct position in <cite>Well
Known Text</cite>
      * (WKT) format.
      *

Modified: sis/branches/JDK7/sis-referencing/src/main/java/org/apache/sis/geometry/AbstractEnvelope.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/sis-referencing/src/main/java/org/apache/sis/geometry/AbstractEnvelope.java?rev=1467795&r1=1467794&r2=1467795&view=diff
==============================================================================
--- sis/branches/JDK7/sis-referencing/src/main/java/org/apache/sis/geometry/AbstractEnvelope.java
[UTF-8] (original)
+++ sis/branches/JDK7/sis-referencing/src/main/java/org/apache/sis/geometry/AbstractEnvelope.java
[UTF-8] Sun Apr 14 15:51:15 2013
@@ -915,20 +915,26 @@ public abstract class AbstractEnvelope i
     }
 
     /**
-     * Formats this envelope in the <cite>Well Known Text</cite> (WKT) format.
+     * Formats this envelope as a "{@code BOX}" element.
      * The output is of the form "{@code BOX}<var>n</var>{@code D(}{@linkplain
#getLowerCorner()
      * lower corner}{@code ,}{@linkplain #getUpperCorner() upper corner}{@code )}"
      * where <var>n</var> is the {@linkplain #getDimension() number of dimensions}.
-     * Example:
+     * The number of dimension is written only if different than 2.
+     *
+     * <p>Example:</p>
      *
      * {@preformat wkt
+     *   BOX(-90 -180, 90 180)
      *   BOX3D(-90 -180 0, 90 180 1)
      * }
      *
+     * {@note The <code>BOX</code> element is not part of the standard <cite>Well
Known Text</cite>
+     *        (WKT) format. However it is understood by many softwares, for example GDAL
and PostGIS.}
+     *
      * The string returned by this method can be {@linkplain GeneralEnvelope#GeneralEnvelope(CharSequence)
parsed}
      * by the {@code GeneralEnvelope} constructor.
      *
-     * @return This envelope as a {@code BOX2D} or {@code BOX3D} (most typical dimensions)
in WKT format.
+     * @return This envelope as a {@code BOX} or {@code BOX3D} (most typical dimensions)
element.
      */
     @Override
     public String toString() {
@@ -936,12 +942,12 @@ public abstract class AbstractEnvelope i
     }
 
     /**
-     * Implementation of the public {@link #toString()} and {@link Envelopes#toWKT(Envelope)}
methods
-     * for formatting a {@code BOX} element from an envelope in <cite>Well Known Text</cite>
(WKT) format.
+     * Implementation of the public {@link #toString()} and {@link Envelopes#toString(Envelope)}
+     * methods for formatting a {@code BOX} element from an envelope.
      *
      * @param  envelope The envelope to format.
      * @param  isSimplePrecision {@code true} if every lower and upper corner values can
be casted to {@code float}.
-     * @return The envelope as a {@code BOX2D} or {@code BOX3D} (most typical dimensions)
in WKT format.
+     * @return This envelope as a {@code BOX} or {@code BOX3D} (most typical dimensions)
element.
      *
      * @see GeneralEnvelope#GeneralEnvelope(CharSequence)
      * @see org.apache.sis.measure.CoordinateFormat
@@ -949,7 +955,10 @@ public abstract class AbstractEnvelope i
      */
     static String toString(final Envelope envelope, final boolean isSimplePrecision) {
         final int dimension = envelope.getDimension();
-        final StringBuilder buffer = new StringBuilder(64).append("BOX").append(dimension).append('D');
+        final StringBuilder buffer = new StringBuilder(64).append("BOX");
+        if (dimension != 2) {
+            buffer.append(dimension).append('D');
+        }
         if (dimension == 0) {
             buffer.append("()");
         } else {

Modified: sis/branches/JDK7/sis-referencing/src/main/java/org/apache/sis/geometry/ArrayEnvelope.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/sis-referencing/src/main/java/org/apache/sis/geometry/ArrayEnvelope.java?rev=1467795&r1=1467794&r2=1467795&view=diff
==============================================================================
--- sis/branches/JDK7/sis-referencing/src/main/java/org/apache/sis/geometry/ArrayEnvelope.java
[UTF-8] (original)
+++ sis/branches/JDK7/sis-referencing/src/main/java/org/apache/sis/geometry/ArrayEnvelope.java
[UTF-8] Sun Apr 14 15:51:15 2013
@@ -187,8 +187,8 @@ class ArrayEnvelope extends AbstractEnve
 
     /**
      * Constructs a new envelope initialized to the values parsed from the given string in
-     * <cite>Well Known Text</cite> (WKT) format. The given string is typically
a {@code BOX}
-     * element like below:
+     * {@code BOX} or <cite>Well Known Text</cite> (WKT) format. The given string
is typically
+     * a {@code BOX} element like below:
      *
      * {@preformat wkt
      *     BOX(-180 -90, 180 90)

Modified: sis/branches/JDK7/sis-referencing/src/main/java/org/apache/sis/geometry/Envelope2D.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/sis-referencing/src/main/java/org/apache/sis/geometry/Envelope2D.java?rev=1467795&r1=1467794&r2=1467795&view=diff
==============================================================================
--- sis/branches/JDK7/sis-referencing/src/main/java/org/apache/sis/geometry/Envelope2D.java
[UTF-8] (original)
+++ sis/branches/JDK7/sis-referencing/src/main/java/org/apache/sis/geometry/Envelope2D.java
[UTF-8] Sun Apr 14 15:51:15 2013
@@ -966,16 +966,16 @@ public class Envelope2D extends Rectangl
     }
 
     /**
-     * Formats this envelope in the <cite>Well Known Text</cite> (WKT) format.
-     * The output is of the form "{@code BOX2D(}{@linkplain #getLowerCorner()
+     * Formats this envelope as a "{@code BOX}" element.
+     * The output is of the form "{@code BOX(}{@linkplain #getLowerCorner()
      * lower corner}{@code ,}{@linkplain #getUpperCorner() upper corner}{@code )}".
      * Example:
      *
      * {@preformat wkt
-     *   BOX3D(-90 -180, 90 180)
+     *   BOX(-90 -180, 90 180)
      * }
      *
-     * @see Envelopes#toWKT(Envelope)
+     * @see Envelopes#toString(Envelope)
      */
     @Override
     public String toString() {

Added: sis/branches/JDK7/sis-referencing/src/main/java/org/apache/sis/geometry/Envelopes.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/sis-referencing/src/main/java/org/apache/sis/geometry/Envelopes.java?rev=1467795&view=auto
==============================================================================
--- sis/branches/JDK7/sis-referencing/src/main/java/org/apache/sis/geometry/Envelopes.java
(added)
+++ sis/branches/JDK7/sis-referencing/src/main/java/org/apache/sis/geometry/Envelopes.java
[UTF-8] Sun Apr 14 15:51:15 2013
@@ -0,0 +1,170 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.sis.geometry;
+
+/*
+ * Do not add dependency to java.awt.Rectangle2D in this class, because not every platforms
+ * support Java2D (e.g. Android),  or applications that do not need it may want to avoid
to
+ * force installation of the Java2D module (e.g. JavaFX/SWT).
+ */
+import org.opengis.geometry.Envelope;
+import org.opengis.util.FactoryException;
+import org.apache.sis.util.Static;
+import org.apache.sis.util.resources.Errors;
+
+import static org.apache.sis.util.ArgumentChecks.ensureNonNull;
+import static org.apache.sis.util.StringBuilders.trimFractionalPart;
+
+
+/**
+ * Utility methods for envelopes. This utility class is made up of static functions working
+ * with arbitrary implementations of GeoAPI interfaces.
+ *
+ * @author  Martin Desruisseaux (IRD, Geomatys)
+ * @author  Johann Sorel (Geomatys)
+ * @since   0.3 (derived from geotk-2.4)
+ * @version 0.3
+ * @module
+ *
+ * @see CRS
+ */
+public final class Envelopes extends Static {
+    /**
+     * Enumeration of the 4 corners in an envelope, with repetition of the first point.
+     * The values are (x,y) pairs with {@code false} meaning "minimal value" and {@code true}
+     * meaning "maximal value". This is used by {@link #toPolygonWKT(Envelope)} only.
+     */
+    private static final boolean[] CORNERS = {
+        false, false,
+        false, true,
+        true,  true,
+        true,  false,
+        false, false
+    };
+
+    /**
+     * Do not allow instantiation of this class.
+     */
+    private Envelopes() {
+    }
+
+    /**
+     * Returns the bounding box of a geometry defined in <cite>Well Known Text</cite>
(WKT) format.
+     * This method does not check the consistency of the provided WKT. For example it does
not check
+     * that every points in a {@code LINESTRING} have the same dimension. However this method
+     * ensures that the parenthesis are balanced, in order to catch some malformed WKT.
+     *
+     * <p>Example:</p>
+     * <ul>
+     *   <li>{@code BOX(-180 -90, 180 90)} (not really a geometry, but understood by
many softwares)</li>
+     *   <li>{@code POINT(6 10)}</li>
+     *   <li>{@code MULTIPOLYGON(((1 1, 5 1, 1 5, 1 1),(2 2, 3 2, 3 3, 2 2)))}</li>
+     *   <li>{@code GEOMETRYCOLLECTION(POINT(4 6),LINESTRING(3 8,7 10))}</li>
+     * </ul>
+     *
+     * See {@link GeneralEnvelope#GeneralEnvelope(String)} for more information about the
+     * parsing rules.
+     *
+     * @param  wkt The {@code BOX}, {@code POLYGON} or other kind of element to parse.
+     * @return The envelope of the given geometry.
+     * @throws FactoryException If the given WKT can not be parsed.
+     *
+     * @see #toString(Envelope)
+     * @see CRS#fromWKT(String)
+     * @see org.apache.sis.io.wkt
+     */
+    public static Envelope fromWKT(final String wkt) throws FactoryException {
+        ensureNonNull("wkt", wkt);
+        try {
+            return new GeneralEnvelope(wkt);
+        } catch (RuntimeException e) {
+            throw new FactoryException(Errors.format(
+                    Errors.Keys.UnparsableStringForClass_2, Envelope.class), e);
+        }
+    }
+
+    /**
+     * Formats the given envelope as a {@code BOX} element. The output is like below,
+     * where <var>n</var> is the {@linkplain Envelope#getDimension() number of
dimensions}
+     * (omitted if equals to 2):
+     *
+     * <blockquote>{@code BOX}<var>n</var>{@code D(}{@linkplain Envelope#getLowerCorner()
lower
+     * corner}{@code ,} {@linkplain Envelope#getUpperCorner() upper corner}{@code )}</blockquote>
+     *
+     * {@note The <code>BOX</code> element is not part of the standard <cite>Well
Known Text</cite>
+     *        (WKT) format. However it is understood by many softwares, for example GDAL
and PostGIS.}
+     *
+     * The string returned by this method can be {@linkplain GeneralEnvelope#GeneralEnvelope(String)
+     * parsed} by the {@code GeneralEnvelope} constructor.
+     *
+     * @param  envelope The envelope to format.
+     * @return The envelope as a {@code BOX} or {@code BOX3D} in WKT format.
+     *
+     * @see #fromWKT(String)
+     * @see org.apache.sis.io.wkt
+     */
+    public static String toString(final Envelope envelope) {
+        return AbstractEnvelope.toString(envelope, false);
+    }
+
+    /**
+     * Formats the given envelope as a {@code POLYGON} element in the <cite>Well Known
Text</cite>
+     * (WKT) format. {@code POLYGON} can be used as an alternative to {@code BOX} when the
element
+     * needs to be considered as a standard WKT geometry.
+     *
+     * <p>The string returned by this method can be {@linkplain GeneralEnvelope#GeneralEnvelope(String)
+     * parsed} by the {@code GeneralEnvelope} constructor.</p>
+     *
+     * @param  envelope The envelope to format.
+     * @return The envelope as a {@code POLYGON} in WKT format.
+     * @throws IllegalArgumentException if the given envelope can not be formatted.
+     *
+     * @see org.apache.sis.io.wkt
+     */
+    public static String toPolygonWKT(final Envelope envelope) throws IllegalArgumentException
{
+        /*
+         * Get the dimension, ignoring the trailing ones which have infinite values.
+         */
+        int dimension = envelope.getDimension();
+        while (dimension != 0) {
+            final double length = envelope.getSpan(dimension - 1);
+            if (!Double.isNaN(length) && !Double.isInfinite(length)) {
+                break;
+            }
+            dimension--;
+        }
+        if (dimension < 2) {
+            throw new IllegalArgumentException(Errors.format(Errors.Keys.EmptyEnvelope2D));
+        }
+        final StringBuilder buffer = new StringBuilder("POLYGON(");
+        String separator = "(";
+        for (int corner=0; corner<CORNERS.length; corner+=2) {
+            for (int i=0; i<dimension; i++) {
+                final double value;
+                switch (i) {
+                    case  0: // Fall through
+                    case  1: value = CORNERS[corner+i] ? envelope.getMaximum(i) : envelope.getMinimum(i);
break;
+                    default: value = envelope.getMedian(i); break;
+                }
+                trimFractionalPart(buffer.append(separator).append(value));
+                separator = " ";
+            }
+            separator = ", ";
+        }
+        return buffer.append("))").toString();
+    }
+}

Propchange: sis/branches/JDK7/sis-referencing/src/main/java/org/apache/sis/geometry/Envelopes.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: sis/branches/JDK7/sis-referencing/src/main/java/org/apache/sis/geometry/Envelopes.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain;charset=UTF-8

Modified: sis/branches/JDK7/sis-referencing/src/main/java/org/apache/sis/geometry/GeneralEnvelope.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/sis-referencing/src/main/java/org/apache/sis/geometry/GeneralEnvelope.java?rev=1467795&r1=1467794&r2=1467795&view=diff
==============================================================================
--- sis/branches/JDK7/sis-referencing/src/main/java/org/apache/sis/geometry/GeneralEnvelope.java
[UTF-8] (original)
+++ sis/branches/JDK7/sis-referencing/src/main/java/org/apache/sis/geometry/GeneralEnvelope.java
[UTF-8] Sun Apr 14 15:51:15 2013
@@ -62,7 +62,7 @@ import static org.apache.sis.math.MathFu
  *   <li>{@linkplain #GeneralEnvelope(Envelope) From a an other envelope} (copy constructor).</li>
  *   <li>{@linkplain #GeneralEnvelope(GeographicBoundingBox) From a geographic bounding
box}.</li>
  *   <li>{@linkplain #GeneralEnvelope(CharSequence) From a character sequence}
- *       representing a {@code BBOX} in <cite>Well Known Text</cite> (WKT) format.</li>
+ *       representing a {@code BBOX} or a <cite>Well Known Text</cite> (WKT)
format.</li>
  * </ul>
  *
  * {@section Spanning the anti-meridian of a Geographic CRS}
@@ -182,8 +182,8 @@ public class GeneralEnvelope extends Arr
 
     /**
      * Constructs a new envelope initialized to the values parsed from the given string in
-     * <cite>Well Known Text</cite> (WKT) format. The given string is typically
a {@code BOX}
-     * element like below:
+     * {@code BOX} or <cite>Well Known Text</cite> (WKT) format. The given string
is typically
+     * a {@code BOX} element like below:
      *
      * {@preformat wkt
      *     BOX(-180 -90, 180 90)
@@ -201,11 +201,11 @@ public class GeneralEnvelope extends Arr
      *   <li>The coordinate having the highest dimension determines the dimension of
this envelope.</li>
      * </ul>
      *
-     * This constructor does not check the consistency of the provided WKT. For example it
doesn't
+     * This constructor does not check the consistency of the provided text. For example
it does not
      * check that every points in a {@code LINESTRING} have the same dimension. However this
      * constructor ensures that the parenthesis are balanced, in order to catch some malformed
WKT.
      *
-     * <p>The following examples can be parsed by this constructor in addition of the
standard
+     * <p>The following examples can be parsed by this constructor in addition of the
usual
      * {@code BOX} element. This constructor creates the bounding box of those geometries:</p>
      *
      * <ul>
@@ -217,8 +217,8 @@ public class GeneralEnvelope extends Arr
      * @param  wkt The {@code BOX}, {@code POLYGON} or other kind of element to parse.
      * @throws IllegalArgumentException If the given string can not be parsed.
      *
-     * @see Envelopes#parseWKT(String)
-     * @see Envelopes#toWKT(Envelope)
+     * @see Envelopes#fromWKT(String)
+     * @see Envelopes#toString(Envelope)
      */
     public GeneralEnvelope(final CharSequence wkt) throws IllegalArgumentException {
         super(wkt);

Modified: sis/branches/JDK7/sis-referencing/src/main/java/org/apache/sis/geometry/ImmutableEnvelope.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/sis-referencing/src/main/java/org/apache/sis/geometry/ImmutableEnvelope.java?rev=1467795&r1=1467794&r2=1467795&view=diff
==============================================================================
--- sis/branches/JDK7/sis-referencing/src/main/java/org/apache/sis/geometry/ImmutableEnvelope.java
[UTF-8] (original)
+++ sis/branches/JDK7/sis-referencing/src/main/java/org/apache/sis/geometry/ImmutableEnvelope.java
[UTF-8] Sun Apr 14 15:51:15 2013
@@ -136,8 +136,8 @@ public final class ImmutableEnvelope ext
 
     /**
      * Constructs a new envelope initialized to the values parsed from the given string in
-     * <cite>Well Known Text</cite> (WKT) format. The given string is typically
a {@code BOX}
-     * element like below:
+     * {@code BOX} or <cite>Well Known Text</cite> (WKT) format. The given string
is typically
+     * a {@code BOX} element like below:
      *
      * {@preformat wkt
      *     BOX(-180 -90, 180 90)

Added: sis/branches/JDK7/sis-referencing/src/test/java/org/apache/sis/geometry/EnvelopesTest.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/sis-referencing/src/test/java/org/apache/sis/geometry/EnvelopesTest.java?rev=1467795&view=auto
==============================================================================
--- sis/branches/JDK7/sis-referencing/src/test/java/org/apache/sis/geometry/EnvelopesTest.java
(added)
+++ sis/branches/JDK7/sis-referencing/src/test/java/org/apache/sis/geometry/EnvelopesTest.java
[UTF-8] Sun Apr 14 15:51:15 2013
@@ -0,0 +1,77 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.sis.geometry;
+
+import org.opengis.geometry.Envelope;
+import org.opengis.util.FactoryException;
+import org.apache.sis.test.TestCase;
+import org.apache.sis.test.DependsOn;
+import org.junit.Test;
+
+import static org.apache.sis.test.Assert.*;
+import static org.opengis.test.Validators.validate;
+
+
+/**
+ * Tests the {@link Envelopes} class.
+ *
+ * @author  Martin Desruisseaux (IRD, Geomatys)
+ * @since   0.3
+ * @version 0.3
+ * @module
+ */
+@DependsOn(GeneralEnvelopeTest.class)
+public final strictfp class EnvelopesTest extends TestCase {
+    /**
+     * Tests {@link Envelopes#fromWKT(String)}. This test is provided as a matter of principle,
+     * but the real test is done by {@link GeneralEnvelopeTest#testWktParsing()}.
+     *
+     * @throws FactoryException Should never happen.
+     */
+    @Test
+    public void testFromWKT() throws FactoryException {
+        final Envelope envelope = Envelopes.fromWKT("BOX(-100 -80, 70 40)");
+        assertEquals(2, envelope.getDimension());
+        assertEquals(-100, envelope.getMinimum(0), 0);
+        assertEquals(  70, envelope.getMaximum(0), 0);
+        assertEquals( -80, envelope.getMinimum(1), 0);
+        assertEquals(  40, envelope.getMaximum(1), 0);
+        validate(envelope);
+    }
+
+    /**
+     * Tests {@link Envelopes#toString(Envelope)}.
+     */
+    @Test
+    public void testToString() {
+        final GeneralEnvelope envelope = new GeneralEnvelope(2);
+        envelope.setRange(0, 40, 50);
+        envelope.setRange(1, 20, 25);
+        assertEquals("BOX(40 20, 50 25)", Envelopes.toString(envelope));
+    }
+
+    /**
+     * Tests {@link Envelopes#toPolygonWKT(Envelope)}.
+     */
+    @Test
+    public void testToPolygonWKT() {
+        final GeneralEnvelope envelope = new GeneralEnvelope(2);
+        envelope.setRange(0, 40, 50);
+        envelope.setRange(1, 20, 25);
+        assertEquals("POLYGON((40 20, 40 25, 50 25, 50 20, 40 20))", Envelopes.toPolygonWKT(envelope));
+    }
+}

Propchange: sis/branches/JDK7/sis-referencing/src/test/java/org/apache/sis/geometry/EnvelopesTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: sis/branches/JDK7/sis-referencing/src/test/java/org/apache/sis/geometry/EnvelopesTest.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain;charset=UTF-8

Modified: sis/branches/JDK7/sis-referencing/src/test/java/org/apache/sis/geometry/GeneralEnvelopeTest.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/sis-referencing/src/test/java/org/apache/sis/geometry/GeneralEnvelopeTest.java?rev=1467795&r1=1467794&r2=1467795&view=diff
==============================================================================
--- sis/branches/JDK7/sis-referencing/src/test/java/org/apache/sis/geometry/GeneralEnvelopeTest.java
[UTF-8] (original)
+++ sis/branches/JDK7/sis-referencing/src/test/java/org/apache/sis/geometry/GeneralEnvelopeTest.java
[UTF-8] Sun Apr 14 15:51:15 2013
@@ -457,20 +457,20 @@ public final strictfp class GeneralEnvel
         assertEquals(  40, envelope.getUpper(1), STRICT);
         validate(envelope);
 
-        assertEquals("BOX2D(6 10, 6 10)",     new GeneralEnvelope("POINT(6 10)").toString());
+        assertEquals("BOX(6 10, 6 10)",     new GeneralEnvelope("POINT(6 10)").toString());
         assertEquals("BOX3D(6 10 3, 6 10 3)", new GeneralEnvelope("POINT M [ 6 10 3 ] ").toString());
-        assertEquals("BOX2D(3 4, 20 50)",     new GeneralEnvelope("LINESTRING(3 4,10 50,20
25)").toString());
-        assertEquals("BOX2D(1 1, 6 5)",       new GeneralEnvelope(
+        assertEquals("BOX(3 4, 20 50)",     new GeneralEnvelope("LINESTRING(3 4,10 50,20
25)").toString());
+        assertEquals("BOX(1 1, 6 5)",       new GeneralEnvelope(
                 "MULTIPOLYGON(((1 1,5 1,5 5,1 5,1 1),(2 2, 3 2, 3 3, 2 3,2 2)),((3 3,6 2,6
4,3 3)))").toString());
-        assertEquals("BOX2D(3 6, 7 10)", new GeneralEnvelope("GEOMETRYCOLLECTION(POINT(4
6),LINESTRING(3 8,7 10))").toString());
+        assertEquals("BOX(3 6, 7 10)", new GeneralEnvelope("GEOMETRYCOLLECTION(POINT(4 6),LINESTRING(3
8,7 10))").toString());
         assertEquals(0, new GeneralEnvelope("BOX()").getDimension());
 
         try {
-            new GeneralEnvelope("BOX2D(3 4");
+            new GeneralEnvelope("BOX(3 4");
             fail("Parsing should fails because of missing parenthesis.");
         } catch (IllegalArgumentException e) {
             // This is the expected exception.
-            assertTrue(e.getMessage().contains("BOX2D"));
+            assertTrue(e.getMessage().contains("BOX"));
         }
         try {
             new GeneralEnvelope("LINESTRING(3 4,10 50),20 25)");

Modified: sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/util/Static.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/util/Static.java?rev=1467795&r1=1467794&r2=1467795&view=diff
==============================================================================
--- sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/util/Static.java [UTF-8] (original)
+++ sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/util/Static.java [UTF-8] Sun
Apr 14 15:51:15 2013
@@ -51,6 +51,8 @@ package org.apache.sis.util;
  * <tr><th colspan="2" class="hsep">OGC/ISO objects (metadata, referencing, geometries)</th></tr>
  * <tr><td>{@link org.apache.sis.metadata.iso.extent.Extents}</td>
  *     <td>Extract information from {@link org.opengis.metadata.extent.Extent} objects.</td></tr>
+ * <tr><td>{@link org.apache.sis.geometry.Envelopes}</td>
+ *     <td>Parse, format and transform {@linkplain org.opengis.geometry.Envelope envelopes}.</td></tr>
  *
  * <tr><th colspan="2" class="hsep">Input / Output (including CRS, XML, images)</th></tr>
  * <tr><td>{@link org.apache.sis.io.IO}</td>

Modified: sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/util/resources/Errors.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/util/resources/Errors.java?rev=1467795&r1=1467794&r2=1467795&view=diff
==============================================================================
--- sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/util/resources/Errors.java
[UTF-8] (original)
+++ sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/util/resources/Errors.java
[UTF-8] Sun Apr 14 15:51:15 2013
@@ -139,6 +139,11 @@ public final class Errors extends Indexe
         public static final int EmptyDictionary = 54;
 
         /**
+         * Envelope must be at least two-dimensional and non-empty.
+         */
+        public static final int EmptyEnvelope2D = 88;
+
+        /**
          * Property named “{0}” shall not be empty.
          */
         public static final int EmptyProperty_1 = 55;

Modified: sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/util/resources/Errors.properties
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/util/resources/Errors.properties?rev=1467795&r1=1467794&r2=1467795&view=diff
==============================================================================
--- sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/util/resources/Errors.properties
[ISO-8859-1] (original)
+++ sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/util/resources/Errors.properties
[ISO-8859-1] Sun Apr 14 15:51:15 2013
@@ -39,6 +39,7 @@ DuplicatedValuesCount_1         = Found 
 ElementAlreadyPresent_1         = Element \u201c{0}\u201d is already present.
 EmptyArgument_1                 = Argument \u2018{0}\u2019 shall not be empty.
 EmptyDictionary                 = The dictionary shall contains at least one entry.
+EmptyEnvelope2D                 = Envelope must be at least two-dimensional and non-empty.
 EmptyProperty_1                 = Property named \u201c{0}\u201d shall not be empty.
 ExcessiveArgumentSize_3         = Argument \u2018{0}\u2019 shall not contain more than {1}
elements. A number of {2} is excessive.
 ForbiddenAttribute_2            = Attribute \u201c{0}\u201d is not allowed for an object
of type \u2018{1}\u2019.

Modified: sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/util/resources/Errors_fr.properties
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/util/resources/Errors_fr.properties?rev=1467795&r1=1467794&r2=1467795&view=diff
==============================================================================
--- sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/util/resources/Errors_fr.properties
[ISO-8859-1] (original)
+++ sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/util/resources/Errors_fr.properties
[ISO-8859-1] Sun Apr 14 15:51:15 2013
@@ -29,6 +29,7 @@ DuplicatedValuesCount_1         = {0} va
 ElementAlreadyPresent_1         = L\u2019\u00e9lement \u201c{0}\u201d est d\u00e9j\u00e0
pr\u00e9sent.
 EmptyArgument_1                 = L\u2019argument \u2018{0}\u2019 ne doit pas \u00eatre vide.
 EmptyDictionary                 = Le dictionnaire doit contenir au moins une entr\u00e9e.
+EmptyEnvelope2D                 = L\u2019enveloppe doit avoir au moins deux dimensions et
ne pas \u00eatre vide.
 EmptyProperty_1                 = La propri\u00e9t\u00e9 nomm\u00e9e \u201c{0}\u201d ne doit
pas \u00eatre vide.
 ExcessiveArgumentSize_3         = L\u2019argument \u2018{0}\u2019 ne peut pas contenir plus
de {1} \u00e9l\u00e9ments. Un nombre de {2} est excessif.
 ForbiddenAttribute_2            = L\u2019attribut \u201c{0}\u201d n\u2019est pas autoris\u00e9
pour un objet de type \u2018{1}\u2019.



Mime
View raw message