Class Extents

java.lang.Object
org.apache.sis.util.Static
org.apache.sis.metadata.iso.extent.Extents

public final class Extents extends Static
Convenience static methods for extracting information from Extent or Metadata objects. This class provides methods for:
Since:
0.3
Version:
1.3
See Also:
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    private org.opengis.metadata.extent.GeographicBoundingBox
    The bounding box computed by this class.
    If more than one GeographicBoundingBox is found, a new instance used for computing the union of all bounding boxes.
    static final org.opengis.metadata.extent.Extent
    A geographic extent ranging from 180°W to 180°E and 90°S to 90°N.
  • Constructor Summary

    Constructors
    Modifier
    Constructor
    Description
    private
    Do no allow instantiation of this class, except for internal purposes.
  • Method Summary

    Modifier and Type
    Method
    Description
    private void
    addHorizontal(org.opengis.metadata.extent.Extent extent)
    private static <I, C extends ISOMetadata>
    I
    apply(I e1, I e2, Function<I,C> constructor, BiConsumer<C,I> operator)
    Implementation of intersection(…) and union(…) methods.
    static double
    area(org.opengis.metadata.extent.GeographicBoundingBox box)
    Returns an estimation of the area (in square metres) of the given bounding box.
    static org.opengis.geometry.DirectPosition
    centroid(org.opengis.metadata.extent.GeographicBoundingBox bbox)
    Returns the position at the median longitude and latitude values of the given bounding box.
    static Collection<? extends org.opengis.metadata.extent.Extent>
    fromIdentificationInfo(org.opengis.metadata.Metadata metadata)
    Returns the extents found in all Identification elements of the given metadata.
    static Date
    getDate(org.opengis.metadata.extent.Extent extent, double location)
    Returns an instant in the temporal elements of the given extent, or null if none.
    static String
    getDescription(org.opengis.metadata.extent.Extent extent, Locale locale)
    Returns the description of the given extent, or null if none.
    static org.opengis.metadata.extent.GeographicBoundingBox
    getGeographicBoundingBox(org.opengis.metadata.extent.Extent extent)
    Returns a single geographic bounding box from the specified extent.
    static org.opengis.metadata.extent.GeographicBoundingBox
    getGeographicBoundingBox(org.opengis.metadata.Metadata metadata)
    Returns a single geographic bounding box from the specified metadata.
    static Range<Date>
    getTimeRange(org.opengis.metadata.extent.Extent extent)
    Returns the union of all time ranges found in the given extent, or null if none.
    getVerticalRange(org.opengis.metadata.extent.Extent extent)
    Returns the union of chosen vertical ranges found in the given extent, or null if none.
    static org.opengis.metadata.extent.Extent
    intersection(org.opengis.metadata.extent.Extent e1, org.opengis.metadata.extent.Extent e2)
    Returns the intersection of the given extents.
    static org.opengis.metadata.extent.GeographicBoundingBox
    intersection(org.opengis.metadata.extent.GeographicBoundingBox b1, org.opengis.metadata.extent.GeographicBoundingBox b2)
    Returns the intersection of the given geographic bounding boxes.
    (package private) static org.opengis.metadata.extent.GeographicExtent
    intersection(org.opengis.metadata.extent.GeographicExtent e1, org.opengis.metadata.extent.GeographicExtent e2)
    May compute an intersection between the given geographic extents.
    static org.opengis.metadata.extent.TemporalExtent
    intersection(org.opengis.metadata.extent.TemporalExtent e1, org.opengis.metadata.extent.TemporalExtent e2)
    Returns the intersection of the given temporal extents.
    static org.opengis.metadata.extent.VerticalExtent
    intersection(org.opengis.metadata.extent.VerticalExtent e1, org.opengis.metadata.extent.VerticalExtent e2)
    Returns the intersection of the given vertical extents.
    static org.opengis.metadata.extent.GeographicBoundingBox
    union(org.opengis.metadata.extent.GeographicBoundingBox b1, org.opengis.metadata.extent.GeographicBoundingBox b2)
    Returns the union of the given geographic bounding boxes.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • bounds

      private org.opengis.metadata.extent.GeographicBoundingBox bounds
      The bounding box computed by this class.
    • modifiable

      private DefaultGeographicBoundingBox modifiable
      If more than one GeographicBoundingBox is found, a new instance used for computing the union of all bounding boxes.
    • WORLD

      public static final org.opengis.metadata.extent.Extent WORLD
      A geographic extent ranging from 180°W to 180°E and 90°S to 90°N. This extent has no vertical and no temporal components.
  • Constructor Details

    • Extents

      private Extents()
      Do no allow instantiation of this class, except for internal purposes.
  • Method Details

    • fromIdentificationInfo

      public static Collection<? extends org.opengis.metadata.extent.Extent> fromIdentificationInfo(org.opengis.metadata.Metadata metadata)
      Returns the extents found in all Identification elements of the given metadata. If there is only one Identification element (which is the usual case), then its collection of extents is returned as-is; the collection is not copied.

      In the less usual case where there is many Identification elements providing non-empty collection of extents, then this method returns the union of all collections without duplicated elements (duplication determined by Object.equals(Object)). In the special case where the first non-empty collection of extents contains all other collections, then that collection is returned as-is.

      Rational: above policy makes a best effort for avoiding to create new collections. The reason is that collection implementations may perform lazy calculations of Extent elements. This method tries to preserve the lazy behavior (if any).
      Parameters:
      metadata - the metadata, or null if none.
      Returns:
      extents found in all Identification elements, or an empty collection if none.
      Since:
      1.3
    • getGeographicBoundingBox

      @OptionalCandidate public static org.opengis.metadata.extent.GeographicBoundingBox getGeographicBoundingBox(org.opengis.metadata.Metadata metadata)
      Returns a single geographic bounding box from the specified metadata. If the given metadata contains many Identification or many Extent instances, then this method returns the union of all of them.
      Use case: this convenience method is useful when the metadata is expected to contain only one bounding box, typically because the metadata were obtained from a resource which is known to support only singletons (one raster or one set of features). For more general cases, it is often more appropriate to handle each bounding box separately using getGeographicBoundingBox(Extent).
      Parameters:
      metadata - the metadata from which to get a global bounding box, or null if none.
      Returns:
      a global bounding box for all extents found in the given metadata, or null if none.
      Since:
      1.1
    • getGeographicBoundingBox

      @OptionalCandidate public static org.opengis.metadata.extent.GeographicBoundingBox getGeographicBoundingBox(org.opengis.metadata.extent.Extent extent)
      Returns a single geographic bounding box from the specified extent. This method tries to find the bounding box in the cheapest way before to fallback on more expansive computations:
      1. First, this method searches geographic elements that are instance of GeographicBoundingBox.
        • If exactly one such instance is found, then this method returns that instance directly (no copy).
        • If more than one instance is found, then this method computes and returns the union of all bounding boxes.
      2. If above step found no GeographicBoundingBox, then this method inspects geographic elements that are instance of BoundingPolygon, taking in account only the envelopes associated to a coordinate reference system of kind GeographicCRS. If such envelopes are found, then this method computes and returns their union.
      3. If above step found no polygon's envelope associated to a geographic CRS, then in last resort this method uses all polygon's envelopes regardless their coordinate reference system (provided that the CRS is not null), applying coordinate transformations if needed.
      4. If above step found no polygon's envelope, then this method returns null.
      Parameters:
      extent - the extent to convert to a geographic bounding box, or null.
      Returns:
      a geographic bounding box extracted from the given extent, or null if none.
      See Also:
    • addHorizontal

      private void addHorizontal(org.opengis.metadata.extent.Extent extent) throws org.opengis.referencing.operation.TransformException
      Implementation of getGeographicBoundingBox(Extent). Defined in as a class member for allowing accumulation of many extents.
      Parameters:
      extent - the extent to add. Must be non-null.
      Throws:
      org.opengis.referencing.operation.TransformException
    • getVerticalRange

      @OptionalCandidate public static MeasurementRange<Double> getVerticalRange(org.opengis.metadata.extent.Extent extent)
      Returns the union of chosen vertical ranges found in the given extent, or null if none. This method gives preference to heights above the Mean Sea Level when possible. Depths have negative height values: if the axis direction is toward down, then this method reverses the sign of minimum and maximum values.

      Multi-occurrences

      If the given Extent object contains more than one vertical extent, then this method performs a choice based on the vertical datum and the unit of measurement:
      • Choice based on vertical datum
        Only the extents associated (indirectly, through their CRS) to the same non-null VerticalDatumType will be taken in account. If all datum types are null, then this method conservatively uses only the first vertical extent. Otherwise the datum type used for filtering the vertical extents is:

        • VerticalDatumType.GEOIDAL or DEPTH if at least one extent uses those datum types. For this method, DEPTH is considered as equivalent to GEOIDAL except for the axis direction.
        • Otherwise, the first non-null datum type found in iteration order.
        Rational: like geographic bounding box, the vertical range is an approximated information; the range returned by this method does not carry any information about the vertical CRS and this method does not attempt to perform coordinate transformation. But this method is more useful if the returned ranges are close to a frequently used surface, like the Mean Sea Level. The same simplification is applied in the VerticalExtent element of Well Known Text (WKT) format, which specifies that “Vertical extent is an approximate description of location; heights are relative to an unspecified mean sea level.”
      • Choice based on units of measurement
        If, after the choice based on the vertical datum described above, there is still more than one vertical extent to consider, then the next criterion checks for the units of measurement.

        • If no range specify a unit of measurement, return the first range and ignore all others.
        • Otherwise take the first range having a unit of measurement. Then:
          • All other ranges having an incompatible unit of measurement will be ignored.
          • All other ranges having a compatible unit of measurement will be converted to the unit of the first retained range, and their union will be computed.
        Example: Heights or depths are often measured using some pressure units, for example hectopascals (hPa). An Extent could contain two vertical elements: one with the height measurements in hPa, and the other element with heights transformed to metres using an empirical formula. In such case this method will select the first vertical element on the assumption that it is the "main" one that the metadata producer intended to show. Next, this method will search for other vertical elements using pressure unit. In our example there is none, but if such elements were found, this method would compute their union.
      Parameters:
      extent - the extent to convert to a vertical measurement range, or null.
      Returns:
      a vertical measurement range created from the given extent, or null if none.
      Since:
      0.4
    • getTimeRange

      @OptionalCandidate public static Range<Date> getTimeRange(org.opengis.metadata.extent.Extent extent)
      Returns the union of all time ranges found in the given extent, or null if none.
      Parameters:
      extent - the extent to convert to a time range, or null.
      Returns:
      a time range created from the given extent, or null if none.
      Since:
      0.4
    • getDate

      @OptionalCandidate public static Date getDate(org.opengis.metadata.extent.Extent extent, double location)
      Returns an instant in the temporal elements of the given extent, or 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: Special cases:
      • If location is 0, then this method returns the start time.
      • If location is 1, then this method returns the end time.
      • If location is 0.5, then this method returns the average of start time and end time.
      • If location is outside the [0 … 1] range, then the result will be outside the temporal extent.
      Parameters:
      extent - the extent from which to get an instant, or null.
      location - 0 for the start time, 1 for the end time, 0.5 for the average time, or the coefficient (usually in the [0 … 1] range) for interpolating an instant.
      Returns:
      an instant interpolated at the given location, or null if none.
      Since:
      0.4
    • getDescription

      @OptionalCandidate public static String getDescription(org.opengis.metadata.extent.Extent extent, Locale locale)
      Returns the description of the given extent, or null if none.
      Parameters:
      extent - the extent from which to get a description, or null.
      locale - desired locale, or null for default.
      Returns:
      description of the given extent, or null if none.
      Since:
      1.1
    • centroid

      public static org.opengis.geometry.DirectPosition centroid(org.opengis.metadata.extent.GeographicBoundingBox bbox)
      Returns the position at the median longitude and latitude values of the given bounding box. This method does not check the inclusion status. This method takes in account bounding boxes that cross the anti-meridian.
      Parameters:
      bbox - the bounding box for which to get the median longitude and latitude values, or null.
      Returns:
      a median position of the given bounding box, or null if none.
    • area

      public static double area(org.opengis.metadata.extent.GeographicBoundingBox box)
      Returns an estimation of the area (in square metres) of the given bounding box. Since GeographicBoundingBox provides only approximated information (for example it does not specify the datum), the value returned by this method is also approximated.

      The current implementation performs its computation on the GRS 1980 Authalic Sphere. However, this may change in any future SIS version.

      Parameters:
      box - the geographic bounding box for which to compute the area, or null.
      Returns:
      an estimation of the area in the given bounding box (m²), or NaN if the given box was null.
      Since:
      0.4
    • union

      public static org.opengis.metadata.extent.GeographicBoundingBox union(org.opengis.metadata.extent.GeographicBoundingBox b1, org.opengis.metadata.extent.GeographicBoundingBox b2)
      Returns the union of the given geographic bounding boxes. If any of the arguments is null, then this method returns the other argument (which may be null). Otherwise this method returns a box which is the union of the two given boxes.

      This method never modify the given boxes, but may return directly one of the given arguments if it already represents the union result.

      Parameters:
      b1 - the first bounding box, or null.
      b2 - the second bounding box, or null.
      Returns:
      the union (may be any of the b1 or b2 argument if unchanged), or null if the two given boxes are null.
      Since:
      1.2
      See Also:
    • intersection

      public static org.opengis.metadata.extent.GeographicBoundingBox intersection(org.opengis.metadata.extent.GeographicBoundingBox b1, org.opengis.metadata.extent.GeographicBoundingBox b2)
      Returns the intersection of the given geographic bounding boxes. If any of the arguments is 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. If there is no intersection, the returned bounding box contains Double.NaN bounds.

      This method never modify the given boxes, but may return directly one of the given arguments if it already represents the intersection result.

      Parameters:
      b1 - the first bounding box, or null.
      b2 - the second bounding box, or null.
      Returns:
      the intersection (may be any of the b1 or b2 argument if unchanged), or null if the two given boxes are null. May contain Double.NaN bounds.
      Throws:
      IllegalArgumentException - if the inclusion status is not the same for both boxes.
      Since:
      0.4
      See Also:
    • intersection

      static org.opengis.metadata.extent.GeographicExtent intersection(org.opengis.metadata.extent.GeographicExtent e1, org.opengis.metadata.extent.GeographicExtent e2)
      May compute an intersection between the given geographic extents. Current implementation supports only GeographicBoundingBox; all other kinds are handled as if they were null.

      We may improve this method in future Apache SIS version, but it is not yet clear how. For example, how to handle GeographicDescription or BoundingPolygon? This method should not be public before we find a better contract.

    • intersection

      public static org.opengis.metadata.extent.VerticalExtent intersection(org.opengis.metadata.extent.VerticalExtent e1, org.opengis.metadata.extent.VerticalExtent e2)
      Returns the intersection of the given vertical extents. If any of the arguments is null, then this method returns the other argument (which may be null). Otherwise this method returns a vertical extent which is the intersection of the two given extents.

      This method never modify the given extents, but may return directly one of the given arguments if it already represents the intersection result.

      Advantage and inconvenient of this method

      This method cannot intersect extents defined with different datums because height transformations generally require the geodetic positions (latitudes and longitudes) of the heights to transform. For more general transformations, it is better to convert all extent components into a single envelope, then transform the envelope at once. On the other hand, this intersect(…) method preserves better the NilReason (if any).
      Parameters:
      e1 - the first extent, or null.
      e2 - the second extent, or null.
      Returns:
      the intersection (may be any of the e1 or e2 argument if unchanged), or null if the two given extents are null.
      Throws:
      IllegalArgumentException - if the two extents do not use the same datum, ignoring metadata.
      Since:
      0.8
      See Also:
    • intersection

      public static org.opengis.metadata.extent.TemporalExtent intersection(org.opengis.metadata.extent.TemporalExtent e1, org.opengis.metadata.extent.TemporalExtent e2)
      Returns the intersection of the given temporal extents. If any of the arguments is null, then this method returns the other argument (which may be null). Otherwise this method returns a temporal extent which is the intersection of the two given extents.

      This method never modify the given extents, but may return directly one of the given arguments if it already represents the intersection result.

      Parameters:
      e1 - the first extent, or null.
      e2 - the second extent, or null.
      Returns:
      the intersection (may be any of the e1 or e2 argument if unchanged), or null if the two given extents are null.
      Throws:
      UnsupportedOperationException - if no implementation of TemporalFactory has been found on the classpath.
      Since:
      0.8
      See Also:
    • intersection

      public static org.opengis.metadata.extent.Extent intersection(org.opengis.metadata.extent.Extent e1, org.opengis.metadata.extent.Extent e2)
      Returns the intersection of the given extents. If any of the arguments is null, then this method returns the other argument (which may be null). Otherwise this method returns an extent which is the intersection of all geographic, vertical and temporal elements in the two given extents.

      This method never modify the given extents, but may return directly one of the given arguments if it already represents the intersection result.

      Parameters:
      e1 - the first extent, or null.
      e2 - the second extent, or null.
      Returns:
      the intersection (may be any of the e1 or e2 argument if unchanged), or null if the two given extents are null.
      Throws:
      IllegalArgumentException - if two elements to intersect are not compatible (e.g. mismatched bounding box inclusion status or mismatched vertical datum).
      UnsupportedOperationException - if a TemporalFactory is required but no implementation has been found on the classpath.
      Since:
      0.8
      See Also:
    • apply

      private static <I, C extends ISOMetadata> I apply(I e1, I e2, Function<I,C> constructor, BiConsumer<C,I> operator)
      Implementation of intersection(…) and union(…) methods.
      Note: the C parameter type should be <C extends ISOMetadata & I>. But this is not allowed by current Java compiler, because of complexity. See JDK-4899305.
      Type Parameters:
      I - the metadata interface.
      C - the metadata implementation class. Shall implement <I>.
      Parameters:
      e1 - the first extent, or null.
      e2 - the second extent, or null.
      constructor - copy constructor of metadata implementation class.
      operator - the union or intersection operator to apply.
      Returns: