Class JtsGeometry
- java.lang.Object
-
- org.locationtech.spatial4j.shape.BaseShape<JtsSpatialContext>
-
- org.locationtech.spatial4j.shape.jts.JtsGeometry
-
- All Implemented Interfaces:
Shape
public class JtsGeometry extends BaseShape<JtsSpatialContext>
Wraps a JTSGeometry(i.e. may be a polygon or basically anything). JTS does a great deal of the hard work, but there is work here in handling dateline (aka anti-meridian) wrap.
-
-
Field Summary
Fields Modifier and Type Field Description protected PreparedGeometrypreparedGeometrystatic StringSYSPROP_ASSERT_VALIDATESystem property boolean that can disable auto validation in an assert.protected booleanvalidated
-
Constructor Summary
Constructors Constructor Description JtsGeometry(Geometry geom, JtsSpatialContext ctx, boolean dateline180Check, boolean allowMultiOverlap)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description protected RectanglecomputeGeoBBox(Geometry geoms)Givengeomswhich has already been checked for being in world bounds, return the minimal longitude range of the bounding box.booleanequals(Object o)The sub-classes of Shape generally implement the same contract forObject.equals(Object)andObject.hashCode()amongst the same sub-interface type.doublegetArea(SpatialContext ctx)Calculates the area of the shape, in square-degrees.RectanglegetBoundingBox()Get the bounding box for this Shape.JtsGeometrygetBuffered(double distance, SpatialContext ctx)Returns a buffered version of this shape.JtsPointgetCenter()Returns the center point of this shape.GeometrygetGeom()booleanhasArea()Does the shape have area? This will be false for points and lines.inthashCode()voidindex()Adds an index to this class internally to compute spatial relations faster.static SpatialRelationintersectionMatrixToSpatialRelation(IntersectionMatrix matrix)booleanisEmpty()Shapes can be "empty", which is to say it exists nowhere.protected SpatialRelationrelate(Geometry oGeom)SpatialRelationrelate(Circle circle)SpatialRelationrelate(JtsGeometry jtsGeometry)SpatialRelationrelate(Point pt)SpatialRelationrelate(Rectangle rectangle)SpatialRelationrelate(Shape other)Describe the relationship between the two objects.StringtoString()voidvalidate()Validates the shape, throwing a descriptive error if it isn't valid.-
Methods inherited from class org.locationtech.spatial4j.shape.BaseShape
getContext
-
-
-
-
Field Detail
-
SYSPROP_ASSERT_VALIDATE
public static final String SYSPROP_ASSERT_VALIDATE
System property boolean that can disable auto validation in an assert.- See Also:
- Constant Field Values
-
preparedGeometry
protected PreparedGeometry preparedGeometry
-
validated
protected boolean validated
-
-
Constructor Detail
-
JtsGeometry
public JtsGeometry(Geometry geom, JtsSpatialContext ctx, boolean dateline180Check, boolean allowMultiOverlap)
-
-
Method Detail
-
validate
public void validate() throws InvalidShapeExceptionValidates the shape, throwing a descriptive error if it isn't valid. Note that this is usually called automatically by default, but that can be disabled.- Throws:
InvalidShapeException- with descriptive error if the shape isn't valid
-
index
public void index()
Adds an index to this class internally to compute spatial relations faster. In JTS this is called aPreparedGeometry. This isn't done by default because it takes some time to do the optimization, and it uses more memory. Calling this method isn't thread-safe so be careful when this is done. If it was already indexed then nothing happens.
-
isEmpty
public boolean isEmpty()
Description copied from interface:ShapeShapes can be "empty", which is to say it exists nowhere. The underlying coordinates are typically NaN.
-
computeGeoBBox
protected Rectangle computeGeoBBox(Geometry geoms)
Givengeomswhich has already been checked for being in world bounds, return the minimal longitude range of the bounding box.
-
getBuffered
public JtsGeometry getBuffered(double distance, SpatialContext ctx)
Description copied from interface:ShapeReturns 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.
-
hasArea
public boolean hasArea()
Description copied from interface:ShapeDoes 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
public double getArea(SpatialContext ctx)
Description copied from interface:ShapeCalculates 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.
-
getBoundingBox
public Rectangle getBoundingBox()
Description copied from interface:ShapeGet 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
-
getCenter
public JtsPoint getCenter()
Description copied from interface:ShapeReturns 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
-
relate
public SpatialRelation relate(Shape other)
Description copied from interface:ShapeDescribe 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.
-
relate
public SpatialRelation relate(Point pt)
-
relate
public SpatialRelation relate(Rectangle rectangle)
-
relate
public SpatialRelation relate(Circle circle)
-
relate
public SpatialRelation relate(JtsGeometry jtsGeometry)
-
relate
protected SpatialRelation relate(Geometry oGeom)
-
intersectionMatrixToSpatialRelation
public static SpatialRelation intersectionMatrixToSpatialRelation(IntersectionMatrix matrix)
-
equals
public boolean equals(Object o)
Description copied from interface:ShapeThe 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.
-
getGeom
public Geometry getGeom()
-
-