sis-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From desruisse...@apache.org
Subject svn commit: r1785180 - in /sis/branches/JDK8/core/sis-referencing-by-identifiers/src/main/java/org/apache/sis/referencing/gazetteer: AbstractLocation.java MilitaryGridReferenceSystem.java ReferencingByIdentifiers.java package-info.java
Date Thu, 02 Mar 2017 18:12:22 GMT
Author: desruisseaux
Date: Thu Mar  2 18:12:22 2017
New Revision: 1785180

URL: http://svn.apache.org/viewvc?rev=1785180&view=rev
Log:
Begin the transformation of "Encoder" inner class as a Location implementation.

Modified:
    sis/branches/JDK8/core/sis-referencing-by-identifiers/src/main/java/org/apache/sis/referencing/gazetteer/AbstractLocation.java
    sis/branches/JDK8/core/sis-referencing-by-identifiers/src/main/java/org/apache/sis/referencing/gazetteer/MilitaryGridReferenceSystem.java
    sis/branches/JDK8/core/sis-referencing-by-identifiers/src/main/java/org/apache/sis/referencing/gazetteer/ReferencingByIdentifiers.java
    sis/branches/JDK8/core/sis-referencing-by-identifiers/src/main/java/org/apache/sis/referencing/gazetteer/package-info.java

Modified: sis/branches/JDK8/core/sis-referencing-by-identifiers/src/main/java/org/apache/sis/referencing/gazetteer/AbstractLocation.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-referencing-by-identifiers/src/main/java/org/apache/sis/referencing/gazetteer/AbstractLocation.java?rev=1785180&r1=1785179&r2=1785180&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-referencing-by-identifiers/src/main/java/org/apache/sis/referencing/gazetteer/AbstractLocation.java
[UTF-8] (original)
+++ sis/branches/JDK8/core/sis-referencing-by-identifiers/src/main/java/org/apache/sis/referencing/gazetteer/AbstractLocation.java
[UTF-8] Thu Mar  2 18:12:22 2017
@@ -22,11 +22,13 @@ import org.opengis.metadata.citation.Par
 import org.opengis.metadata.extent.TemporalExtent;
 import org.opengis.metadata.extent.GeographicExtent;
 import org.opengis.metadata.extent.GeographicBoundingBox;
+import org.opengis.geometry.Envelope;
 import org.opengis.geometry.coordinate.Position;
 import org.opengis.referencing.gazetteer.Location;
 import org.opengis.referencing.gazetteer.LocationType;
 import org.opengis.util.InternationalString;
 import org.apache.sis.util.iso.Types;
+import org.apache.sis.geometry.Envelope2D;
 import org.apache.sis.metadata.iso.extent.Extents;
 
 
@@ -48,6 +50,7 @@ import org.apache.sis.metadata.iso.exten
  * <ul>
  *   <li><b>temporal extent</b></li>
  *   <li><b>alternative geographic identifier</b></li>
+ *   <li><b>envelope</b> (an Apache SIS extension not in ISO 19112 standard)</li>
  *   <li><b>position</b> (mandatory if the geographic identifier contains
insufficient information to identify location)</li>
  *   <li><b>parent location instance</b></li>
  *   <li><b>child location instance</b></li>
