sis-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From desruisse...@apache.org
Subject svn commit: r1535054 - in /sis/branches/JDK7/core: sis-metadata/src/main/java/org/apache/sis/internal/metadata/ sis-metadata/src/main/java/org/apache/sis/metadata/iso/extent/ sis-metadata/src/test/java/org/apache/sis/metadata/iso/extent/ sis-metadata/s...
Date Wed, 23 Oct 2013 15:14:37 GMT
Author: desruisseaux
Date: Wed Oct 23 15:14:37 2013
New Revision: 1535054

URL: http://svn.apache.org/r1535054
Log:
Added a Extents.area(GeographicBoundingBox) for providing a surface estimation.

Added:
    sis/branches/JDK7/core/sis-metadata/src/test/java/org/apache/sis/metadata/iso/extent/
    sis/branches/JDK7/core/sis-metadata/src/test/java/org/apache/sis/metadata/iso/extent/ExtentsTest.java
  (with props)
Modified:
    sis/branches/JDK7/core/sis-metadata/src/main/java/org/apache/sis/internal/metadata/ReferencingServices.java
    sis/branches/JDK7/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/extent/Extents.java
    sis/branches/JDK7/core/sis-metadata/src/test/java/org/apache/sis/test/suite/MetadataTestSuite.java
    sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/internal/referencing/Formulas.java
    sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/GeodeticObjects.java
    sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/StandardDefinitions.java

Modified: sis/branches/JDK7/core/sis-metadata/src/main/java/org/apache/sis/internal/metadata/ReferencingServices.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-metadata/src/main/java/org/apache/sis/internal/metadata/ReferencingServices.java?rev=1535054&r1=1535053&r2=1535054&view=diff
==============================================================================
--- sis/branches/JDK7/core/sis-metadata/src/main/java/org/apache/sis/internal/metadata/ReferencingServices.java
[UTF-8] (original)
+++ sis/branches/JDK7/core/sis-metadata/src/main/java/org/apache/sis/internal/metadata/ReferencingServices.java
[UTF-8] Wed Oct 23 15:14:37 2013
@@ -40,6 +40,16 @@ import org.apache.sis.util.resources.Err
  */
 public abstract class ReferencingServices extends SystemListener {
     /**
+     * The length of one nautical mile, in metres.
+     */
+    public static final double NAUTICAL_MILE = 1852;
+
+    /**
+     * The GRS80 {@linkplain org.apache.sis.referencing.datum.DefaultEllipsoid#getAuthalicRadius()
authalic radius}.
+     */
+    public static final double AUTHALIC_RADIUS = 6371007;
+
+    /**
      * The services, fetched when first needed.
      */
     private static ReferencingServices instance;

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=1535054&r1=1535053&r2=1535054&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] Wed Oct 23 15:14:37 2013
@@ -23,7 +23,9 @@ import org.opengis.metadata.extent.Geogr
 import org.apache.sis.util.resources.Vocabulary;
 import org.apache.sis.util.Static;
 
+import static java.lang.Math.*;
 import static org.apache.sis.internal.metadata.MetadataUtilities.getInclusion;
+import static org.apache.sis.internal.metadata.ReferencingServices.AUTHALIC_RADIUS;
 
 
 /**
@@ -31,7 +33,7 @@ import static org.apache.sis.internal.me
  *
  * @author  Martin Desruisseaux (Geomatys)
  * @since   0.3 (derived from geotk-2.2)
- * @version 0.3
+ * @version 0.4
  * @module
  *
  * @see org.apache.sis.geometry.Envelopes
@@ -108,4 +110,29 @@ public final class Extents extends Stati
         }
         return candidate;
     }
+
+    /**
+     * Returns an <em>estimation</em> of the area (in square metres) of the given
bounding box.
+     * Since {@code GeographicBoundingBox} provides only approximative information (for example
+     * they do not specify the datum), the value returned by this method is also approximative.
+     *
+     * <p>The current implementation assumes the
+     * {@linkplain org.apache.sis.referencing.GeodeticObjects#SPHERE GRS 1980 Authalic Sphere}.
+     * However this may change in any future SIS version.</p>
+     *
+     * @param  box The geographic bounding box for which to compute the area, or {@code null}.
+     * @return An estimation of the geographic area in the given bounding box,
+     *         or {@link Double#NaN} if the given box was null.
+     *
+     * @since 0.4
+     */
+    public static double area(final GeographicBoundingBox box) {
+        if (box == null) {
+            return Double.NaN;
+        }
+        return max(0, sin(toRadians(box.getNorthBoundLatitude())) -
+                      sin(toRadians(box.getSouthBoundLatitude()))) *
+               max(0, toRadians(box.getEastBoundLongitude() - box.getWestBoundLongitude()))
*
+                (AUTHALIC_RADIUS * AUTHALIC_RADIUS);
+    }
 }

