Search in sources :

Example 1 with RectangleImpl

use of org.locationtech.spatial4j.shape.impl.RectangleImpl 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 2 with RectangleImpl

use of org.locationtech.spatial4j.shape.impl.RectangleImpl 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 3 with RectangleImpl

use of org.locationtech.spatial4j.shape.impl.RectangleImpl 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 4 with RectangleImpl

use of org.locationtech.spatial4j.shape.impl.RectangleImpl 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)

Example 5 with RectangleImpl

use of org.locationtech.spatial4j.shape.impl.RectangleImpl in project lucene-solr by apache.

the class Geo3dShape method getBoundingBox.

@Override
public Rectangle getBoundingBox() {
    //volatile read once
    Rectangle bbox = this.boundingBox;
    if (bbox == null) {
        LatLonBounds bounds = new LatLonBounds();
        shape.getBounds(bounds);
        double leftLon;
        double rightLon;
        if (bounds.checkNoLongitudeBound()) {
            leftLon = -180.0;
            rightLon = 180.0;
        } else {
            leftLon = bounds.getLeftLongitude().doubleValue() * DistanceUtils.RADIANS_TO_DEGREES;
            rightLon = bounds.getRightLongitude().doubleValue() * DistanceUtils.RADIANS_TO_DEGREES;
        }
        double minLat;
        if (bounds.checkNoBottomLatitudeBound()) {
            minLat = -90.0;
        } else {
            minLat = bounds.getMinLatitude().doubleValue() * DistanceUtils.RADIANS_TO_DEGREES;
        }
        double maxLat;
        if (bounds.checkNoTopLatitudeBound()) {
            maxLat = 90.0;
        } else {
            maxLat = bounds.getMaxLatitude().doubleValue() * DistanceUtils.RADIANS_TO_DEGREES;
        }
        bbox = new RectangleImpl(leftLon, rightLon, minLat, maxLat, ctx).getBuffered(ROUNDOFF_ADJUSTMENT, ctx);
        this.boundingBox = bbox;
    }
    return bbox;
}
Also used : Rectangle(org.locationtech.spatial4j.shape.Rectangle) RectangleImpl(org.locationtech.spatial4j.shape.impl.RectangleImpl) LatLonBounds(org.apache.lucene.spatial3d.geom.LatLonBounds)

Aggregations

RectangleImpl (org.locationtech.spatial4j.shape.impl.RectangleImpl)5 SpatialContextFactory (org.locationtech.spatial4j.context.SpatialContextFactory)4 QuadPrefixTree (org.apache.lucene.spatial.prefix.tree.QuadPrefixTree)3 Test (org.junit.Test)2 Repeat (com.carrotsearch.randomizedtesting.annotations.Repeat)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 LatLonBounds (org.apache.lucene.spatial3d.geom.LatLonBounds)1 Circle (org.locationtech.spatial4j.shape.Circle)1 Point (org.locationtech.spatial4j.shape.Point)1 Rectangle (org.locationtech.spatial4j.shape.Rectangle)1