@@ -60,6 +63,13 @@ import org.apache.sis.metadata.iso.exten
  */
 public abstract class AbstractLocation implements Location {
     /**
+     * The description of the nature of this geographic identifier, or {@code null} if unspecified.
+     *
+     * @see #getLocationType()
+     */
+    private final LocationType type;
+
+    /**
      * The geographic identifier, or {@code null} if unspecified.
      *
      * @see #getGeographicIdentifier()
@@ -70,9 +80,11 @@ public abstract class AbstractLocation i
      * Creates a new location for the given geographic identifier.
      * This constructor accepts a {@code null} argument, but this is not recommended.
      *
+     * @param type        the description of the nature of this geographic identifier.
      * @param identifier  the geographic identifier to be returned by {@link #getGeographicIdentifier()}.
      */
-    protected AbstractLocation(final CharSequence identifier) {
+    protected AbstractLocation(final LocationType type, final CharSequence identifier) {
+        this.type       = type;
         this.identifier = identifier;
     }
 
@@ -138,9 +150,26 @@ public abstract class AbstractLocation i
     }
 
     /**
+     * Returns an envelope that encompass the location. This property is partially redundant
with
+     * {@link #getGeographicExtent()}, except that this method allows envelopes in non-geographic
CRS.
+     *
+     * <p>The default implementation copies the {@link #getGeographicExtent()} in a
new envelope associated
+     * to the {@linkplain org.apache.sis.referencing.CommonCRS#defaultGeographic() default
geographic CRS}.</p>
+     *
+     * @return envelope that encompass the location, or {@code null} if none.
+     */
+    public Envelope getEnvelope() {
+        final GeographicExtent extent = getGeographicExtent();
+        return (extent instanceof GeographicBoundingBox) ? new Envelope2D((GeographicBoundingBox)
extent) : null;
+    }
+
+    /**
      * Returns coordinates of a representative point for the location instance.
-     * The default implementation returns the centroid of the {@linkplain #getGeographicExtent()
geographic extent}
-     * if that extent is geographic bounding box.
+     * This is often the centroid of the location instance, but not necessarily;
+     * another typical value is the lower-left corner.
+     *
+     * <p>The default implementation returns the centroid of the {@linkplain #getGeographicExtent()
+     * geographic extent} if that extent is geographic bounding box.</p>
      *
      * @return coordinates of a representative point for the location instance, or {@code
null} if none.
      */
@@ -156,7 +185,9 @@ public abstract class AbstractLocation i
      * @return the nature of the identifier and its associated geographic location.
      */
     @Override
-    public abstract LocationType getLocationType();
+    public LocationType getLocationType() {
+        return type;
+    }
 
     /**
      * Returns the organization responsible for defining the characteristics of the location
instance.

Modified: sis/branches/JDK8/core/sis-referencing-by-identifiers/src/main/java/org/apache/sis/referencing/gazetteer/MilitaryGridReferenceSystem.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-referencing-by-identifiers/src/main/java/org/apache/sis/referencing/gazetteer/MilitaryGridReferenceSystem.java?rev=1785180&r1=1785179&r2=1785180&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-referencing-by-identifiers/src/main/java/org/apache/sis/referencing/gazetteer/MilitaryGridReferenceSystem.java
[UTF-8] (original)
+++ sis/branches/JDK8/core/sis-referencing-by-identifiers/src/main/java/org/apache/sis/referencing/gazetteer/MilitaryGridReferenceSystem.java
[UTF-8] Thu Mar  2 18:12:22 2017
@@ -53,6 +53,7 @@ import org.apache.sis.util.resources.Voc
 import org.apache.sis.geometry.DirectPosition2D;
 import org.apache.sis.internal.system.Modules;
 import org.apache.sis.measure.Latitude;
+import org.opengis.geometry.coordinate.Position;
 
 // Branch-dependent imports
 import org.opengis.metadata.citation.Party;
@@ -239,6 +240,13 @@ public class MilitaryGridReferenceSystem
     }
 
     /**
+     * Returns the first location types, which should be the grid zone identifier.
+     */
+    final LocationType rootType() {
+        return super.getLocationTypes().get(0);     // Use super.… for protecting from
method overriding.
+    }
+
+    /**
      * Returns the value to add to the row number in order to have the "A" letter on the
southernmost or
      * northernmost value on Greenwich meridian of the Universal Polar Stereographic (UPS)
projection.
      * If {@code south} is {@code true}, then this is computed from the northernmost value
of UPS South;
@@ -341,6 +349,13 @@ public class MilitaryGridReferenceSystem
         }
 
         /**
+         * Returns the reference system for which MGRS references will be encoded or decoded.
+         */
+        final MilitaryGridReferenceSystem getReferenceSystem() {
+            return MilitaryGridReferenceSystem.this;
+        }
+
+        /**
          * Returns the precision of the references formatted by this coder.
          * This method returns one of the following values:
          *
@@ -421,14 +436,6 @@ public class MilitaryGridReferenceSystem
         }
 
         /**
-         * Bridge to {@link MilitaryGridReferenceSystem#polarOffset(boolean)}
-         * for the {@link Encoder} and {@link Decoder} classes.
-         */
-        final int polarOffset(final boolean south) throws TransformException {
-            return MilitaryGridReferenceSystem.this.polarOffset(south);
-        }
-
-        /**
          * Returns the encoder for the given coordinate reference system.
          *
          * @throws IllegalArgumentException if the given CRS do not use one of the supported
datums.
@@ -747,7 +754,7 @@ public class MilitaryGridReferenceSystem
                         throw new GazetteerException(Errors.format(Errors.Keys.OutsideDomainOfValidity));
                     }
                     col  = columns[col];
-                    row -= owner.polarOffset(signedZone < 0);
+                    row -= owner.getReferenceSystem().polarOffset(signedZone < 0);
                 }
                 row += 'A';
                 if (row >= EXCLUDE_I && ++row >= EXCLUDE_O) row++;
@@ -796,14 +803,15 @@ public class MilitaryGridReferenceSystem
 
 
     /**
-     * The result of decoding a MGRS reference.
+     * The result of decoding a MGRS reference. The {@linkplain #getPosition() position}
+     * represents the lower-left corner (not the centroid) of the decoded MGRS reference.
      *
      * @author  Martin Desruisseaux (Geomatys)
      * @since   0.8
      * @version 0.8
      * @module
      */
-    static final class Decoder {
+    static final class Decoder extends AbstractLocation {
         /**
          * Number of bits reserved for storing the minimal northing value of latitude bands
in the
          * {@link #ROW_RESOLVER} table.
@@ -879,6 +887,8 @@ public class MilitaryGridReferenceSystem
          * The position decoded from the MGRS reference given to the constructor.
          * This is the lower-left corner of a cell of size {@link #sx} × {@link #sy}
          * The CRS of that position will be a UTM or UPS projected CRS.
+         *
+         * @see #getPosition()
          */
         private final DirectPosition2D position;
 
@@ -894,6 +904,7 @@ public class MilitaryGridReferenceSystem
          * @param owner  the {@code Coder} which is creating this {@code Decoder}.
          */
         Decoder(final Coder owner, final CharSequence reference) throws TransformException
{
+            super(owner.getReferenceSystem().rootType(), reference);
             final int zone;                     // UTM zone, or 0 if UPS.
             final ProjectedCRS crs;             // UTM or UPS projection for the zone.
             boolean hasSquareIdentification;    // Whether a square identification is present
(UTM only).
@@ -944,7 +955,7 @@ parse:                  switch (part) {
                             case 2: {
                                 if (c >= EXCLUDE_O) c--;
                                 if (c >= EXCLUDE_I) c--;
-                                row = (c - 'A') + owner.polarOffset(south);
+                                row = (c - 'A') + owner.getReferenceSystem().polarOffset(south);
                                 i = ni;
                                 continue;
                             }
@@ -1296,5 +1307,13 @@ parse:                  switch (part) {
             return φ < TransverseMercator.Zoner.SVALBARD_BOUNDS ? φ + LATITUDE_BAND_HEIGHT
                      : TransverseMercator.Zoner.NORTH_BOUNDS;
         }
+
+        /**
+         * Returns the lower-left corner of the decoded MGRS cell.
+         */
+        @Override
+        public Position getPosition() {
+            return position;
+        }
     }
 }

Modified: sis/branches/JDK8/core/sis-referencing-by-identifiers/src/main/java/org/apache/sis/referencing/gazetteer/ReferencingByIdentifiers.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-referencing-by-identifiers/src/main/java/org/apache/sis/referencing/gazetteer/ReferencingByIdentifiers.java?rev=1785180&r1=1785179&r2=1785180&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-referencing-by-identifiers/src/main/java/org/apache/sis/referencing/gazetteer/ReferencingByIdentifiers.java
[UTF-8] (original)
+++ sis/branches/JDK8/core/sis-referencing-by-identifiers/src/main/java/org/apache/sis/referencing/gazetteer/ReferencingByIdentifiers.java
[UTF-8] Thu Mar  2 18:12:22 2017
@@ -17,7 +17,7 @@
 package org.apache.sis.referencing.gazetteer;
 
 import java.util.Map;
-import java.util.Collection;
+import java.util.List;
 import java.util.Objects;
 import javax.xml.bind.annotation.XmlTransient;
 import org.opengis.util.InternationalString;
@@ -82,7 +82,7 @@ public class ReferencingByIdentifiers ex
      *
      * @see #getLocationTypes()
      */
-    private final Collection<LocationType> locationTypes;
+    private final List<LocationType> locationTypes;
 
     /**
      * Creates a reference system from the given properties.
@@ -208,7 +208,7 @@ public class ReferencingByIdentifiers ex
      */
     @Override
     @SuppressWarnings("ReturnOfCollectionOrArrayField")         // Because the collection
is unmodifiable.
-    public Collection<LocationType> getLocationTypes() {
+    public List<LocationType> getLocationTypes() {
         return locationTypes;
     }
 

Modified: sis/branches/JDK8/core/sis-referencing-by-identifiers/src/main/java/org/apache/sis/referencing/gazetteer/package-info.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-referencing-by-identifiers/src/main/java/org/apache/sis/referencing/gazetteer/package-info.java?rev=1785180&r1=1785179&r2=1785180&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-referencing-by-identifiers/src/main/java/org/apache/sis/referencing/gazetteer/package-info.java
[UTF-8] (original)
+++ sis/branches/JDK8/core/sis-referencing-by-identifiers/src/main/java/org/apache/sis/referencing/gazetteer/package-info.java
[UTF-8] Thu Mar  2 18:12:22 2017
@@ -23,6 +23,14 @@
  * Gazetteers provide linking mechanism between referencing using geographic identifiers
(this package)
  * and referencing using coordinates (…{@link org.apache.sis.referencing.crs .crs} package).
  *
+ * <div class="section">Extensions to ISO 19112</div>
+ * In addition to standard properties, the Apache SIS implementation provides the following
extensions:
+ *
+ * <ul>
+ *   <li>{@link org.apache.sis.referencing.gazetteer.AbstractLocation#getEnvelope()}
can provide envelopes
+ *       in non-geographic CRS.</li>
+ * </ul>
+ *
  * @author  Chris Mattmann (JPL)
  * @author  Martin Desruisseaux (Geomatys)
  * @since   0.8



Mime
View raw message