sis-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From desruisse...@apache.org
Subject svn commit: r1785122 - in /sis/branches/JDK8/core: sis-metadata/src/main/java/org/apache/sis/internal/metadata/ sis-metadata/src/main/java/org/apache/sis/metadata/iso/extent/ sis-referencing-by-identifiers/src/main/java/org/apache/sis/referencing/gazet...
Date Thu, 02 Mar 2017 12:56:03 GMT
Author: desruisseaux
Date: Thu Mar  2 12:56:03 2017
New Revision: 1785122

URL: http://svn.apache.org/viewvc?rev=1785122&view=rev
Log:
Add AbstractLocation class.

Added:
    sis/branches/JDK8/core/sis-referencing-by-identifiers/src/main/java/org/apache/sis/referencing/gazetteer/AbstractLocation.java
  (with props)
Modified:
    sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/internal/metadata/ReferencingServices.java
    sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/extent/Extents.java
    sis/branches/JDK8/core/sis-referencing-by-identifiers/src/main/java/org/apache/sis/referencing/gazetteer/ModifiableLocationType.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/src/main/java/org/apache/sis/internal/referencing/ServicesForMetadata.java

Modified: sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/internal/metadata/ReferencingServices.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/internal/metadata/ReferencingServices.java?rev=1785122&r1=1785121&r2=1785122&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/internal/metadata/ReferencingServices.java
[UTF-8] (original)
+++ sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/internal/metadata/ReferencingServices.java
[UTF-8] Thu Mar  2 12:56:03 2017
@@ -22,6 +22,7 @@ import java.util.Locale;
 import javax.measure.Unit;
 import javax.measure.quantity.Length;
 import org.opengis.geometry.Envelope;
+import org.opengis.geometry.DirectPosition;
 import org.opengis.metadata.Identifier;
 import org.opengis.parameter.ParameterDescriptor;
 import org.opengis.referencing.IdentifiedObject;
@@ -70,7 +71,7 @@ import org.apache.sis.util.Deprecable;
  *
  * @author  Martin Desruisseaux (Geomatys)
  * @since   0.3
- * @version 0.7
+ * @version 0.8
  * @module
  */
 public class ReferencingServices extends OptionalDependency {
@@ -275,6 +276,20 @@ public class ReferencingServices extends
         throw moduleNotFound();
     }
 
+    /**
+     * Creates a two-dimensional geographic position associated to the default geographic
CRS.
+     * Axis order is (longitude, latitude).
+     *
+     * @param  λ  the longitude value.
+     * @param  φ  the latitude value.
+     * @return the direct position for the given geographic coordinate.
+     *
+     * @since 0.8
+     */
+    public DirectPosition geographic(final double λ, final double φ) {
+        throw moduleNotFound();
+    }
+
 
 
 

Modified: sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/extent/Extents.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/extent/Extents.java?rev=1785122&r1=1785121&r2=1785122&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/extent/Extents.java
[UTF-8] (original)
+++ sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/extent/Extents.java
[UTF-8] Thu Mar  2 12:56:03 2017
@@ -21,6 +21,7 @@ import java.util.List;
 import java.util.ArrayList;
 import javax.measure.Unit;
 import org.opengis.geometry.Envelope;
+import org.opengis.geometry.DirectPosition;
 import org.opengis.temporal.TemporalPrimitive;
 import org.opengis.metadata.extent.Extent;
 import org.opengis.metadata.extent.VerticalExtent;
@@ -36,6 +37,7 @@ import org.opengis.referencing.crs.Coord
 import org.opengis.referencing.datum.VerticalDatum;
 import org.opengis.referencing.datum.VerticalDatumType;
 import org.opengis.referencing.operation.TransformException;
+import org.apache.sis.internal.metadata.ReferencingServices;
 import org.apache.sis.metadata.InvalidMetadataException;
 import org.apache.sis.measure.Longitude;
 import org.apache.sis.measure.MeasurementRange;
