Class ReferencingServices

All Implemented Interfaces:
EventListener
Direct Known Subclasses:
ServicesForMetadata

public class ReferencingServices extends OptionalDependency
Provides access to services defined in the "sis-referencing" module. This class searches for the ServicesForMetadata implementation using Java reflection.

This class also opportunistically defines some methods and constants related to "referencing by coordinates" but needed by metadata.

Since:
0.3
Version:
1.3
  • Field Details

    • NAUTICAL_MILE

      public static final double NAUTICAL_MILE
      The length of one nautical mile, which is 1852.0 metres.
      See Also:
    • AUTHALIC_RADIUS

      public static final double AUTHALIC_RADIUS
      The GRS80 authalic radius, which is 6371007.0 metres. This is close to the WGS84 authalic radius, which is about 6371007.180918474 when computed with double precision.
      See Also:
    • instance

      private static volatile ReferencingServices instance
      The services, fetched when first needed.
  • Constructor Details

    • ReferencingServices

      protected ReferencingServices()
      For subclass only. This constructor registers this instance as a SystemListener in order to force a new ReferencingServices lookup if the classpath changes.
  • Method Details

    • classpathChanged

      protected final void classpathChanged()
      Invoked when the classpath changed. Resets the instance to null in order to force the next call to getInstance() to fetch a new one, which may be different.
      Overrides:
      classpathChanged in class OptionalDependency
    • getInstance

      public static ReferencingServices getInstance()
      Returns the singleton instance.
      Returns:
      the singleton instance.
    • setBounds

      public DefaultGeographicBoundingBox setBounds(org.opengis.geometry.Envelope envelope, DefaultGeographicBoundingBox target, String findOpCaller) throws org.opengis.referencing.operation.TransformException
      Sets a geographic bounding box from the specified envelope. If the envelope contains a CRS which is not geographic, then the bounding box will be transformed to a geographic CRS (without datum shift if possible). Otherwise, the envelope is assumed already in a geographic CRS using (longitude, latitude) axis order.

      If findOpCaller is non-null, then this method will be executed in optional mode: some failures will cause this method to return null instead of throwing an exception. Note that TransformException may still be thrown but not directly by this method. Warning may be logged, but in such case this method presumes that public caller is the named method from Envelopes — typically Envelopes.findOperation(Envelope, Envelope).

      Parameters:
      envelope - the source envelope.
      target - the target bounding box, or null for creating it automatically.
      findOpCaller - non-null for replacing some (not all) exceptions by null return value.
      Returns:
      the bounding box or null on failure. Never null if findOpCaller argument is null.
      Throws:
      UnsupportedOperationException - if the "sis-referencing" module has not been found on the classpath.
      org.opengis.referencing.operation.TransformException - if the given envelope cannot be transformed.
    • setBounds

      public void setBounds(org.opengis.geometry.Envelope envelope, DefaultVerticalExtent target) throws org.opengis.referencing.operation.TransformException
      Sets a vertical extent with the value inferred from the given envelope. Only the vertical coordinates are extracted; all other coordinates are ignored.
      Parameters:
      envelope - the source envelope.
      target - the target vertical extent.
      Throws:
      org.opengis.referencing.operation.TransformException - if no vertical component can be extracted from the given envelope.
      UnsupportedOperationException - if the "sis-referencing" module has not been found on the classpath.
    • setBounds

      public void setBounds(org.opengis.geometry.Envelope envelope, DefaultTemporalExtent target) throws org.opengis.referencing.operation.TransformException
      Sets a temporal extent with the value inferred from the given envelope. Only the temporal coordinates are extracted; all other coordinates are ignored.
      Parameters:
      envelope - the source envelope.
      target - the target temporal extent.
      Throws:
      org.opengis.referencing.operation.TransformException - if no temporal component can be extracted from the given envelope.
      UnsupportedOperationException - if the "sis-referencing" module has not been found on the classpath.
    • setBounds

      public void setBounds(org.opengis.geometry.Envelope envelope, DefaultSpatialTemporalExtent target) throws org.opengis.referencing.operation.TransformException
      Sets the geographic, vertical and temporal extents with the values inferred from the given envelope. If the given target has more geographic or vertical extents than needed (0 or 1), then the extraneous extents are removed.

      Behavior regarding missing dimensions:

      • If the given envelope has no horizontal component, then all geographic extents are removed from the given target. Non-geographic extents (e.g. descriptions and polygons) are left unchanged.
      • If the given envelope has no vertical component, then the vertical extent is set to null.
      • If the given envelope has no temporal component, then the temporal extent is set to null.
      Parameters:
      envelope - the source envelope.
      target - the target spatiotemporal extent.
      Throws:
      org.opengis.referencing.operation.TransformException - if no temporal component can be extracted from the given envelope.
      UnsupportedOperationException - if the "sis-referencing" module has not been found on the classpath.
    • addElements

      public void addElements(org.opengis.geometry.Envelope envelope, DefaultExtent target) throws org.opengis.referencing.operation.TransformException
      Initializes a horizontal, vertical and temporal extent with the values inferred from the given envelope.
      Parameters:
      envelope - the source envelope.
      target - the target extent.
      Throws:
      org.opengis.referencing.operation.TransformException - if a coordinate transformation was required and failed.
      UnsupportedOperationException - if the "sis-referencing" module has not been found on the classpath.
    • geographic

      public org.opengis.geometry.DirectPosition geographic(double λ, double φ)
      Creates a two-dimensional geographic position associated to the default geographic CRS. Axis order is (longitude, latitude).
      Parameters:
      \u03bb - the longitude value.
      \u03c6 - the latitude value.
      Returns:
      the direct position for the given geographic coordinate.
      Since:
      0.8
    • getPreferredIdentifier

      public String getPreferredIdentifier(org.opengis.referencing.IdentifiedObject object) throws org.opengis.util.FactoryException
      Returns an identifier for the given object, giving precedence to EPSG identifier if available. The returned string should be of the form "AUTHORITY:CODE" if possible (no guarantees).
      Parameters:
      object - the object for which to get an identifier.
      Returns:
      an identifier for the given object, with preference given to EPSG codes.
      Throws:
      org.opengis.util.FactoryException - if an error occurred while searching for the EPSG code.
      Since:
      1.0
    • getValueType

      public org.opengis.util.TypeName getValueType(org.opengis.parameter.ParameterDescriptor<?> parameter)
      Returns the name of the type of values.
      Parameters:
      parameter - parameter for which to get the name of type of values, or null.
      Returns:
      name of type of values, or null if not supported by given implementation.
    • toImplementation

      public <T> org.opengis.parameter.ParameterDescriptor<T> toImplementation(org.opengis.parameter.ParameterDescriptor<T> parameter)
      Returns a fully implemented parameter descriptor.
      Type Parameters:
      T - the type of values.
      Parameters:
      parameter - a partially implemented parameter descriptor, or null.
      Returns:
      a fully implemented parameter descriptor, or null if the given argument was null.
      Throws:
      UnsupportedOperationException - if the "sis-referencing" module has not been found on the classpath.
      Since:
      0.5
    • createCoordinateFormat

      public Format createCoordinateFormat(Locale locale, TimeZone timezone)
      Creates a format for DirectPosition instances.
      Parameters:
      locale - the locale for the new Format, or null for Locale.ROOT.
      timezone - the timezone, or null for UTC.
      Returns:
      a CoordinateFormat.
      Since:
      0.8
    • getCoordinateOperationFactory

      public org.opengis.referencing.operation.CoordinateOperationFactory getCoordinateOperationFactory()
      Returns the default coordinate operation factory.
      Returns:
      the coordinate operation factory to use.
    • getInformation

      public String getInformation(String key, Locale locale)
      Returns information about the Apache SIS configuration to be reported in About. This method is invoked only for aspects that depends on other modules than sis-utility.

      Current keys are:

      • "EPSG": version of EPSG database.
      Parameters:
      key - a key identifying the information to return.
      locale - language to use if possible.
      Returns:
      the information, or null if none.
      Since:
      0.7
      See Also: