Search in sources :

Example 1 with SpatialContextFactory

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();
}
Also used : SpatialContextFactory(org.locationtech.spatial4j.context.SpatialContextFactory)

Example 2 with SpatialContextFactory

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();
}
Also used : SpatialContextFactory(org.locationtech.spatial4j.context.SpatialContextFactory) PackedQuadPrefixTree(org.apache.lucene.spatial.prefix.tree.PackedQuadPrefixTree) QuadPrefixTree(org.apache.lucene.spatial.prefix.tree.QuadPrefixTree) RectangleImpl(org.locationtech.spatial4j.shape.impl.RectangleImpl) PackedQuadPrefixTree(org.apache.lucene.spatial.prefix.tree.PackedQuadPrefixTree)

Example 3 with SpatialContextFactory

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);
}
Also used : Circle(org.locationtech.spatial4j.shape.Circle) SpatialContextFactory(org.locationtech.spatial4j.context.SpatialContextFactory) QuadPrefixTree(org.apache.lucene.spatial.prefix.tree.QuadPrefixTree) RectangleImpl(org.locationtech.spatial4j.shape.impl.RectangleImpl) Point(org.locationtech.spatial4j.shape.Point) Test(org.junit.Test)

Example 4 with SpatialContextFactory

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();
    }
}
Also used : SpatialContextFactory(org.locationtech.spatial4j.context.SpatialContextFactory) RectangleImpl(org.locationtech.spatial4j.shape.impl.RectangleImpl) SpatialOperation(org.apache.lucene.spatial.query.SpatialOperation) FieldType(org.apache.lucene.document.FieldType) Test(org.junit.Test) Repeat(com.carrotsearch.randomizedtesting.annotations.Repeat)

Example 5 with SpatialContextFactory

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();
}
Also used : SpatialContextFactory(org.locationtech.spatial4j.context.SpatialContextFactory) QuadPrefixTree(org.apache.lucene.spatial.prefix.tree.QuadPrefixTree) RectangleImpl(org.locationtech.spatial4j.shape.impl.RectangleImpl)

Aggregations

SpatialContextFactory (org.locationtech.spatial4j.context.SpatialContextFactory)6 RectangleImpl (org.locationtech.spatial4j.shape.impl.RectangleImpl)4 QuadPrefixTree (org.apache.lucene.spatial.prefix.tree.QuadPrefixTree)3 Test (org.junit.Test)2 Repeat (com.carrotsearch.randomizedtesting.annotations.Repeat)1 DataOutputStream (java.io.DataOutputStream)1 ByteArrayOutputStream (org.apache.commons.io.output.ByteArrayOutputStream)1 FieldType (org.apache.lucene.document.FieldType)1 PackedQuadPrefixTree (org.apache.lucene.spatial.prefix.tree.PackedQuadPrefixTree)1 SpatialOperation (org.apache.lucene.spatial.query.SpatialOperation)1 Geoshape (org.janusgraph.core.attribute.Geoshape)1 ReadBuffer (org.janusgraph.diskstorage.ReadBuffer)1 DataOutput (org.janusgraph.graphdb.database.serialize.DataOutput)1 Test (org.junit.jupiter.api.Test)1 SpatialContext (org.locationtech.spatial4j.context.SpatialContext)1 BinaryCodec (org.locationtech.spatial4j.io.BinaryCodec)1 Circle (org.locationtech.spatial4j.shape.Circle)1 Point (org.locationtech.spatial4j.shape.Point)1 Shape (org.locationtech.spatial4j.shape.Shape)1