package org.apache.lucene.spatial.spatial4j;
import java.util.Map;
import org.apache.lucene.spatial3d.geom.PlanetModel;
import org.locationtech.spatial4j.context.SpatialContext;
import org.locationtech.spatial4j.context.SpatialContextFactory;
public class Geo3dSpatialContextFactory extends SpatialContextFactory {
private static final PlanetModel DEFAULT_PLANET_MODEL = PlanetModel.SPHERE;
public PlanetModel planetModel;
public Geo3dSpatialContextFactory() {
this.binaryCodecClass = Geo3dBinaryCodec.class;
this.shapeFactoryClass = Geo3dShapeFactory.class;
}
@Override
public SpatialContext newSpatialContext() {
if (planetModel == null) {
planetModel = DEFAULT_PLANET_MODEL;
}
if (distCalc == null) {
this.distCalc = new Geo3dDistanceCalculator(planetModel);
}
return new SpatialContext(this);
}
@Override
protected void init(Map<String, String> args, ClassLoader classLoader) {
initPlanetModel(args);
super.init(args, classLoader);
}
protected void initPlanetModel(Map<String, String> args) {
String planetModel = args.get("planetModel");
if (planetModel != null) {
if (planetModel.equalsIgnoreCase("sphere")) {
this.planetModel = PlanetModel.SPHERE;
} else if (planetModel.equalsIgnoreCase("wgs84")) {
this.planetModel = PlanetModel.WGS84;
} else {
throw new RuntimeException("Unknown planet model: " + planetModel);
}
} else {
this.planetModel = DEFAULT_PLANET_MODEL;
}
}
@Override
protected void initCalculator() {
String calcStr = this.args.get("distCalculator");
if (calcStr == null) {
return;
} else if (calcStr.equals("geo3d")) {
this.distCalc = new Geo3dDistanceCalculator(planetModel);
} else {
super.initCalculator();
}
}
}