Package org.locationtech.spatial4j.shape
Interface Shape
-
- 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 aSpatialContext
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 Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description boolean
equals(java.lang.Object other)
The sub-classes of Shape generally implement the same contract forObject.equals(Object)
andObject.hashCode()
amongst the same sub-interface type.double
getArea(SpatialContext ctx)
Calculates the area of the shape, in square-degrees.Rectangle
getBoundingBox()
Get the bounding box for this Shape.Shape
getBuffered(double distance, SpatialContext ctx)
Returns a buffered version of this shape.Point
getCenter()
Returns the center point of this shape.SpatialContext
getContext()
Get the SpatialContext that created the Shapeboolean
hasArea()
Does the shape have area? This will be false for points and lines.boolean
isEmpty()
Shapes can be "empty", which is to say it exists nowhere.SpatialRelation
relate(Shape other)
Describe the relationship between the two objects.
-
-
-
Method Detail
-
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
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 asgetBoundingBox().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(java.lang.Object other)
The sub-classes of Shape generally implement the same contract forObject.equals(Object)
andObject.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 classjava.lang.Object
-
getContext
SpatialContext getContext()
Get the SpatialContext that created the Shape
-
-