Added: sis/branches/JDK7/core/sis-metadata/src/test/java/org/apache/sis/metadata/iso/extent/ExtentsTest.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-metadata/src/test/java/org/apache/sis/metadata/iso/extent/ExtentsTest.java?rev=1535054&view=auto
==============================================================================
--- sis/branches/JDK7/core/sis-metadata/src/test/java/org/apache/sis/metadata/iso/extent/ExtentsTest.java
(added)
+++ sis/branches/JDK7/core/sis-metadata/src/test/java/org/apache/sis/metadata/iso/extent/ExtentsTest.java
[UTF-8] Wed Oct 23 15:14:37 2013
@@ -0,0 +1,62 @@
+/*
+ * 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.metadata.iso.extent;
+
+import org.opengis.metadata.extent.GeographicBoundingBox;
+import org.apache.sis.test.TestCase;
+import org.junit.Test;
+
+import static org.apache.sis.internal.metadata.ReferencingServices.NAUTICAL_MILE;
+import static org.junit.Assert.*;
+
+
+/**
+ * Tests {@link Extents}.
+ *
+ * @author  Martin Desruisseaux (Geomatys)
+ * @since   0.4
+ * @version 0.4
+ * @module
+ */
+public final strictfp class ExtentsTest extends TestCase {
+    /**
+     * One minute of angle, in degrees.
+     */
+    private static final double MINUTE = 1./60;
+
+    /**
+     * Tests {@link Extents#area(GeographicBoundingBox)}.
+     */
+    @Test
+    public void testGetArea() {
+        /*
+         * The nautical mile is equals to the length of 1 second of arc along meridians or
parallels at the equator.
+         * Since we are using the GRS80 authalic sphere instead than WGS84, we have a slight
empirical shift.
+         */
+        final DefaultGeographicBoundingBox box = new DefaultGeographicBoundingBox(10, 10+MINUTE,
2.9685, 2.9685+MINUTE);
+        assertEquals(NAUTICAL_MILE * NAUTICAL_MILE, Extents.area(box), 0.1);
+        /*
+         * Result should be much smaller near the poles.
+         */
+        box.setNorthBoundLatitude(90);
+        box.setSouthBoundLatitude(90-MINUTE);
+        assertEquals(499.5, Extents.area(box), 0.1);
+        box.setSouthBoundLatitude(-90);
+        box.setNorthBoundLatitude(-90+MINUTE);
+        assertEquals(499.5, Extents.area(box), 0.1);
+    }
+}

Propchange: sis/branches/JDK7/core/sis-metadata/src/test/java/org/apache/sis/metadata/iso/extent/ExtentsTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: sis/branches/JDK7/core/sis-metadata/src/test/java/org/apache/sis/metadata/iso/extent/ExtentsTest.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain;charset=UTF-8

Modified: sis/branches/JDK7/core/sis-metadata/src/test/java/org/apache/sis/test/suite/MetadataTestSuite.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-metadata/src/test/java/org/apache/sis/test/suite/MetadataTestSuite.java?rev=1535054&r1=1535053&r2=1535054&view=diff
==============================================================================
--- sis/branches/JDK7/core/sis-metadata/src/test/java/org/apache/sis/test/suite/MetadataTestSuite.java
[UTF-8] (original)
+++ sis/branches/JDK7/core/sis-metadata/src/test/java/org/apache/sis/test/suite/MetadataTestSuite.java
[UTF-8] Wed Oct 23 15:14:37 2013
@@ -40,6 +40,7 @@ import org.junit.BeforeClass;
     org.apache.sis.metadata.iso.spatial.DefaultGeorectifiedTest.class,
     org.apache.sis.metadata.iso.maintenance.DefaultScopeDescriptionTest.class,
     org.apache.sis.metadata.iso.quality.AbstractElementTest.class,
