Class JtsShapeFactory
- java.lang.Object
-
- org.locationtech.spatial4j.shape.impl.ShapeFactoryImpl
-
- org.locationtech.spatial4j.shape.jts.JtsShapeFactory
-
- All Implemented Interfaces:
ShapeFactory
public class JtsShapeFactory extends ShapeFactoryImpl
EnhancesShapeFactoryImpl
with support for Polygons using JTS. To the extent possible, ourJtsGeometry
adds some amount of geodetic support over vanilla JTS which only has a Euclidean (flat plane) model.
-
-
Nested Class Summary
-
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
Fields Modifier and Type Field Description protected boolean
allowMultiOverlap
protected boolean
autoIndex
protected DatelineRule
datelineRule
protected static org.locationtech.jts.geom.LinearRing[]
EMPTY_HOLES
protected org.locationtech.jts.geom.GeometryFactory
geometryFactory
protected boolean
useJtsLineString
protected boolean
useJtsMulti
protected boolean
useJtsPoint
protected ValidationRule
validationRule
-
Fields inherited from class org.locationtech.spatial4j.shape.impl.ShapeFactoryImpl
ctx
-
-
Constructor Summary
Constructors Constructor Description JtsShapeFactory(JtsSpatialContext ctx, JtsSpatialContextFactory factory)
Called byJtsSpatialContextFactory.newSpatialContext()
.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description DatelineRule
getDatelineRule()
Returns the rule used to handle geometry objects that have dateline (aka anti-meridian) crossing considerations.org.locationtech.jts.geom.GeometryFactory
getGeometryFactory()
org.locationtech.jts.geom.Geometry
getGeometryFrom(Shape shape)
Gets a JTSGeometry
for the givenShape
.ValidationRule
getValidationRule()
Returns the rule used to handle errors when creating a JTSGeometry
, particularly after it has been read from one of theShapeReader
s.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.boolean
isAutoIndex()
If JtsGeometry shapes should be automatically "prepared" (i.e.ShapeFactory.LineStringBuilder
lineString()
(Builder) Constructs a line string, with a possible buffer.Shape
lineString(List<Point> points, double bufferDistance)
Constructs a line string with a possible buffer.Rectangle
makeRectFromRectangularPoly(org.locationtech.jts.geom.Geometry geom)
INTERNAL: Returns a Rectangle of the JTSEnvelope
(bounding box) of the givengeom
.JtsGeometry
makeShape(org.locationtech.jts.geom.Geometry geom)
INTERNAL: Creates aShape
from a JTSGeometry
.JtsGeometry
makeShape(org.locationtech.jts.geom.Geometry geom, boolean dateline180Check, boolean allowMultiOverlap)
INTERNALShape
makeShapeFromGeometry(org.locationtech.jts.geom.Geometry geom)
INTERNAL Usually creates a JtsGeometry, potentially validating, repairing, and indexing ("preparing").ShapeFactory.MultiLineStringBuilder
multiLineString()
(Builder) Constructs a MultiLineString, or possibly the result of that buffered.ShapeFactory.MultiPointBuilder
multiPoint()
(Builder) Constructs a MultiPoint.ShapeFactory.MultiPolygonBuilder
multiPolygon()
(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)Point
pointXY(double x, double y)
Construct a point.Point
pointXYZ(double x, double y, double z)
Construct a point of 3 dimensions.ShapeFactory.PolygonBuilder
polygon()
(Builder) Constructs a polygon.boolean
useJtsLineString()
ShouldlineString(java.util.List,double)
returnJtsGeometry
?boolean
useJtsMulti()
WhethermultiPoint()
,multiLineString()
, andmultiPolygon()
should all use JTS's subclasses ofGeometryCollection
instead of Spatial4j's basic impl.boolean
useJtsPoint()
ShouldpointXY(double, double)
returnJtsPoint
?-
Methods inherited from class org.locationtech.spatial4j.shape.impl.ShapeFactoryImpl
circle, circle, getSpatialContext, isNormWrapLongitude, multiShape, rect, rect, verifyX, verifyY, verifyZ
-
-
-
-
Field Detail
-
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
protected final DatelineRule datelineRule
-
validationRule
protected final ValidationRule validationRule
-
autoIndex
protected final boolean autoIndex
-
-
Constructor Detail
-
JtsShapeFactory
public JtsShapeFactory(JtsSpatialContext ctx, JtsSpatialContextFactory factory)
Called byJtsSpatialContextFactory.newSpatialContext()
.
-
-
Method Detail
-
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
public DatelineRule getDatelineRule()
Returns the rule used to handle geometry objects that have dateline (aka anti-meridian) crossing considerations.
-
getValidationRule
public ValidationRule 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:
JtsGeometry.index()
-
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:
ShapeFactory.normX(double)
-
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:
ShapeFactory.normX(double)
-
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
public org.locationtech.jts.geom.Geometry getGeometryFrom(Shape shape)
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
public Point pointXY(double x, double y)
Description copied from interface:ShapeFactory
Construct a point.- Specified by:
pointXY
in interfaceShapeFactory
- Overrides:
pointXY
in classShapeFactoryImpl
-
pointXYZ
public Point pointXYZ(double x, double y, double z)
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
public Shape lineString(List<Point> points, double bufferDistance)
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
public ShapeFactory.LineStringBuilder 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
public ShapeFactory.PolygonBuilder 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
public ShapeFactory.MultiPointBuilder multiPoint()
Description copied from interface:ShapeFactory
(Builder) Constructs a MultiPoint.- Specified by:
multiPoint
in interfaceShapeFactory
- Overrides:
multiPoint
in classShapeFactoryImpl
-
multiLineString
public ShapeFactory.MultiLineStringBuilder 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
public ShapeFactory.MultiPolygonBuilder multiPolygon()
Description copied from interface:ShapeFactory
(Builder) Constructs a MultiPolygon.- Specified by:
multiPolygon
in interfaceShapeFactory
- Overrides:
multiPolygon
in classShapeFactoryImpl
-
multiShape
public <T extends Shape> ShapeFactory.MultiShapeBuilder<T> multiShape(Class<T> shapeClass)
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
public Shape makeShapeFromGeometry(org.locationtech.jts.geom.Geometry geom)
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(org.locationtech.jts.geom.Geometry)
-
makeShape
public JtsGeometry makeShape(org.locationtech.jts.geom.Geometry geom)
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
public Rectangle makeRectFromRectangularPoly(org.locationtech.jts.geom.Geometry geom)
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.
-
-