Interface Shape

All Known Subinterfaces:
Circle, Point, Rectangle
All Known Implementing Classes:
BaseShape, BufferedLine, BufferedLineString, CircleImpl, GeoCircle, JtsGeometry, JtsPoint, PointImpl, RectangleImpl, ShapeCollection

public interface Shape
The base interface defining a geometric shape. Shape instances should be instantiated via one of the create* methods on a SpatialContext or by reading WKT which calls those methods; they should not be created directly.

Shapes are generally immutable and thread-safe. If a particular shape has a reset(...) method then its use means the shape is actually mutable. Mutating shape state is considered expert and should be done with care.

  • Method Details

    • relate

      SpatialRelation relate(Shape other)
      Describe the relationship between the two objects. For example
      • this is WITHIN other
      • this CONTAINS other
      • this is DISJOINT other
      • this INTERSECTS other
      Note that a Shape implementation may choose to return INTERSECTS when the true answer is WITHIN or CONTAINS for performance reasons. If a shape does this then it must document when it does. Ideally the shape will not do this approximation in all circumstances, just sometimes.

      If the shapes are equal then the result is CONTAINS (preferred) or WITHIN.

    • getBoundingBox

      Rectangle getBoundingBox()
      Get the bounding box for this Shape. This means the shape is within the bounding box and that it touches each side of the rectangle.

      Postcondition: this.getBoundingBox().relate(this) == CONTAINS

    • hasArea

      boolean hasArea()
      Does the shape have area? This will be false for points and lines. It will also be false for shapes that normally have area but are constructed in a degenerate case as to not have area (e.g. a circle with 0 radius or rectangle with no height or no width).
    • getArea

      double getArea(SpatialContext ctx)
      Calculates the area of the shape, in square-degrees. If ctx is null then simple Euclidean calculations will be used. This figure can be an estimate.
    • getCenter

      Point getCenter()
      Returns the center point of this shape. This is usually the same as getBoundingBox().getCenter() but it doesn't have to be.

      Postcondition: this.relate(this.getCenter()) == CONTAINS

    • getBuffered

      Shape getBuffered(double distance, SpatialContext ctx)
      Returns a buffered version of this shape. The buffer is usually a rounded-corner buffer, although some shapes might buffer differently. This is an optional operation.
      Returns:
      Not null, and the returned shape should contain the current shape.
    • isEmpty

      boolean isEmpty()
      Shapes can be "empty", which is to say it exists nowhere. The underlying coordinates are typically NaN.
    • equals

      boolean equals(Object other)
      The sub-classes of Shape generally implement the same contract for Object.equals(Object) and Object.hashCode() amongst the same sub-interface type. This means, for example, that multiple Point implementations of different classes are equal if they share the same x & y.
      Overrides:
      equals in class Object
    • getContext

      SpatialContext getContext()
      Get the SpatialContext that created the Shape