Class JtsShapeFactory
java.lang.Object
org.locationtech.spatial4j.shape.impl.ShapeFactoryImpl
org.locationtech.spatial4j.shape.jts.JtsShapeFactory
- All Implemented Interfaces:
ShapeFactory
Enhances
ShapeFactoryImpl
with support for Polygons
using JTS.
To the extent possible, our JtsGeometry
adds some amount of geodetic support over
vanilla JTS which only has a Euclidean (flat plane) model.-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprivate class
private class
private class
private class
private class
private class
JtsShapeFactory.JtsMultiShapeBuilder<T extends Shape>
private class
Nested classes/interfaces inherited from class org.locationtech.spatial4j.shape.impl.ShapeFactoryImpl
ShapeFactoryImpl.GeneralShapeMultiShapeBuilder<T extends Shape>
Nested classes/interfaces inherited from interface org.locationtech.spatial4j.shape.ShapeFactory
ShapeFactory.LineStringBuilder, ShapeFactory.MultiLineStringBuilder, ShapeFactory.MultiPointBuilder, ShapeFactory.MultiPolygonBuilder, ShapeFactory.MultiShapeBuilder<T extends Shape>, ShapeFactory.PointsBuilder<T>, ShapeFactory.PolygonBuilder
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected final boolean
protected final boolean
protected final DatelineRule
protected static final org.locationtech.jts.geom.LinearRing[]
protected final org.locationtech.jts.geom.GeometryFactory
protected final boolean
protected final boolean
protected final boolean
protected final ValidationRule
Fields inherited from class org.locationtech.spatial4j.shape.impl.ShapeFactoryImpl
ctx
-
Constructor Summary
ConstructorsConstructorDescriptionJtsShapeFactory
(JtsSpatialContext ctx, JtsSpatialContextFactory factory) Called byJtsSpatialContextFactory.newSpatialContext()
. -
Method Summary
Modifier and TypeMethodDescriptionReturns the rule used to handle geometry objects that have dateline (aka anti-meridian) crossing considerations.org.locationtech.jts.geom.GeometryFactory
org.locationtech.jts.geom.Geometry
getGeometryFrom
(Shape shape) Gets a JTSGeometry
for the givenShape
.Returns the rule used to handle errors when creating a JTSGeometry
, particularly after it has been read from one of theShapeReader
s.boolean
If geom might be a multi geometry of some kind, then might multiple component geometries overlap? Strict OGC says this is invalid but we can accept it by computing the union.boolean
If JtsGeometry shapes should be automatically "prepared" (i.e.(Builder) Constructs a line string, with a possible buffer.lineString
(List<Point> points, double bufferDistance) Constructs a line string with a possible buffer.makeRectFromRectangularPoly
(org.locationtech.jts.geom.Geometry geom) INTERNAL: Returns a Rectangle of the JTSEnvelope
(bounding box) of the givengeom
.makeShape
(org.locationtech.jts.geom.Geometry geom) INTERNAL: Creates aShape
from a JTSGeometry
.makeShape
(org.locationtech.jts.geom.Geometry geom, boolean dateline180Check, boolean allowMultiOverlap) INTERNALmakeShapeFromGeometry
(org.locationtech.jts.geom.Geometry geom) INTERNAL Usually creates a JtsGeometry, potentially validating, repairing, and indexing ("preparing").(Builder) Constructs a MultiLineString, or possibly the result of that buffered.(Builder) Constructs a MultiPoint.(Builder) Constructs a MultiPolygon.<T extends Shape>
ShapeFactory.MultiShapeBuilder<T> multiShape
(Class<T> shapeClass) (Builder) Constructs a Shape aggregate in which each component/member is an instance of the specified class.double
normDist
(double d) Called to normalize a value that isn't X or Y or Z.double
normX
(double x) Normalize the 'x' dimension.double
normY
(double y) double
normZ
(double z) (disclaimer: the Z dimension isn't fully supported)pointXY
(double x, double y) Construct a point.pointXYZ
(double x, double y, double z) Construct a point of 3 dimensions.polygon()
(Builder) Constructs a polygon.boolean
ShouldlineString(java.util.List,double)
returnJtsGeometry
?boolean
WhethermultiPoint()
,multiLineString()
, andmultiPolygon()
should all use JTS's subclasses ofGeometryCollection
instead of Spatial4j's basic impl.boolean
ShouldpointXY(double, double)
returnJtsPoint
?Methods inherited from class org.locationtech.spatial4j.shape.impl.ShapeFactoryImpl
circle, circle, getSpatialContext, isNormWrapLongitude, multiShape, rect, rect, verifyX, verifyY, verifyZ
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface org.locationtech.spatial4j.shape.ShapeFactory
pointLatLon
-
Field Details
-
EMPTY_HOLES
protected static final org.locationtech.jts.geom.LinearRing[] EMPTY_HOLES -
geometryFactory
protected final org.locationtech.jts.geom.GeometryFactory geometryFactory -
allowMultiOverlap
protected final boolean allowMultiOverlap -
useJtsPoint
protected final boolean useJtsPoint -
useJtsLineString
protected final boolean useJtsLineString -
useJtsMulti
protected final boolean useJtsMulti -
datelineRule
-
validationRule
-
autoIndex
protected final boolean autoIndex
-
-
Constructor Details
-
JtsShapeFactory
Called byJtsSpatialContextFactory.newSpatialContext()
.
-
-
Method Details
-
isAllowMultiOverlap
public boolean isAllowMultiOverlap()If geom might be a multi geometry of some kind, then might multiple component geometries overlap? Strict OGC says this is invalid but we can accept it by computing the union. Note: Our ShapeCollection mostly doesn't care but it has a method related to thisShapeCollection.relateContainsShortCircuits()
. -
getDatelineRule
Returns the rule used to handle geometry objects that have dateline (aka anti-meridian) crossing considerations. -
getValidationRule
Returns the rule used to handle errors when creating a JTSGeometry
, particularly after it has been read from one of theShapeReader
s. -
isAutoIndex
public boolean isAutoIndex()If JtsGeometry shapes should be automatically "prepared" (i.e. optimized) when read via from aShapeReader
.- See Also:
-
normX
public double normX(double x) Description copied from interface:ShapeFactory
Normalize the 'x' dimension. Might reduce precision or wrap it to be within the bounds. This is called byShapeReader
s before creating a shape.- Specified by:
normX
in interfaceShapeFactory
- Overrides:
normX
in classShapeFactoryImpl
-
normY
public double normY(double y) - Specified by:
normY
in interfaceShapeFactory
- Overrides:
normY
in classShapeFactoryImpl
- See Also:
-
normZ
public double normZ(double z) Description copied from interface:ShapeFactory
(disclaimer: the Z dimension isn't fully supported)- Specified by:
normZ
in interfaceShapeFactory
- Overrides:
normZ
in classShapeFactoryImpl
- See Also:
-
normDist
public double normDist(double d) Description copied from interface:ShapeFactory
Called to normalize a value that isn't X or Y or Z. X & Y & Z are normalized viaSpatialContext.normX(double)
& normY & normZ. This is called by aShapeReader
before creating a shape.- Specified by:
normDist
in interfaceShapeFactory
- Overrides:
normDist
in classShapeFactoryImpl
-
getGeometryFrom
Gets a JTSGeometry
for the givenShape
. Some shapes hold a JTS geometry whereas new ones must be created for the rest.- Parameters:
shape
- Not null- Returns:
- Not null
-
useJtsPoint
public boolean useJtsPoint()ShouldpointXY(double, double)
returnJtsPoint
? -
pointXY
Description copied from interface:ShapeFactory
Construct a point.- Specified by:
pointXY
in interfaceShapeFactory
- Overrides:
pointXY
in classShapeFactoryImpl
-
pointXYZ
Description copied from interface:ShapeFactory
Construct a point of 3 dimensions. The implementation might ignore unsupported dimensions like 'z' or throw an error.- Specified by:
pointXYZ
in interfaceShapeFactory
- Overrides:
pointXYZ
in classShapeFactoryImpl
-
useJtsLineString
public boolean useJtsLineString()ShouldlineString(java.util.List,double)
returnJtsGeometry
? -
lineString
Description copied from interface:ShapeFactory
Constructs a line string with a possible buffer. It's an ordered sequence of connected vertexes, with a buffer distance along the line in all directions. There is no official shape/interface for it so we just return Shape.- Specified by:
lineString
in interfaceShapeFactory
- Overrides:
lineString
in classShapeFactoryImpl
-
lineString
Description copied from interface:ShapeFactory
(Builder) Constructs a line string, with a possible buffer. It's an ordered sequence of connected vertexes. There is no official shape/interface for it yet so we just return Shape.- Specified by:
lineString
in interfaceShapeFactory
- Overrides:
lineString
in classShapeFactoryImpl
-
polygon
Description copied from interface:ShapeFactory
(Builder) Constructs a polygon. There is no official shape/interface for it yet so we just return Shape.- Specified by:
polygon
in interfaceShapeFactory
- Overrides:
polygon
in classShapeFactoryImpl
-
useJtsMulti
public boolean useJtsMulti()WhethermultiPoint()
,multiLineString()
, andmultiPolygon()
should all use JTS's subclasses ofGeometryCollection
instead of Spatial4j's basic impl. The generalmultiShape(Class)
will never useGeometryCollection
because that class doesn't support relations. -
multiPoint
Description copied from interface:ShapeFactory
(Builder) Constructs a MultiPoint.- Specified by:
multiPoint
in interfaceShapeFactory
- Overrides:
multiPoint
in classShapeFactoryImpl
-
multiLineString
Description copied from interface:ShapeFactory
(Builder) Constructs a MultiLineString, or possibly the result of that buffered.- Specified by:
multiLineString
in interfaceShapeFactory
- Overrides:
multiLineString
in classShapeFactoryImpl
-
multiPolygon
Description copied from interface:ShapeFactory
(Builder) Constructs a MultiPolygon.- Specified by:
multiPolygon
in interfaceShapeFactory
- Overrides:
multiPolygon
in classShapeFactoryImpl
-
multiShape
Description copied from interface:ShapeFactory
(Builder) Constructs a Shape aggregate in which each component/member is an instance of the specified class.- Specified by:
multiShape
in interfaceShapeFactory
- Overrides:
multiShape
in classShapeFactoryImpl
-
makeShapeFromGeometry
INTERNAL Usually creates a JtsGeometry, potentially validating, repairing, and indexing ("preparing"). This method is intended for use byShapeReader
instances. If given a direct instance ofGeometryCollection
then it's contents will be recursively converted and then the resulting list will be passed toSpatialContext.makeCollection(List)
and returned. If given aPoint
thenSpatialContext.makePoint(double, double)
is called, which will return aJtsPoint
ifJtsSpatialContext.useJtsPoint()
; otherwise a standard Spatial4j Point is returned. If given aLineString
and ifJtsSpatialContext.useJtsLineString()
is true then then the geometry's parts are exposed to callSpatialContext.makeLineString(List)
. -
makeShape
public JtsGeometry makeShape(org.locationtech.jts.geom.Geometry geom, boolean dateline180Check, boolean allowMultiOverlap) INTERNAL- Parameters:
geom
- Non-nulldateline180Check
- if both this is true andSpatialContext.isGeo()
, then JtsGeometry will check for adjacent coordinates greater than 180 degrees longitude apart, and it will do tricks to make that line segment (and the shape as a whole) cross the dateline even though JTS doesn't have geodetic support.allowMultiOverlap
- SeeisAllowMultiOverlap()
.- See Also:
-
makeShape
INTERNAL: Creates aShape
from a JTSGeometry
. Generally, this shouldn't be called when one of the other factory methods are available, such as for points. The caller needs to have done some verification/normalization of the coordinates by now, if any. Also, note that direct instances ofGeometryCollection
isn't supported. Instead of calling this method, considermakeShapeFromGeometry(Geometry)
which -
getGeometryFactory
public org.locationtech.jts.geom.GeometryFactory getGeometryFactory() -
makeRectFromRectangularPoly
INTERNAL: Returns a Rectangle of the JTSEnvelope
(bounding box) of the givengeom
. This asserts thatGeometry.isRectangle()
is true. This method reacts to theDatelineRule
setting.- Parameters:
geom
- non-null- Returns:
- the equivalent Rectangle.
-