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 classprivate classprivate classprivate classprivate classprivate classJtsShapeFactory.JtsMultiShapeBuilder<T extends Shape>private classNested 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 booleanprotected final booleanprotected final DatelineRuleprotected static final org.locationtech.jts.geom.LinearRing[]protected final org.locationtech.jts.geom.GeometryFactoryprotected final booleanprotected final booleanprotected final booleanprotected final ValidationRuleFields 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.GeometryFactoryorg.locationtech.jts.geom.GeometrygetGeometryFrom(Shape shape) Gets a JTSGeometryfor the givenShape.Returns the rule used to handle errors when creating a JTSGeometry, particularly after it has been read from one of theShapeReaders.booleanIf 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.booleanIf 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 aShapefrom 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.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)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.booleanShouldlineString(java.util.List,double)returnJtsGeometry?booleanWhethermultiPoint(),multiLineString(), andmultiPolygon()should all use JTS's subclasses ofGeometryCollectioninstead of Spatial4j's basic impl.booleanShouldpointXY(double, double)returnJtsPoint?Methods inherited from class org.locationtech.spatial4j.shape.impl.ShapeFactoryImpl
circle, circle, getSpatialContext, isNormWrapLongitude, multiShape, rect, rect, verifyX, verifyY, verifyZMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods 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 theShapeReaders. -
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: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:
-
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:
-
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
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
Description copied from interface:ShapeFactoryConstruct a point.- Specified by:
pointXYin interfaceShapeFactory- Overrides:
pointXYin classShapeFactoryImpl
-
pointXYZ
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
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
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
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
Description copied from interface:ShapeFactory(Builder) Constructs a MultiPoint.- Specified by:
multiPointin interfaceShapeFactory- Overrides:
multiPointin classShapeFactoryImpl
-
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
Description copied from interface:ShapeFactory(Builder) Constructs a MultiPolygon.- Specified by:
multiPolygonin interfaceShapeFactory- Overrides:
multiPolygonin 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:
multiShapein interfaceShapeFactory- Overrides:
multiShapein classShapeFactoryImpl
-
makeShapeFromGeometry
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(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 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 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 theDatelineRulesetting.- Parameters:
geom- non-null- Returns:
- the equivalent Rectangle.
-