Package com.spatial4j.core.context.jts
Class JtsSpatialContext
- java.lang.Object
-
- com.spatial4j.core.context.SpatialContext
-
- com.spatial4j.core.context.jts.JtsSpatialContext
-
public class JtsSpatialContext extends SpatialContext
Enhances the defaultSpatialContextwith support for Polygons (and other geometries) using JTS. To the extent possible, ourJtsGeometryadds some amount of geodetic support over vanilla JTS which only has a Euclidean (flat plane) model.
-
-
Field Summary
Fields Modifier and Type Field Description protected booleanallowMultiOverlapprotected booleanautoIndexprotected DatelineRuledatelineRulestatic JtsSpatialContextGEOprotected com.vividsolutions.jts.geom.GeometryFactorygeometryFactoryprotected booleanuseJtsLineStringprotected booleanuseJtsPointprotected ValidationRulevalidationRule
-
Constructor Summary
Constructors Constructor Description JtsSpatialContext(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 crossing considerations.com.vividsolutions.jts.geom.GeometryFactorygetGeometryFactory()com.vividsolutions.jts.geom.GeometrygetGeometryFrom(Shape shape)Gets a JTSGeometryfor the givenShape.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.ShapemakeLineString(List<Point> points)Constructs a line string.PointmakePoint(double x, double y)Construct a point.RectanglemakeRectFromRectangularPoly(com.vividsolutions.jts.geom.Geometry geom)INTERNAL: Returns a Rectangle of the JTSEnvelope(bounding box) of the givengeom.JtsGeometrymakeShape(com.vividsolutions.jts.geom.Geometry geom)INTERNAL: Creates aShapefrom a JTSGeometry.JtsGeometrymakeShape(com.vividsolutions.jts.geom.Geometry geom, boolean dateline180Check, boolean allowMultiOverlap)INTERNALShapemakeShapeFromGeometry(com.vividsolutions.jts.geom.Geometry geom)INTERNAL Usually creates a JtsGeometry, potentially validating, repairing, and indexing ("preparing").doublenormX(double x)Normalize the 'x' dimension.doublenormY(double y)Normalize the 'y' dimension.StringtoString()StringtoString(Shape shape)Writes the shape to a String using the old/deprecatedLegacyShapeWriter.booleanuseJtsLineString()ShouldmakeLineString(java.util.List)returnJtsGeometry?booleanuseJtsPoint()ShouldmakePoint(double, double)returnJtsPoint?-
Methods inherited from class com.spatial4j.core.context.SpatialContext
calcDistance, calcDistance, getBinaryCodec, getDistCalc, getFormats, getWktShapeParser, getWorldBounds, isGeo, isNormWrapLongitude, makeBufferedLineString, makeCircle, makeCircle, makeCollection, makeRectangle, makeRectangle, readShape, readShapeFromWkt, verifyX, verifyY
-
-
-
-
Field Detail
-
GEO
public static final JtsSpatialContext GEO
-
geometryFactory
protected final com.vividsolutions.jts.geom.GeometryFactory geometryFactory
-
allowMultiOverlap
protected final boolean allowMultiOverlap
-
useJtsPoint
protected final boolean useJtsPoint
-
useJtsLineString
protected final boolean useJtsLineString
-
datelineRule
protected final DatelineRule datelineRule
-
validationRule
protected final ValidationRule validationRule
-
autoIndex
protected final boolean autoIndex
-
-
Constructor Detail
-
JtsSpatialContext
public JtsSpatialContext(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 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 class:SpatialContextNormalize the 'x' dimension. Might reduce precision or wrap it to be within the bounds. This is called byWKTReaderbefore creating a shape.- Overrides:
normXin classSpatialContext
-
normY
public double normY(double y)
Description copied from class:SpatialContextNormalize the 'y' dimension. Might reduce precision or wrap it to be within the bounds. This is called byWKTReaderbefore creating a shape.- Overrides:
normYin classSpatialContext
-
toString
public String toString(Shape shape)
Description copied from class:SpatialContextWrites the shape to a String using the old/deprecatedLegacyShapeWriter. The JTS based subclass will write it to WKT if the legacy format doesn't support that shape. Spatial4j in the near future won't support writing shapes to strings.- Overrides:
toStringin classSpatialContext- Parameters:
shape- non-null- Returns:
- non-null
-
getGeometryFrom
public com.vividsolutions.jts.geom.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()
ShouldmakePoint(double, double)returnJtsPoint?
-
makePoint
public Point makePoint(double x, double y)
Description copied from class:SpatialContextConstruct a point.- Overrides:
makePointin classSpatialContext
-
useJtsLineString
public boolean useJtsLineString()
ShouldmakeLineString(java.util.List)returnJtsGeometry?
-
makeLineString
public Shape makeLineString(List<Point> points)
Description copied from class:SpatialContextConstructs a line string. It's an ordered sequence of connected vertexes. There is no official shape/interface for it yet so we just return Shape.- Overrides:
makeLineStringin classSpatialContext
-
makeShapeFromGeometry
public Shape makeShapeFromGeometry(com.vividsolutions.jts.geom.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 aJtsPointifuseJtsPoint(); otherwise a standard Spatial4j Point is returned. If given aLineStringand ifuseJtsLineString()is true then then the geometry's parts are exposed to callSpatialContext.makeLineString(List).
-
makeShape
public JtsGeometry makeShape(com.vividsolutions.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(com.vividsolutions.jts.geom.Geometry)
-
makeShape
public JtsGeometry makeShape(com.vividsolutions.jts.geom.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, considerJtsWKTReader#makeShapeFromGeometry(Geometry)which
-
getGeometryFactory
public com.vividsolutions.jts.geom.GeometryFactory getGeometryFactory()
-
toString
public String toString()
- Overrides:
toStringin classSpatialContext
-
makeRectFromRectangularPoly
public Rectangle makeRectFromRectangularPoly(com.vividsolutions.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 theDatelineRulesetting.- Parameters:
geom- non-null- Returns:
- null equivalent Rectangle.
-
-