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
EnhancesShapeFactoryImplwith support for Polygons using JTS. To the extent possible, ourJtsGeometryadds 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 booleanallowMultiOverlapprotected booleanautoIndexprotected DatelineRuledatelineRuleprotected static LinearRing[]EMPTY_HOLESprotected GeometryFactorygeometryFactoryprotected booleanuseJtsLineStringprotected booleanuseJtsMultiprotected booleanuseJtsPointprotected ValidationRulevalidationRule-
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 DatelineRulegetDatelineRule()Returns the rule used to handle geometry objects that have dateline (aka anti-meridian) crossing considerations.GeometryFactorygetGeometryFactory()GeometrygetGeometryFrom(Shape shape)ValidationRulegetValidationRule()Returns the rule used to handle errors when creating a JTSGeometry, particularly after it has been read from one of theShapeReaders.booleanisAllowMultiOverlap()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.booleanisAutoIndex()If JtsGeometry shapes should be automatically "prepared" (i.e.ShapeFactory.LineStringBuilderlineString()(Builder) Constructs a line string, with a possible buffer.ShapelineString(List<Point> points, double bufferDistance)Constructs a line string with a possible buffer.RectanglemakeRectFromRectangularPoly(Geometry geom)INTERNAL: Returns a Rectangle of the JTSEnvelope(bounding box) of the givengeom.JtsGeometrymakeShape(Geometry geom)JtsGeometrymakeShape(Geometry geom, boolean dateline180Check, boolean allowMultiOverlap)INTERNALShapemakeShapeFromGeometry(Geometry geom)INTERNAL Usually creates a JtsGeometry, potentially validating, repairing, and indexing ("preparing").ShapeFactory.MultiLineStringBuildermultiLineString()(Builder) Constructs a MultiLineString, or possibly the result of that buffered.ShapeFactory.MultiPointBuildermultiPoint()(Builder) Constructs a MultiPoint.ShapeFactory.MultiPolygonBuildermultiPolygon()(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.doublenormDist(double d)Called to normalize a value that isn't X or Y or Z.doublenormX(double x)Normalize the 'x' dimension.doublenormY(double y)doublenormZ(double z)(disclaimer: the Z dimension isn't fully supported)PointpointXY(double x, double y)Construct a point.PointpointXYZ(double x, double y, double z)Construct a point of 3 dimensions.ShapeFactory.PolygonBuilderpolygon()(Builder) Constructs a polygon.booleanuseJtsLineString()ShouldlineString(java.util.List,double)returnJtsGeometry?booleanuseJtsMulti()WhethermultiPoint(),multiLineString(), andmultiPolygon()should all use JTS's subclasses ofGeometryCollectioninstead of Spatial4j's basic impl.booleanuseJtsPoint()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 LinearRing[] EMPTY_HOLES
-
geometryFactory
protected final 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 theShapeReaders.
-
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:ShapeFactoryNormalize the 'x' dimension. Might reduce precision or wrap it to be within the bounds. This is called byShapeReaders before creating a shape.- Specified by:
normXin interfaceShapeFactory- Overrides:
normXin classShapeFactoryImpl
-
normY
public double normY(double y)
- Specified by:
normYin interfaceShapeFactory- Overrides:
normYin 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:
normZin interfaceShapeFactory- Overrides:
normZin classShapeFactoryImpl- See Also:
ShapeFactory.normX(double)
-
normDist
public double normDist(double d)
Description copied from interface:ShapeFactoryCalled 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 aShapeReaderbefore creating a shape.- Specified by:
normDistin interfaceShapeFactory- Overrides:
normDistin classShapeFactoryImpl
-
getGeometryFrom
public Geometry getGeometryFrom(Shape shape)
Gets a JTSGeometryfor 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:ShapeFactoryConstruct a point.- Specified by:
pointXYin interfaceShapeFactory- Overrides:
pointXYin classShapeFactoryImpl
-
pointXYZ
public Point pointXYZ(double x, double y, double z)
Description copied from interface:ShapeFactoryConstruct a point of 3 dimensions. The implementation might ignore unsupported dimensions like 'z' or throw an error.- Specified by:
pointXYZin interfaceShapeFactory- Overrides:
pointXYZin classShapeFactoryImpl
-
useJtsLineString
public boolean useJtsLineString()
ShouldlineString(java.util.List,double)returnJtsGeometry?
-
lineString
public Shape lineString(List<Point> points, double bufferDistance)
Description copied from interface:ShapeFactoryConstructs 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:
lineStringin interfaceShapeFactory- Overrides:
lineStringin 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:
lineStringin interfaceShapeFactory- Overrides:
lineStringin 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:
polygonin interfaceShapeFactory- Overrides:
polygonin classShapeFactoryImpl
-
useJtsMulti
public boolean useJtsMulti()
WhethermultiPoint(),multiLineString(), andmultiPolygon()should all use JTS's subclasses ofGeometryCollectioninstead of Spatial4j's basic impl. The generalmultiShape(Class)will never useGeometryCollectionbecause that class doesn't support relations.
-
multiPoint
public ShapeFactory.MultiPointBuilder multiPoint()
Description copied from interface:ShapeFactory(Builder) Constructs a MultiPoint.- Specified by:
multiPointin interfaceShapeFactory- Overrides:
multiPointin classShapeFactoryImpl
-
multiLineString
public ShapeFactory.MultiLineStringBuilder multiLineString()
Description copied from interface:ShapeFactory(Builder) Constructs a MultiLineString, or possibly the result of that buffered.- Specified by:
multiLineStringin interfaceShapeFactory- Overrides:
multiLineStringin classShapeFactoryImpl
-
multiPolygon
public ShapeFactory.MultiPolygonBuilder multiPolygon()
Description copied from interface:ShapeFactory(Builder) Constructs a MultiPolygon.- Specified by:
multiPolygonin interfaceShapeFactory- Overrides:
multiPolygonin 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:
multiShapein interfaceShapeFactory- Overrides:
multiShapein classShapeFactoryImpl
-
makeShapeFromGeometry
public Shape makeShapeFromGeometry(Geometry geom)
INTERNAL Usually creates a JtsGeometry, potentially validating, repairing, and indexing ("preparing"). This method is intended for use byShapeReaderinstances. If given a direct instance ofGeometryCollectionthen it's contents will be recursively converted and then the resulting list will be passed toSpatialContext.makeCollection(List)and returned. If given aPointthenSpatialContext.makePoint(double, double)is called, which will return aJtsPointifJtsSpatialContext.useJtsPoint(); otherwise a standard Spatial4j Point is returned. If given aLineStringand ifJtsSpatialContext.useJtsLineString()is true then then the geometry's parts are exposed to callSpatialContext.makeLineString(List).
-
makeShape
public JtsGeometry makeShape(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(Geometry geom)
INTERNAL: Creates aShapefrom 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 ofGeometryCollectionisn't supported. Instead of calling this method, considermakeShapeFromGeometry(Geometry)which
-
getGeometryFactory
public GeometryFactory getGeometryFactory()
-
makeRectFromRectangularPoly
public Rectangle makeRectFromRectangularPoly(Geometry geom)
INTERNAL: Returns a Rectangle of the JTSEnvelope(bounding box) of the givengeom. This asserts thatGeometry.isRectangle()is true. This method reacts to theDatelineRulesetting.- Parameters:
geom- non-null- Returns:
- the equivalent Rectangle.
-
-