Class Referenced

java.lang.Object
nz.org.riskscape.engine.types.Referenced
All Implemented Interfaces:
Type, WrappingType

public class Referenced extends Object implements WrappingType

Type that adds CoordinateReferenceSystem and an optional bounds to another type.

NB This class can wrap any type, not just geometry, so care should be taken when finding Referenced types to ensure that they are also Geometry types before casting the values to Geometry.

  • Constructor Summary

    Constructors
    Constructor
    Description
    Referenced(Type underlying, org.geotools.api.referencing.crs.CoordinateReferenceSystem crs)
    Convenience constructor that omits the bounds from the Referenced type.
    Referenced(Type underlying, org.geotools.api.referencing.crs.CoordinateReferenceSystem crs, org.locationtech.jts.geom.Envelope envelope)
    Create a new Referenced type that wraps the given type with a crs and a bounds envelope.
    Referenced(Type underlying, org.geotools.geometry.jts.ReferencedEnvelope envelope)
    Convenience constructor that takes the crs and bounds from the given referenced envelope
  • Method Summary

    Modifier and Type
    Method
    Description
    protected boolean
     
    coerce(Object value)
    Attempt to convert the given value in to one represented by this type.
    static Type
     
    boolean
     
    org.geotools.geometry.jts.ReferencedEnvelope
     
    org.geotools.api.referencing.crs.CoordinateReferenceSystem
     
    org.locationtech.jts.geom.Envelope
     
     
    int
     
    The underlying java class used to represent this type.
    static Type
    of(Type underlying, org.geotools.api.referencing.crs.CoordinateReferenceSystem crs)
    Now somewhat needless static constructor to avoid undue change in code that was calling it.
    static Type
    of(Type underlying, org.geotools.api.referencing.crs.CoordinateReferenceSystem crs, org.locationtech.jts.geom.Envelope envelope)
    Now somewhat needless static constructor to avoid undue change in code that was calling it.
    static Type
    ofNullable(Type underlying, org.geotools.api.referencing.crs.CoordinateReferenceSystem crs)
    Static constructor that takes care of re-wrapping the produced referenced type with nullable if the given underlying type was nullable
    static Type
    ofNullable(Type underlying, org.geotools.api.referencing.crs.CoordinateReferenceSystem crs, org.locationtech.jts.geom.Envelope envelope)
    Static constructor that takes care of re-wrapping the produced referenced type with nullable if the given underlying type was nullable
    static Type
    ofNullable(Type underlying, org.geotools.geometry.jts.ReferencedEnvelope bounds)
    Static constructor that takes care of re-wrapping the produced referenced type with nullable if the given underlying type was nullable
     
    wrap(Type toWrap)
    Returns a new Type with underlyingType of toWrap with the same crs and bounds as this referenced.
    Returns a new Type with underlyingType of toWrap with the same crs and bounds as this referenced.

    Methods inherited from class java.lang.Object

    clone, finalize, getClass, notify, notifyAll, wait, wait, wait

    Methods inherited from interface nz.org.riskscape.engine.types.Type

    checkForNull, find, findAllowNull, getUnwrappedType, isA, isNumeric, isWrapped, toString, unwrap

    Methods inherited from interface nz.org.riskscape.engine.types.WrappingType

    asStruct, estimateSize, fromBytes, isNullable, toBytes, visit
  • Constructor Details

    • Referenced

      public Referenced(Type underlying, org.geotools.geometry.jts.ReferencedEnvelope envelope)

      Convenience constructor that takes the crs and bounds from the given referenced envelope

    • Referenced

      public Referenced(Type underlying, org.geotools.api.referencing.crs.CoordinateReferenceSystem crs)

      Convenience constructor that omits the bounds from the Referenced type.

    • Referenced

      public Referenced(Type underlying, org.geotools.api.referencing.crs.CoordinateReferenceSystem crs, org.locationtech.jts.geom.Envelope envelope)

      Create a new Referenced type that wraps the given type with a crs and a bounds envelope.

      Parameters:
      underlying - not Nullable, not already Referenced, Type. Use one of the ofNullable constructors if the given type might be nullable
      crs - a CoordinateReferenceSystem to associate with the given type. Can not be null.
      envelope - an optional envelope to associate with the geometry. If this is given then it is expected that all geometry that emerges from this type will be within the bounds of the envelope. Can be null
      Throws:
      IllegalArgumentException - if the type is nullable or already wrapped in a referenced type.
  • Method Details

    • computeAncestor

      public static Type computeAncestor(Referenced lhs, Referenced rhs)
      Returns:
      the common ancestor type, preserving the Referenced info, if possible
    • ofNullable

      public static Type ofNullable(Type underlying, org.geotools.api.referencing.crs.CoordinateReferenceSystem crs)

      Static constructor that takes care of re-wrapping the produced referenced type with nullable if the given underlying type was nullable

    • ofNullable

      public static Type ofNullable(Type underlying, org.geotools.geometry.jts.ReferencedEnvelope bounds)

      Static constructor that takes care of re-wrapping the produced referenced type with nullable if the given underlying type was nullable

    • ofNullable

      public static Type ofNullable(Type underlying, org.geotools.api.referencing.crs.CoordinateReferenceSystem crs, org.locationtech.jts.geom.Envelope envelope)

      Static constructor that takes care of re-wrapping the produced referenced type with nullable if the given underlying type was nullable

    • of

      public static Type of(Type underlying, org.geotools.api.referencing.crs.CoordinateReferenceSystem crs, org.locationtech.jts.geom.Envelope envelope)

      Now somewhat needless static constructor to avoid undue change in code that was calling it. NB static constructors are most useful when they do something that isn't possible in a vanilla constructor, such as handing out frequently used instances to avoid unnecessary promulgation of objects, or having some extra logic that might affect the return type, or perhaps giving it a more meaningful name in the case it accepts different arguments. I had originally started remove all the uses of this method, but it seemed petty so i've left them, but know that this method does nothing special beyond constructing an instance.

    • of

      public static Type of(Type underlying, org.geotools.api.referencing.crs.CoordinateReferenceSystem crs)

      Now somewhat needless static constructor to avoid undue change in code that was calling it. NB static constructors are most useful when they do something that isn't possible in a vanilla constructor, such as handing out frequently used instances to avoid unnecessary promulgation of objects, or having some extra logic that might affect the return type, or perhaps giving it a more meaningful name in the case it accepts different arguments. I had originally started remove all the uses of this method, but it seemed petty so i've left them, but know that this method does nothing special beyond constructing an instance.

    • getBounds

      public org.geotools.geometry.jts.ReferencedEnvelope getBounds()
    • coerce

      public Object coerce(Object value) throws CoercionException
      Description copied from interface: Type

      Attempt to convert the given value in to one represented by this type.

      Specified by:
      coerce in interface Type
      Parameters:
      value - The value to coerce
      Returns:
      A value that conforms to this type
      Throws:
      CoercionException - if the given object can not be converted to something represented by this type
    • internalType

      public Class<?> internalType()
      Description copied from interface: Type

      The underlying java class used to represent this type.

      Specified by:
      internalType in interface Type
    • wrapNullable

      public Type wrapNullable(Type toWrap)

      Returns a new Type with underlyingType of toWrap with the same crs and bounds as this referenced.

      Parameters:
      toWrap - type to reference with this crs/bounds
      Returns:
      referenced toWrap
    • wrap

      public Referenced wrap(Type toWrap)

      Returns a new Type with underlyingType of toWrap with the same crs and bounds as this referenced.

      Parameters:
      toWrap - type to reference with this crs/bounds
      Returns:
      referenced toWrap
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • equals

      public boolean equals(Object o)
      Overrides:
      equals in class Object
    • canEqual

      protected boolean canEqual(Object other)
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • getUnderlyingType

      public Type getUnderlyingType()
      Specified by:
      getUnderlyingType in interface WrappingType
      Returns:
      the type that we immediately wrap. Used by Type.getUnwrappedType() to descend through all wrapped Type to find the first unwrapped one.
    • getCrs

      public org.geotools.api.referencing.crs.CoordinateReferenceSystem getCrs()
    • getEnvelope

      public org.locationtech.jts.geom.Envelope getEnvelope()