Class JtsSpatialContext


  • public class JtsSpatialContext
    extends SpatialContext
    Enhances the default SpatialContext with support for Polygons (and other geometries) 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.
    • Field Detail

      • geometryFactory

        protected final com.vividsolutions.jts.geom.GeometryFactory geometryFactory
      • allowMultiOverlap

        protected final boolean allowMultiOverlap
      • useJtsPoint

        protected final boolean useJtsPoint
      • useJtsLineString

        protected final boolean useJtsLineString
      • autoIndex

        protected final boolean autoIndex
    • 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 this ShapeCollection.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 JTS Geometry, particularly after it has been read from one of the ShapeReaders.
      • isAutoIndex

        public boolean isAutoIndex()
        If JtsGeometry shapes should be automatically "prepared" (i.e. optimized) when read via from a ShapeReader.
        See Also:
        JtsGeometry.index()
      • normX

        public double normX​(double x)
        Description copied from class: SpatialContext
        Normalize the 'x' dimension. Might reduce precision or wrap it to be within the bounds. This is called by WKTReader before creating a shape.
        Overrides:
        normX in class SpatialContext
      • normY

        public double normY​(double y)
        Description copied from class: SpatialContext
        Normalize the 'y' dimension. Might reduce precision or wrap it to be within the bounds. This is called by WKTReader before creating a shape.
        Overrides:
        normY in class SpatialContext
      • toString

        public String toString​(Shape shape)
        Description copied from class: SpatialContext
        Writes the shape to a String using the old/deprecated LegacyShapeWriter. 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:
        toString in class SpatialContext
        Parameters:
        shape - non-null
        Returns:
        non-null
      • getGeometryFrom

        public com.vividsolutions.jts.geom.Geometry getGeometryFrom​(Shape shape)
        Gets a JTS Geometry for the given Shape. Some shapes hold a JTS geometry whereas new ones must be created for the rest.
        Parameters:
        shape - Not null
        Returns:
        Not null
      • makeLineString

        public Shape makeLineString​(List<Point> points)
        Description copied from class: SpatialContext
        Constructs 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:
        makeLineString in class SpatialContext
      • makeShape

        public JtsGeometry makeShape​(com.vividsolutions.jts.geom.Geometry geom,
                                     boolean dateline180Check,
                                     boolean allowMultiOverlap)
        INTERNAL
        Parameters:
        geom - Non-null
        dateline180Check - if both this is true and SpatialContext.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 - See isAllowMultiOverlap().
        See Also:
        makeShape(com.vividsolutions.jts.geom.Geometry)
      • makeShape

        public JtsGeometry makeShape​(com.vividsolutions.jts.geom.Geometry geom)
        INTERNAL: Creates a Shape from a JTS Geometry. 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 of GeometryCollection isn't supported. Instead of calling this method, consider JtsWKTReader#makeShapeFromGeometry(Geometry) which
      • getGeometryFactory

        public com.vividsolutions.jts.geom.GeometryFactory getGeometryFactory()
      • makeRectFromRectangularPoly

        public Rectangle makeRectFromRectangularPoly​(com.vividsolutions.jts.geom.Geometry geom)
        INTERNAL: Returns a Rectangle of the JTS Envelope (bounding box) of the given geom. This asserts that Geometry.isRectangle() is true. This method reacts to the DatelineRule setting.
        Parameters:
        geom - non-null
        Returns:
        null equivalent Rectangle.