use of org.locationtech.spatial4j.context.SpatialContextFactory in project lucene-solr by apache.
the class RandomSpatialOpFuzzyPrefixTreeTest method setupCtx2D.
private void setupCtx2D(SpatialContext ctx) {
if (!ctx.isGeo())
ctx2D = ctx;
//A non-geo version of ctx.
SpatialContextFactory ctxFactory = new SpatialContextFactory();
ctxFactory.geo = false;
ctxFactory.worldBounds = ctx.getWorldBounds();
ctx2D = ctxFactory.newSpatialContext();
}
use of org.locationtech.spatial4j.context.SpatialContextFactory in project lucene-solr by apache.
the class RandomSpatialOpFuzzyPrefixTreeTest method setupQuadGrid.
private void setupQuadGrid(int maxLevels, boolean packedQuadPrefixTree) {
//non-geospatial makes this test a little easier (in gridSnap), and using boundary values 2^X raises
// the prospect of edge conditions we want to test, plus makes for simpler numbers (no decimals).
SpatialContextFactory factory = new SpatialContextFactory();
factory.geo = false;
factory.worldBounds = new RectangleImpl(0, 256, -128, 128, null);
this.ctx = factory.newSpatialContext();
//A fairly shallow grid, and default 2.5% distErrPct
if (maxLevels == -1)
//max 64k cells (4^8), also 256*256
maxLevels = randomIntBetween(1, 8);
if (packedQuadPrefixTree) {
this.grid = new PackedQuadPrefixTree(ctx, maxLevels);
} else {
this.grid = new QuadPrefixTree(ctx, maxLevels);
}
this.strategy = newRPT();
}
use of org.locationtech.spatial4j.context.SpatialContextFactory in project lucene-solr by apache.
the class HeatmapFacetCounterTest method testQueryCircle.
@Test
public void testQueryCircle() throws IOException {
//overwrite setUp; non-geo bounds is more straight-forward; otherwise 88,88 would actually be practically north,
final SpatialContextFactory spatialContextFactory = new SpatialContextFactory();
spatialContextFactory.geo = false;
spatialContextFactory.worldBounds = new RectangleImpl(-90, 90, -90, 90, null);
ctx = spatialContextFactory.newSpatialContext();
final int LEVEL = 4;
grid = new QuadPrefixTree(ctx, LEVEL);
strategy = new RecursivePrefixTreeStrategy(grid, getTestClass().getSimpleName());
Circle circle = ctx.makeCircle(0, 0, 89);
//top-right, inside bbox of circle but not the circle
adoc("0", ctx.makePoint(88, 88));
//clearly inside; dead center in fact
adoc("1", ctx.makePoint(0, 0));
commit();
final HeatmapFacetCounter.Heatmap heatmap = HeatmapFacetCounter.calcFacets((PrefixTreeStrategy) strategy, indexSearcher.getTopReaderContext(), null, circle, LEVEL, 1000);
//assert that only one point is found, not 2
boolean foundOne = false;
for (int count : heatmap.counts) {
switch(count) {
case 0:
break;
case 1:
//this is the first
assertFalse(foundOne);
foundOne = true;
break;
default:
fail("counts should be 0 or 1: " + count);
}
}
assertTrue(foundOne);
}
use of org.locationtech.spatial4j.context.SpatialContextFactory in project lucene-solr by apache.
the class TestBBoxStrategy method testOperations.
@Test
@Repeat(iterations = 15)
public void testOperations() throws IOException {
//setup
if (random().nextInt(4) > 0) {
//75% of the time choose geo (more interesting to test)
this.ctx = SpatialContext.GEO;
} else {
SpatialContextFactory factory = new SpatialContextFactory();
factory.geo = false;
factory.worldBounds = new RectangleImpl(-300, 300, -100, 100, null);
this.ctx = factory.newSpatialContext();
}
this.strategy = BBoxStrategy.newInstance(ctx, "bbox");
//test we can disable docValues for predicate tests
if (random().nextBoolean()) {
FieldType fieldType = new FieldType(((BBoxStrategy) strategy).getFieldType());
fieldType.setDocValuesType(DocValuesType.NONE);
strategy = new BBoxStrategy(ctx, strategy.getFieldName(), fieldType);
}
for (SpatialOperation operation : SpatialOperation.values()) {
if (operation == SpatialOperation.Overlaps)
//unsupported
continue;
testOperationRandomShapes(operation);
deleteAll();
commit();
}
}
use of org.locationtech.spatial4j.context.SpatialContextFactory in project lucene-solr by apache.
the class CompositeStrategyTest method setupQuadGrid.
private void setupQuadGrid(int maxLevels) {
//non-geospatial makes this test a little easier (in gridSnap), and using boundary values 2^X raises
// the prospect of edge conditions we want to test, plus makes for simpler numbers (no decimals).
SpatialContextFactory factory = new SpatialContextFactory();
factory.geo = false;
factory.worldBounds = new RectangleImpl(0, 256, -128, 128, null);
this.ctx = factory.newSpatialContext();
//A fairly shallow grid
if (maxLevels == -1)
//max 64k cells (4^8), also 256*256
maxLevels = randomIntBetween(1, 8);
this.grid = new QuadPrefixTree(ctx, maxLevels);
this.rptStrategy = newRPT();
}
Aggregations