Package com.spatial4j.core.context
Class SpatialContext
- java.lang.Object
-
- com.spatial4j.core.context.SpatialContext
-
- Direct Known Subclasses:
JtsSpatialContext
public class SpatialContext extends Object
This is a facade to most of Spatial4j, holding things likeDistanceCalculator,ShapeIO, and acting as a factory for theShapes. If you want a typical geodetic context, just referenceGEO. Otherwise, You should either create and configure aSpatialContextFactoryand then callSpatialContextFactory.newSpatialContext(), OR, callSpatialContextFactory.makeSpatialContext(java.util.Map, ClassLoader)to do this via configuration data. Thread-safe & immutable.
-
-
Field Summary
Fields Modifier and Type Field Description static SpatialContextGEOA popular default SpatialContext implementation for geospatial.
-
Constructor Summary
Constructors Constructor Description SpatialContext(boolean geo)Deprecated.SpatialContext(boolean geo, DistanceCalculator calculator, Rectangle worldBounds)Deprecated.SpatialContext(SpatialContextFactory factory)Called bySpatialContextFactory.newSpatialContext().
-
Method Summary
All Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description doublecalcDistance(Point p, double x2, double y2)Convenience that usesgetDistCalc()doublecalcDistance(Point p, Point p2)Convenience that usesgetDistCalc()BinaryCodecgetBinaryCodec()DistanceCalculatorgetDistCalc()SupportedFormatsgetFormats()WKTReadergetWktShapeParser()Deprecated.RectanglegetWorldBounds()The extent of x & y coordinates should fit within the return'ed rectangle.booleanisGeo()Is the mathematical world model based on a sphere, or is it a flat plane? The word "geodetic" or "geodesic" is sometimes used to refer to the former, and the latter is sometimes referred to as "Euclidean" or "cartesian".booleanisNormWrapLongitude()If true thennormX(double)will wrap longitudes outside of the standard geodetic boundary into it.ShapemakeBufferedLineString(List<Point> points, double buf)Constructs a buffered line string.CirclemakeCircle(double x, double y, double distance)Construct a circle.CirclemakeCircle(Point point, double distance)Construct a circle.<S extends Shape>
ShapeCollection<S>makeCollection(List<S> coll)Construct a ShapeCollection, analogous to an OGC GeometryCollection.ShapemakeLineString(List<Point> points)Constructs a line string.PointmakePoint(double x, double y)Construct a point.RectanglemakeRectangle(double minX, double maxX, double minY, double maxY)Construct a rectangle.RectanglemakeRectangle(Point lowerLeft, Point upperRight)Construct a rectangle.doublenormX(double x)Normalize the 'x' dimension.doublenormY(double y)Normalize the 'y' dimension.ShapereadShape(String value)Deprecated.ShapereadShapeFromWkt(String wkt)Deprecated.StringtoString()StringtoString(Shape shape)Deprecated.voidverifyX(double x)Ensure fits ingetWorldBounds().voidverifyY(double y)Ensure fits ingetWorldBounds().
-
-
-
Field Detail
-
GEO
public static final SpatialContext GEO
A popular default SpatialContext implementation for geospatial.
-
-
Constructor Detail
-
SpatialContext
@Deprecated public SpatialContext(boolean geo, DistanceCalculator calculator, Rectangle worldBounds)
Deprecated.Consider usingSpatialContextFactoryinstead.- Parameters:
geo- Establishes geo vs cartesian / Euclidean.calculator- Optional; defaults to haversine or cartesian depending ongeo.worldBounds- Optional; defaults to GEO_WORLDBOUNDS or MAX_WORLDBOUNDS depending on units.
-
SpatialContext
@Deprecated public SpatialContext(boolean geo)
Deprecated.
-
SpatialContext
public SpatialContext(SpatialContextFactory factory)
Called bySpatialContextFactory.newSpatialContext().
-
-
Method Detail
-
getFormats
public SupportedFormats getFormats()
-
getDistCalc
public DistanceCalculator getDistCalc()
-
calcDistance
public double calcDistance(Point p, double x2, double y2)
Convenience that usesgetDistCalc()
-
calcDistance
public double calcDistance(Point p, Point p2)
Convenience that usesgetDistCalc()
-
getWorldBounds
public Rectangle getWorldBounds()
The extent of x & y coordinates should fit within the return'ed rectangle. Do *NOT* invoke reset() on this return type.
-
isNormWrapLongitude
public boolean isNormWrapLongitude()
If true thennormX(double)will wrap longitudes outside of the standard geodetic boundary into it. Example: 181 will become -179.
-
isGeo
public boolean isGeo()
Is the mathematical world model based on a sphere, or is it a flat plane? The word "geodetic" or "geodesic" is sometimes used to refer to the former, and the latter is sometimes referred to as "Euclidean" or "cartesian".
-
normX
public double normX(double x)
Normalize the 'x' dimension. Might reduce precision or wrap it to be within the bounds. This is called byWKTReaderbefore creating a shape.
-
normY
public double normY(double y)
Normalize the 'y' dimension. Might reduce precision or wrap it to be within the bounds. This is called byWKTReaderbefore creating a shape.
-
verifyX
public void verifyX(double x)
Ensure fits ingetWorldBounds(). It's called by any shape factory method that gets an 'x' dimension.
-
verifyY
public void verifyY(double y)
Ensure fits ingetWorldBounds(). It's called by any shape factory method that gets a 'y' dimension.
-
makePoint
public Point makePoint(double x, double y)
Construct a point.
-
makeRectangle
public Rectangle makeRectangle(Point lowerLeft, Point upperRight)
Construct a rectangle.
-
makeRectangle
public Rectangle makeRectangle(double minX, double maxX, double minY, double maxY)
Construct a rectangle. If just one longitude is on the dateline (+/- 180) then potentially adjust its sign to ensure the rectangle does not cross the dateline.
-
makeCircle
public Circle makeCircle(double x, double y, double distance)
Construct a circle. The units of "distance" should be the same as x & y.
-
makeCircle
public Circle makeCircle(Point point, double distance)
Construct a circle. The units of "distance" should be the same as x & y.
-
makeLineString
public Shape makeLineString(List<Point> points)
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.
-
makeBufferedLineString
public Shape makeBufferedLineString(List<Point> points, double buf)
Constructs a buffered line string. 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.
-
makeCollection
public <S extends Shape> ShapeCollection<S> makeCollection(List<S> coll)
Construct a ShapeCollection, analogous to an OGC GeometryCollection.
-
getWktShapeParser
@Deprecated public WKTReader getWktShapeParser()
Deprecated.TheWKTReaderused byreadShapeFromWkt(String).
-
readShapeFromWkt
@Deprecated public Shape readShapeFromWkt(String wkt) throws ParseException, InvalidShapeException
Deprecated.Reads a shape from the string formatted in WKT.- Parameters:
wkt- non-null WKT.- Returns:
- non-null
- Throws:
ParseException- if it failed to parse.InvalidShapeException- See Also:
WKTReader
-
getBinaryCodec
public BinaryCodec getBinaryCodec()
-
readShape
@Deprecated public Shape readShape(String value) throws InvalidShapeException
Deprecated.Try to read a shape from any supported formats- Parameters:
value-- Returns:
- shape or null if unable to parse any shape
- Throws:
InvalidShapeException
-
toString
@Deprecated public String toString(Shape shape)
Deprecated.Writes 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.- Parameters:
shape- non-null- Returns:
- non-null
-
-