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 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 Summary
Modifier and TypeMethodDescriptionboolean
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.Get the bounding box for this Shape.getBuffered
(double distance, SpatialContext ctx) Returns a buffered version of this shape.Returns the center point of this shape.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.Describe the relationship between the two objects.
-
Method Details
-
relate
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
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
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
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. -
getContext
SpatialContext getContext()Get the SpatialContext that created the Shape
-