Enum SpatialRelation

  • All Implemented Interfaces:
    java.io.Serializable, java.lang.Comparable<SpatialRelation>

    public enum SpatialRelation
    extends java.lang.Enum<SpatialRelation>
    The set of spatial relationships. Naming is somewhat consistent with OGC spec conventions as seen in SQL/MM and others.

    There is no equality case. If two Shape instances are equal then the result might be CONTAINS (preferred) or WITHIN. Client logic may have to be aware of this edge condition; Spatial4j testing certainly does.

    The "CONTAINS" and "WITHIN" wording here is inconsistent with OGC; these here map to OGC "COVERS" and "COVERED BY", respectively. The distinction is in the boundaries; in Spatial4j there is no boundary distinction -- boundaries are part of the shape as if it was an "interior", with respect to OGC's terminology.

    • Enum Constant Summary

      Enum Constants 
      Enum Constant Description
      CONTAINS
      The shape contains the target geometry.
      DISJOINT
      The shape shares no point in common with the target shape.
      INTERSECTS
      The shape shares some points/overlap with the target shape, and the relation is not more specifically WITHIN or CONTAINS.
      WITHIN
      The shape is within the target geometry.
    • Constructor Summary

      Constructors 
      Modifier Constructor Description
      private SpatialRelation()  
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      SpatialRelation combine​(SpatialRelation other)
      If you were to call aShape.relate(bShape) and aShape.relate(cShape), you could call this to merge the intersect results as if bShape & cShape were combined into ShapeCollection.
      boolean intersects()
      Not DISJOINT, i.e.
      SpatialRelation inverse()
      If aShape.relate(bShape) is r, then r.inverse() is inverse(aShape).relate(bShape) whereas inverse(shape) is theoretically the opposite area covered by a shape, i.e.
      SpatialRelation transpose()
      Given the result of shapeA.relate(shapeB), transposing that result should yield the result of shapeB.relate(shapeA).
      static SpatialRelation valueOf​(java.lang.String name)
      Returns the enum constant of this type with the specified name.
      static SpatialRelation[] values()
      Returns an array containing the constants of this enum type, in the order they are declared.
      • Methods inherited from class java.lang.Enum

        clone, compareTo, equals, finalize, getDeclaringClass, hashCode, name, ordinal, toString, valueOf
      • Methods inherited from class java.lang.Object

        getClass, notify, notifyAll, wait, wait, wait
    • Enum Constant Detail

      • WITHIN

        public static final SpatialRelation WITHIN
        The shape is within the target geometry. It's the converse of CONTAINS. Boundaries of shapes count too. OGC specs refer to this relation as "COVERED BY"; WITHIN is differentiated there by not including boundaries.
      • CONTAINS

        public static final SpatialRelation CONTAINS
        The shape contains the target geometry. It's the converse of WITHIN. Boundaries of shapes count too. OGC specs refer to this relation as "COVERS"; CONTAINS is differentiated there by not including boundaries.
      • DISJOINT

        public static final SpatialRelation DISJOINT
        The shape shares no point in common with the target shape.
      • INTERSECTS

        public static final SpatialRelation INTERSECTS
        The shape shares some points/overlap with the target shape, and the relation is not more specifically WITHIN or CONTAINS.
    • Constructor Detail

      • SpatialRelation

        private SpatialRelation()
    • Method Detail

      • values

        public static SpatialRelation[] values()
        Returns an array containing the constants of this enum type, in the order they are declared. This method may be used to iterate over the constants as follows:
        for (SpatialRelation c : SpatialRelation.values())
            System.out.println(c);
        
        Returns:
        an array containing the constants of this enum type, in the order they are declared
      • valueOf

        public static SpatialRelation valueOf​(java.lang.String name)
        Returns the enum constant of this type with the specified name. The string must match exactly an identifier used to declare an enum constant in this type. (Extraneous whitespace characters are not permitted.)
        Parameters:
        name - the name of the enum constant to be returned.
        Returns:
        the enum constant with the specified name
        Throws:
        java.lang.IllegalArgumentException - if this enum type has no constant with the specified name
        java.lang.NullPointerException - if the argument is null
      • transpose

        public SpatialRelation transpose()
        Given the result of shapeA.relate(shapeB), transposing that result should yield the result of shapeB.relate(shapeA). There is a corner case is when the shapes are equal, in which case actually flipping the relate() call will result in the same value -- either CONTAINS or WITHIN; this method can't possible check for that so the caller might have to.
      • combine

        public SpatialRelation combine​(SpatialRelation other)
        If you were to call aShape.relate(bShape) and aShape.relate(cShape), you could call this to merge the intersect results as if bShape & cShape were combined into ShapeCollection. If other is null then the result is "this".
      • intersects

        public boolean intersects()
        Not DISJOINT, i.e. there is some sort of intersection.
      • inverse

        public SpatialRelation inverse()
        If aShape.relate(bShape) is r, then r.inverse() is inverse(aShape).relate(bShape) whereas inverse(shape) is theoretically the opposite area covered by a shape, i.e. everywhere but where the shape is.

        Note that it's not commutative! WITHIN.inverse().inverse() != WITHIN.