Class SpatialContextFactory
- java.lang.Object
-
- org.locationtech.spatial4j.context.SpatialContextFactory
-
- Direct Known Subclasses:
JtsSpatialContextFactory
public class SpatialContextFactory extends java.lang.Object
Factory for aSpatialContext
based on configuration data. CallmakeSpatialContext(java.util.Map, ClassLoader)
to construct one via String name-value pairs. To construct one via code then create a factory instance, set the fields, then callnewSpatialContext()
.The following keys are looked up in the args map:
- spatialContextFactory
- org.locationtech.spatial4j.context.SpatialContext or org.locationtech.spatial4j.context.jts.JtsSpatialContext
- geo
- true (default)| false -- see
SpatialContext.isGeo()
- shapeFactoryClass
- Java class of the
ShapeFactory
. - distCalculator
- haversine | lawOfCosines | vincentySphere | cartesian | cartesian^2
-- see
DistanceCalculator
- worldBounds
ENVELOPE(xMin, xMax, yMax, yMin)
-- seeSpatialContext.getWorldBounds()
- normWrapLongitude
- true | false (default) -- see
SpatialContext.isNormWrapLongitude()
- readers
- Comma separated list of
ShapeReader
class names - writers
- Comma separated list of
ShapeWriter
class names - binaryCodecClass
- Java class of the
BinaryCodec
-
-
Field Summary
Fields Modifier and Type Field Description protected java.util.Map<java.lang.String,java.lang.String>
args
java.lang.Class<? extends BinaryCodec>
binaryCodecClass
protected java.lang.ClassLoader
classLoader
DistanceCalculator
distCalc
boolean
geo
boolean
hasFormatConfig
boolean
normWrapLongitude
java.util.List<java.lang.Class<? extends ShapeReader>>
readers
java.lang.Class<? extends ShapeFactory>
shapeFactoryClass
Rectangle
worldBounds
java.util.List<java.lang.Class<? extends ShapeWriter>>
writers
-
Constructor Summary
Constructors Constructor Description SpatialContextFactory()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description void
addReaderIfNoggitExists(java.lang.Class<? extends ShapeReader> reader)
protected void
checkDefaultFormats()
If no formats were defined in the config, this will make sure GeoJSON and WKT are registeredprotected void
init(java.util.Map<java.lang.String,java.lang.String> args, java.lang.ClassLoader classLoader)
protected void
initCalculator()
protected void
initField(java.lang.String name)
Getsname
from args and populates a field by the same name with the value.protected void
initFormats()
Check args for 'readers' and 'writers'.protected void
initWorldBounds()
BinaryCodec
makeBinaryCodec(SpatialContext ctx)
private <T> T
makeClassInstance(java.lang.Class<? extends T> clazz, java.lang.Object... ctorArgs)
SupportedFormats
makeFormats(SpatialContext ctx)
ShapeFactory
makeShapeFactory(SpatialContext ctx)
static SpatialContext
makeSpatialContext(java.util.Map<java.lang.String,java.lang.String> args, java.lang.ClassLoader classLoader)
Creates a newSpatialContext
based on configuration inargs
.SpatialContext
newSpatialContext()
Subclasses should simply construct the instance from the initialized configuration.
-
-
-
Field Detail
-
args
protected java.util.Map<java.lang.String,java.lang.String> args
-
classLoader
protected java.lang.ClassLoader classLoader
-
geo
public boolean geo
-
distCalc
public DistanceCalculator distCalc
-
worldBounds
public Rectangle worldBounds
-
normWrapLongitude
public boolean normWrapLongitude
-
shapeFactoryClass
public java.lang.Class<? extends ShapeFactory> shapeFactoryClass
-
binaryCodecClass
public java.lang.Class<? extends BinaryCodec> binaryCodecClass
-
readers
public final java.util.List<java.lang.Class<? extends ShapeReader>> readers
-
writers
public final java.util.List<java.lang.Class<? extends ShapeWriter>> writers
-
hasFormatConfig
public boolean hasFormatConfig
-
-
Method Detail
-
makeSpatialContext
public static SpatialContext makeSpatialContext(java.util.Map<java.lang.String,java.lang.String> args, java.lang.ClassLoader classLoader)
Creates a newSpatialContext
based on configuration inargs
. See the class definition for what keys are looked up in it. The factory class is looked up via "spatialContextFactory" in args then falling back to a Java system property (with initial caps). If neither are specified thenSpatialContextFactory
is chosen.- Parameters:
args
- Non-null map of name-value pairs.classLoader
- Optional, except when a class name is provided to an argument.
-
init
protected void init(java.util.Map<java.lang.String,java.lang.String> args, java.lang.ClassLoader classLoader)
-
initField
protected void initField(java.lang.String name)
Getsname
from args and populates a field by the same name with the value.
-
initCalculator
protected void initCalculator()
-
initFormats
protected void initFormats()
Check args for 'readers' and 'writers'. The value should be a comma separated list of class names. The legacy parameter 'wktShapeParserClass' is also supported to add a specific WKT prarser
-
makeFormats
public SupportedFormats makeFormats(SpatialContext ctx)
-
checkDefaultFormats
protected void checkDefaultFormats()
If no formats were defined in the config, this will make sure GeoJSON and WKT are registered
-
addReaderIfNoggitExists
public void addReaderIfNoggitExists(java.lang.Class<? extends ShapeReader> reader)
-
initWorldBounds
protected void initWorldBounds()
-
newSpatialContext
public SpatialContext newSpatialContext()
Subclasses should simply construct the instance from the initialized configuration.
-
makeShapeFactory
public ShapeFactory makeShapeFactory(SpatialContext ctx)
-
makeBinaryCodec
public BinaryCodec makeBinaryCodec(SpatialContext ctx)
-
makeClassInstance
private <T> T makeClassInstance(java.lang.Class<? extends T> clazz, java.lang.Object... ctorArgs)
-
-