Class SpatialOperationContext

java.lang.Object
org.apache.sis.internal.feature.SpatialOperationContext
All Implemented Interfaces:
Serializable

public final class SpatialOperationContext extends Object implements Serializable
Context (such as desired CRS) in which a spatial operator will be executed.

Instances of this class are immutable and thread-safe.

The serialization form is not a committed API and may change in any future version.

Since:
1.1
Version:
1.3
See Also:
  • Nested Class Summary

    Nested Classes
    Modifier and Type
    Class
    Description
    private static final class 
    Creates projections centered on a given geometry.
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    private final org.opengis.metadata.extent.GeographicBoundingBox
    Approximate geographic area of geometries, or null if unspecified.
    private static final int
    The 2 value, for identifying code that assume two-dimensional objects.
    (package private) org.opengis.referencing.crs.CoordinateReferenceSystem
    The common CRS found by transform(GeometryWrapper[]).
    private final org.opengis.referencing.crs.CoordinateReferenceSystem
    The target CRS in which to transform geometries, or null for inferring automatically.
    private static final long
    For cross-version compatibility.
    private final int
    Index of the geometry associated to the common CRS, or -1 if none.
    private final javax.measure.Unit<?>
    If the CRS needs to be in some units of measurement, the Unit.getSystemUnit() value.
  • Constructor Summary

    Constructors
    Constructor
    Description
    SpatialOperationContext(org.opengis.metadata.extent.GeographicBoundingBox areaOfInterest, GeometryWrapper<?> literal, javax.measure.Unit<?> systemUnit, int skipIndex)
    Creates a new context.
  • Method Summary

    Modifier and Type
    Method
    Description
    private static boolean
    isCompatibleUnit(org.opengis.referencing.crs.CoordinateReferenceSystem crs, javax.measure.Unit<?> systemUnit)
    Returns true if the units of measurement of the given CRS are compatible with the given units.
    static boolean
    The value to return when a test cannot be applied.
    static boolean
    The value to return when a test cannot be applied.
    private static org.opengis.referencing.crs.CoordinateReferenceSystem
    to2D(org.opengis.referencing.crs.CoordinateReferenceSystem crs)
    Returns the two first dimensions of the given CRS.
    Transforms the specified geometry to the computation CRS.
    (package private) final <G> boolean
    transform(GeometryWrapper<G>[] geometries)
    Transforms the specified geometries to the common CRS.
    private static org.opengis.referencing.crs.CoordinateReferenceSystem
    usingSystemUnit(GeometryWrapper<?> geometry, org.opengis.referencing.crs.CoordinateReferenceSystem geometryCRS, org.opengis.referencing.crs.CoordinateReferenceSystem targetCRS, javax.measure.Unit<?> systemUnit)
    Returns a coordinate reference system using the unit of measurement compatible with given system unit.

    Methods inherited from class java.lang.Object

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

    • serialVersionUID

      private static final long serialVersionUID
      For cross-version compatibility.
      See Also:
    • BIDIMENSIONAL

      private static final int BIDIMENSIONAL
      The 2 value, for identifying code that assume two-dimensional objects.
      See Also:
    • areaOfInterest

      private final org.opengis.metadata.extent.GeographicBoundingBox areaOfInterest
      Approximate geographic area of geometries, or null if unspecified.
    • computationCRS

      private final org.opengis.referencing.crs.CoordinateReferenceSystem computationCRS
      The target CRS in which to transform geometries, or null for inferring automatically.
    • systemUnit

      private final javax.measure.Unit<?> systemUnit
      If the CRS needs to be in some units of measurement, the Unit.getSystemUnit() value. For example, is units need to be linear, then systemUnit shall be Units.METRE. Note that it does not mean that the units of measurement must be meters; only that they must be compatible with meters.
    • skipIndex

      private final int skipIndex
      Index of the geometry associated to the common CRS, or -1 if none. This is used for avoiding unnecessary check of its CRS.
    • commonCRS

      org.opengis.referencing.crs.CoordinateReferenceSystem commonCRS
      The common CRS found by transform(GeometryWrapper[]). May be null.
  • Constructor Details

    • SpatialOperationContext

      public SpatialOperationContext(org.opengis.metadata.extent.GeographicBoundingBox areaOfInterest, GeometryWrapper<?> literal, javax.measure.Unit<?> systemUnit, int skipIndex) throws org.opengis.util.FactoryException, org.opengis.referencing.operation.TransformException, javax.measure.IncommensurableException
      Creates a new context.
      Parameters:
      areaOfInterest - approximate geographic area of geometries, or null if unspecified.
      literal - if a geometry operand is a literal, that literal. Otherwise null.
      systemUnit - if the CRS needs to be in some units of measurement, the Unit.getSystemUnit() value.
      skipIndex - index of the geometry associated to commonCRS, or -1 if none.
      Throws:
      org.opengis.util.FactoryException - if an error occurred while fetching literal CRS.
      org.opengis.referencing.operation.TransformException - if a coordinate conversion was required but failed.
      javax.measure.IncommensurableException - if a coordinate system does not use the expected units.
  • Method Details

    • to2D

      private static org.opengis.referencing.crs.CoordinateReferenceSystem to2D(org.opengis.referencing.crs.CoordinateReferenceSystem crs)
      Returns the two first dimensions of the given CRS. This is usually the crs argument unchanged (which may be null), unless a three- or four-dimensional CRS has been specified. We work with two dimensional CRS because the wrapped geometries are 2D and for avoiding that ReferencingUtilities.getUnit(CoordinateSystem) returns null.
    • transform

      public <G> GeometryWrapper<G> transform(GeometryWrapper<G> geometry) throws org.opengis.util.FactoryException, org.opengis.referencing.operation.TransformException
      Transforms the specified geometry to the computation CRS. Geometries with unspecified CRS will be used as-is, without transformation. The common CRS is stored in the commonCRS field.
      Type Parameters:
      G - geometry implementation base class.
      Parameters:
      geometry - the geometry to transform.
      Returns:
      the transformed geometry, or the same instance if no transformation was applied.
      Throws:
      org.opengis.util.FactoryException - if an error occurred while fetching a CRS.
      org.opengis.referencing.operation.TransformException - if a coordinate conversion was required but failed.
    • transform

      final <G> boolean transform(GeometryWrapper<G>[] geometries) throws org.opengis.util.FactoryException, org.opengis.referencing.operation.TransformException, javax.measure.IncommensurableException
      Transforms the specified geometries to the common CRS. If computationCRS is null, then this method tries to infer one automatically. Geometries with unspecified CRS will be used as-is, without transformation. The common CRS is stored in the commonCRS field.
      Type Parameters:
      G - geometry implementation base class.
      Parameters:
      geometries - the geometries to transform. Results will be stored in-place.
      Returns:
      whether this method has been able to find a common CRS.
      Throws:
      org.opengis.util.FactoryException - if an error occurred while fetching a CRS.
      org.opengis.referencing.operation.TransformException - if a coordinate conversion was required but failed.
      javax.measure.IncommensurableException - if a geographic CRS does not use angular units (should not happen).
    • isCompatibleUnit

      private static boolean isCompatibleUnit(org.opengis.referencing.crs.CoordinateReferenceSystem crs, javax.measure.Unit<?> systemUnit)
      Returns true if the units of measurement of the given CRS are compatible with the given units. All CRS axes should have the same units, otherwise this method returns false.
      Parameters:
      crs - the CRS for which to test the units of measurement.
      systemUnit - the Unit.getSystemUnit() value of the desired unit.
      Returns:
      whether the CRS units of measurement are compatible.
    • usingSystemUnit

      private static org.opengis.referencing.crs.CoordinateReferenceSystem usingSystemUnit(GeometryWrapper<?> geometry, org.opengis.referencing.crs.CoordinateReferenceSystem geometryCRS, org.opengis.referencing.crs.CoordinateReferenceSystem targetCRS, javax.measure.Unit<?> systemUnit) throws org.opengis.util.FactoryException, org.opengis.referencing.operation.TransformException, javax.measure.IncommensurableException
      Returns a coordinate reference system using the unit of measurement compatible with given system unit. This is usually for creating a ProjectedCRS when the user requested linear units, but it can also return GeographicCRS if the user requested angular units.
      Parameters:
      geometry - one of the geometry used in the operation. Will determine projection center.
      geometryCRS - the CRS of geometry.
      targetCRS - initial proposal of CRS to use for coordinate operation.
      systemUnit - Unit.getSystemUnit() value on the unit requested by user.
      Returns:
      a CRS derived from targetCRS with units compatible with the specified units.
      Throws:
      org.opengis.util.FactoryException - if an error occurred while fetching a CRS.
      org.opengis.referencing.operation.TransformException - if a coordinate conversion was required but failed.
      javax.measure.IncommensurableException - if a coordinate system does not use the expected units.
    • negativeResult

      public static boolean negativeResult(SpatialOperatorName type)
      The value to return when a test cannot be applied. This method is defined for having a single place to update if more operator types need to be recognized.
      Parameters:
      type - the test that could not be applied.
      Returns:
      the operation result to assume.
    • negativeResult

      public static boolean negativeResult(DistanceOperatorName type)
      The value to return when a test cannot be applied. This method is defined for having a single place to update if more operator types need to be recognized.
      Parameters:
      type - the test that could not be applied.
      Returns:
      the operation result to assume.