+    org.apache.sis.metadata.iso.extent.ExtentsTest.class,
 
     // Classes using Java reflection.
     org.apache.sis.metadata.PropertyInformationTest.class,

Modified: sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/internal/referencing/Formulas.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/internal/referencing/Formulas.java?rev=1535054&r1=1535053&r2=1535054&view=diff
==============================================================================
--- sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/internal/referencing/Formulas.java
[UTF-8] (original)
+++ sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/internal/referencing/Formulas.java
[UTF-8] Wed Oct 23 15:14:37 2013
@@ -21,6 +21,7 @@ import org.apache.sis.measure.Latitude;
 
 import static java.lang.Math.*;
 import static org.apache.sis.math.MathFunctions.atanh;
+import static org.apache.sis.internal.metadata.ReferencingServices.NAUTICAL_MILE;
 
 
 /**
@@ -52,7 +53,7 @@ public final class Formulas extends Stat
      * @see #LINEAR_TOLERANCE
      * @see org.apache.sis.internal.util.Numerics#COMPARISON_THRESHOLD
      */
-    public static final double ANGULAR_TOLERANCE = LINEAR_TOLERANCE / (1852 * 60);
+    public static final double ANGULAR_TOLERANCE = LINEAR_TOLERANCE / (NAUTICAL_MILE * 60);
 
     /**
      * Do not allow instantiation of this class.

Modified: sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/GeodeticObjects.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/GeodeticObjects.java?rev=1535054&r1=1535053&r2=1535054&view=diff
==============================================================================
--- sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/GeodeticObjects.java
[UTF-8] (original)
+++ sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/GeodeticObjects.java
[UTF-8] Wed Oct 23 15:14:37 2013
@@ -212,6 +212,8 @@ public enum GeodeticObjects {
      *   <tr><th>Semi-minor axis length:</th>  <td>6371007 <i>(definitive)</i></td></tr>
      *   <tr><th>Ellipsoid axes unit:</th>     <td>{@link SI#METRE}</td></tr>
      * </table></blockquote>
+     *
+     * @see org.apache.sis.referencing.datum.DefaultEllipsoid#getAuthalicRadius()
      */
     SPHERE((short) 7048);
 

Modified: sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/StandardDefinitions.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/StandardDefinitions.java?rev=1535054&r1=1535053&r2=1535054&view=diff
==============================================================================
--- sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/StandardDefinitions.java
[UTF-8] (original)
+++ sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/StandardDefinitions.java
[UTF-8] Wed Oct 23 15:14:37 2013
@@ -32,6 +32,7 @@ import org.apache.sis.referencing.datum.
 import static org.opengis.referencing.IdentifiedObject.NAME_KEY;
 import static org.opengis.referencing.IdentifiedObject.ALIAS_KEY;
 import static org.opengis.referencing.IdentifiedObject.IDENTIFIERS_KEY;
+import static org.apache.sis.internal.metadata.ReferencingServices.AUTHALIC_RADIUS;
 
 
 /**
@@ -85,7 +86,7 @@ final class StandardDefinitions {
             case 7019: alias = "International 1979";       name  = "GRS 1980";     semiMajorAxis
= 6378137.0; other = 298.257222101; break;
             case 7022: name  = "International 1924";       alias = "Hayford 1909"; semiMajorAxis
= 6378388.0; other = 297.0;         break;
             case 7008: name  = "Clarke 1866";              ivfDefinitive = false;  semiMajorAxis
= 6378206.4; other = 6356583.8;     break;
-            case 7048: name  = "GRS 1980 Authalic Sphere"; ivfDefinitive = false;  semiMajorAxis
=            other = 6371007;       break;
+            case 7048: name  = "GRS 1980 Authalic Sphere"; ivfDefinitive = false;  semiMajorAxis
= other = AUTHALIC_RADIUS;          break;
             default:   throw new AssertionError(code);
         }
         final Map<String,Object> map = new HashMap<>(8);



Mime
View raw message