@@ -409,6 +411,30 @@ public final class Extents extends Stati
     }
 
     /**
+     * Returns the position at the median longitude and latitude values of the given bounding
box.
+     * This method does not check the {@linkplain DefaultGeographicBoundingBox#getInclusion()
inclusion} status.
+     * This method takes in account bounding boxes that cross the anti-meridian.
+     *
+     * @param  bbox  the bounding box for which to get the median longitude and latitude
values, or {@code null}.
+     * @return a median position of the given bounding box, or {@code null} if none.
+     */
+    public static DirectPosition centroid(final GeographicBoundingBox bbox) {
+        if (bbox != null) {
+            double y    = (bbox.getNorthBoundLatitude() + bbox.getSouthBoundLatitude()) /
2;
+            double x    =  bbox.getWestBoundLongitude();
+            double xmax =  bbox.getEastBoundLongitude();
+            if (xmax < x) {
+                xmax += (Longitude.MAX_VALUE - Longitude.MIN_VALUE);
+            }
+            x = Longitude.normalize((x + xmax) / 2);
+            if (Double.isFinite(x) || Double.isFinite(y)) {
+                return ReferencingServices.getInstance().geographic(x, y);
+            }
+        }
+        return null;
+    }
+
+    /**
      * Returns the intersection of the given geographic bounding boxes. If any of the arguments
is {@code null},
      * then this method returns the other argument (which may be null). Otherwise this method
returns a box which
      * is the intersection of the two given boxes.

Added: 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=1785122&view=auto
==============================================================================
--- sis/branches/JDK8/core/sis-referencing-by-identifiers/src/main/java/org/apache/sis/referencing/gazetteer/AbstractLocation.java
(added)
+++ sis/branches/JDK8/core/sis-referencing-by-identifiers/src/main/java/org/apache/sis/referencing/gazetteer/AbstractLocation.java
[UTF-8] Thu Mar  2 12:56:03 2017
@@ -0,0 +1,201 @@
+/*
+ * 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.referencing.gazetteer;
+
+import java.util.Collection;
+import java.util.Collections;
+import org.opengis.metadata.citation.Party;
+import org.opengis.metadata.extent.TemporalExtent;
+import org.opengis.metadata.extent.GeographicExtent;
+import org.opengis.metadata.extent.GeographicBoundingBox;
+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.metadata.iso.extent.Extents;
+
+
+/**
+ * Identifiable geographic place. A geographic place may be identified by a name (for example
“Eiffel Tower”),
+ * by a postcode, or any other method specified by the {@linkplain ModifiableLocationType#getIdentifications()
+ * location type identifications}.
+ *
+ * <p>ISO 19112 describes the following properties as mandatory, but Apache SIS relaxes
this restriction by
+ * providing default values (possibly {@code null}) in most cases:</p>
+ * <ul>
+ *   <li><b>geographic identifier</b> (the value, for example a name or
code)</li>
+ *   <li><b>geographic extent</b> (the position of the identified thing)</li>
+ *   <li><b>administrator</b> (who is responsible for this identifier)</li>
+ *   <li><b>location type</b> (which specifies the nature of the identifier
and its associated geographic location)</li>
+ * </ul>
+ *
+ * The following properties are optional:
+ * <ul>
+ *   <li><b>temporal extent</b></li>
+ *   <li><b>alternative geographic identifier</b></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>
+ * </ul>
+ *
+ * @author  Martin Desruisseaux (Geomatys)
+ * @since   0.8
+ * @version 0.8
+ * @module
+ */
+public abstract class AbstractLocation implements Location {
+    /**
+     * The geographic identifier, or {@code null} if unspecified.
+     *
+     * @see #getGeographicIdentifier()
+     */
+    private final CharSequence identifier;
+
+    /**
+     * Creates a new location for the given geographic identifier.
+     * This constructor accepts a {@code null} argument, but this is not recommended.
+     *
+     * @param identifier  the geographic identifier to be returned by {@link #getGeographicIdentifier()}.
+     */
+    protected AbstractLocation(final CharSequence identifier) {
+        this.identifier = identifier;
+    }
+
+    /**
+     * Returns a unique identifier for the location instance. The methods of identifying
locations is specified
+     * by the {@linkplain ModifiableLocationType#getIdentifications() location type identifications}.
+     *
+     * <div class="note"><b>Examples:</b>
+     * if {@link LocationType#getIdentifications()} contain “name”, then geographic identifiers
may be country
+     * names like “Japan” or “France”, or places like “Eiffel Tower”. If location
type identifications contain
+     * “code”, then geographic identifiers may be “SW1P 3AD” postcode.
+     * </div>
+     *
+     * In order to ensure that a geographic identifier is unique within a wider geographic
domain,
+     * the geographic identifier may need to include an identifier of an instance of a parent
location type,
+     * for example “Paris, Texas”.
+     *
+     * @return unique identifier for the location instance.
+     *
+     * @see ModifiableLocationType#getIdentifications()
+     */
+    @Override
+    public InternationalString getGeographicIdentifier() {
+        return Types.toInternationalString(identifier);
+    }
+
+    /**
+     * Returns other identifier(s) for the location instance.
+     * The default implementation returns an empty set.
+     *
+     * @return other identifier(s) for the location instance, or an empty collection if none.
+     */
+    @Override
+    public Collection<? extends InternationalString> getAlternativeGeographicIdentifiers()
{
+        return Collections.emptySet();
+    }
+
+    /**
+     * Returns the date of creation of this version of the location instance.
+     * The default implementation returns {@code null}.
+     *
+     * @return date of creation of this version of the location instance, or {@code null}
if none.
+     */
+    @Override
+    public TemporalExtent getTemporalExtent() {
+        return null;
+    }
+
+    /**
+     * Returns a description of the location instance. This properties is mandatory according
ISO 19112,
+     * but Apache SIS nevertheless allows {@code null} value. If non-null, SIS implementations
typically
+     * provide instances of {@linkplain org.apache.sis.metadata.iso.extent.DefaultGeographicBoundingBox
+     * geographic bounding boxes}.
+     *
+     * @return description of the location instance, or {@code null} if none.
+     *
+     * @see org.apache.sis.metadata.iso.extent.DefaultGeographicBoundingBox
+     * @see org.apache.sis.metadata.iso.extent.DefaultBoundingPolygon
+     */
+    @Override
+    public GeographicExtent getGeographicExtent() {
+        return 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.
+     *
+     * @return coordinates of a representative point for the location instance, or {@code
null} if none.
+     */
+    @Override
+    public Position getPosition() {
+        final GeographicExtent extent = getGeographicExtent();
+        return (extent instanceof GeographicBoundingBox) ? Extents.centroid((GeographicBoundingBox)
extent) : null;
+    }
+
+    /**
+     * Returns a description of the nature of this geographic identifier.
+     *
+     * @return the nature of the identifier and its associated geographic location.
+     */
+    @Override
+    public abstract LocationType getLocationType();
+
+    /**
+     * Returns the organization responsible for defining the characteristics of the location
instance.
+     * The default implementation returns the {@linkplain ModifiableLocationType#getOwner()
owner}.
+     *
+     * @return organization responsible for defining the characteristics of the location
instance, or {@code null}.
+     *
+     * @see ModifiableLocationType#getOwner()
+     * @see ReferencingByIdentifiers#getOverallOwner()
+     */
+    @Override
+    public Party getAdministrator() {
+        final LocationType type = getLocationType();
+        return (type != null) ? type.getOwner() : null;
+    }
+
+    /**
+     * Returns location instances of a different location type, for which this location instance
is a sub-division.
+     * The default implementation returns an empty list.
+     *
+     * @return parent locations, or an empty collection if none.
+     *
+     * @see ModifiableLocationType#getParents()
+     */
+    @Override
+    public Collection<? extends Location> getParents() {
+        return Collections.emptyList();
+    }
+
+    /**
+     * Returns location instances of a different location type which subdivides this location
instance.
+     * The default implementation returns an empty list.
+     *
+     * @return child locations, or an empty collection if none.
+     *
+     * @see ModifiableLocationType#getChildren()
+     */
+    @Override
+    public Collection<? extends Location> getChildren() {
+        return Collections.emptyList();
+    }
+}

Propchange: sis/branches/JDK8/core/sis-referencing-by-identifiers/src/main/java/org/apache/sis/referencing/gazetteer/AbstractLocation.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: sis/branches/JDK8/core/sis-referencing-by-identifiers/src/main/java/org/apache/sis/referencing/gazetteer/AbstractLocation.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain;charset=UTF-8

Modified: sis/branches/JDK8/core/sis-referencing-by-identifiers/src/main/java/org/apache/sis/referencing/gazetteer/ModifiableLocationType.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-referencing-by-identifiers/src/main/java/org/apache/sis/referencing/gazetteer/ModifiableLocationType.java?rev=1785122&r1=1785121&r2=1785122&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-referencing-by-identifiers/src/main/java/org/apache/sis/referencing/gazetteer/ModifiableLocationType.java
[UTF-8] (original)
+++ sis/branches/JDK8/core/sis-referencing-by-identifiers/src/main/java/org/apache/sis/referencing/gazetteer/ModifiableLocationType.java
[UTF-8] Thu Mar  2 12:56:03 2017
@@ -205,6 +205,8 @@ public class ModifiableLocationType exte
      *
      * @return property used as the defining characteristic of the location type,
      *         or {@code null} if no value has been defined or can be inherited.
+     *
+     * @see ReferencingByIdentifiers#getTheme()
      */
     @Override
     public InternationalString getTheme() {
@@ -232,11 +234,19 @@ public class ModifiableLocationType exte
      * If no methods have been explicitely set, then this method inherits the values from
      * the parents providing that all parents specify the same methods.
      *
-     * <p>The collection returned by this method is unmodifiable. For adding or removing
an identification,
-     * use {@link #addIdentification(CharSequence)} or {@link #removeIdentification(CharSequence)}.</p>
+     * <div class="note"><b>Examples:</b>
+     * some identification methods are “name”, “code”, “unique street reference
number” and “geographic address”.
+     * A location using “name” identifications may have the “Spain” {@linkplain AbstractLocation#getGeographicIdentifier()
+     * geographic identifier}, and a location using “postcode” identifications may have
the “SW1P 3AD” geographic identifier.
+     * </div>
+     *
+     * The collection returned by this method is unmodifiable. For adding or removing an
identification,
+     * use {@link #addIdentification(CharSequence)} or {@link #removeIdentification(CharSequence)}.
      *
      * @return method(s) of uniquely identifying location instances,
      *         or an empty list if no value has been defined or can be inherited.
+     *
+     * @see AbstractLocation#getGeographicIdentifier()
      */
     @Override
     public Collection<InternationalString> getIdentifications() {
@@ -304,6 +314,8 @@ public class ModifiableLocationType exte
      *
      * @return geographic area within which the location type occurs,
      *         or {@code null} if no value has been defined or can be inherited.
+     *
+     * @see ReferencingByIdentifiers#getDomainOfValidity()
      */
     @Override
     public GeographicExtent getTerritoryOfUse() {
@@ -340,6 +352,9 @@ public class ModifiableLocationType exte
      *
      * @return organization or class of organization able to create and destroy location
instances,
      *         or {@code null} if no value has been defined or can be inherited.
+     *
+     * @see AbstractLocation#getAdministrator()
+     * @see ReferencingByIdentifiers#getOverallOwner()
      */
     @Override
     public Party getOwner() {
@@ -375,6 +390,8 @@ public class ModifiableLocationType exte
      * use {@link #addParent(ModifiableLocationType)} or {@link #removeParent(ModifiableLocationType)}.</p>
      *
      * @return parent location types, or an empty collection if none.
+     *
+     * @see AbstractLocation#getParents()
      */
     @Override
     public final Collection<ModifiableLocationType> getParents() {
@@ -388,6 +405,8 @@ public class ModifiableLocationType exte
      * or  <code>child.{@linkplain #removeParent removeParent}(this)</code>.
      *
      * @return child location types, or an empty collection if none.
+     *
+     * @see AbstractLocation#getChildren()
      */
     @Override
     public final Collection<ModifiableLocationType> getChildren() {
@@ -455,6 +474,8 @@ public class ModifiableLocationType exte
      * given to the {@link ReferencingByIdentifiers} constructor for example.
      *
      * @return {@code null}.
+     *
+     * @see ReferencingByIdentifiers#getLocationTypes()
      */
     @Override
     public ReferenceSystemUsingIdentifiers getReferenceSystem() {

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=1785122&r1=1785121&r2=1785122&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 12:56:03 2017
@@ -177,6 +177,8 @@ public class ReferencingByIdentifiers ex
      * Property used to characterize the spatial reference system.
      *
      * @return property used to characterize the spatial reference system.
+     *
+     * @see AbstractLocationType#getTheme()
      */
     @Override
     public InternationalString getTheme() {
@@ -187,6 +189,9 @@ public class ReferencingByIdentifiers ex
      * Authority with overall responsibility for the spatial reference system.
      *
      * @return authority with overall responsibility for the spatial reference system.
+     *
+     * @see ModifiableLocationType#getOwner()
+     * @see AbstractLocation#getAdministrator()
      */
     @Override
     public Party getOverallOwner() {
@@ -198,6 +203,8 @@ public class ReferencingByIdentifiers ex
      * The collection returned by this method is unmodifiable.
      *
      * @return description of location type(s) in the spatial reference system.
+     *
+     * @see ModifiableLocationType#getReferenceSystem()
      */
     @Override
     @SuppressWarnings("ReturnOfCollectionOrArrayField")         // Because the collection
is unmodifiable.

Modified: sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/internal/referencing/ServicesForMetadata.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/internal/referencing/ServicesForMetadata.java?rev=1785122&r1=1785121&r2=1785122&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/internal/referencing/ServicesForMetadata.java
[UTF-8] (original)
+++ sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/internal/referencing/ServicesForMetadata.java
[UTF-8] Thu Mar  2 12:56:03 2017
@@ -57,9 +57,11 @@ import org.opengis.metadata.citation.Onl
 import org.opengis.metadata.extent.GeographicBoundingBox;
 import org.opengis.metadata.extent.GeographicExtent;
 import org.opengis.metadata.extent.VerticalExtent;
+import org.opengis.geometry.DirectPosition;
 import org.opengis.geometry.Envelope;
 
 import org.apache.sis.geometry.Envelopes;
+import org.apache.sis.geometry.DirectPosition2D;
 import org.apache.sis.referencing.CRS;
 import org.apache.sis.referencing.CommonCRS;
 import org.apache.sis.referencing.IdentifiedObjects;
@@ -98,7 +100,7 @@ import org.apache.sis.util.Utilities;
  *
  * @author  Martin Desruisseaux (Geomatys)
  * @since   0.5
- * @version 0.7
+ * @version 0.8
  * @module
  */
 public final class ServicesForMetadata extends ReferencingServices {
@@ -390,6 +392,21 @@ public final class ServicesForMetadata e
         }
     }
 
+    /**
+     * Creates a two-dimensional geographic position associated to the default geographic
CRS.
+     * Axis order is (longitude, latitude).
+     *
+     * @param  λ  the longitude value.
+     * @param  φ  the latitude value.
+     * @return the direct position for the given geographic coordinate.
+     *
+     * @since 0.8
+     */
+    @Override
+    public DirectPosition geographic(final double λ, final double φ) {
+        return new DirectPosition2D(CommonCRS.defaultGeographic(), λ, φ);
+    }
+
 
 
 



Mime
View raw message