Search in sources :

Example 6 with QuadPrefixTree

use of org.apache.lucene.spatial.prefix.tree.QuadPrefixTree in project elasticsearch by elastic.

the class GeoUtilsTests method testPrefixTreeCellSizes.

public void testPrefixTreeCellSizes() {
    assertThat(GeoUtils.EARTH_SEMI_MAJOR_AXIS, equalTo(DistanceUtils.EARTH_EQUATORIAL_RADIUS_KM * 1000));
    assertThat(GeoUtils.quadTreeCellWidth(0), lessThanOrEqualTo(GeoUtils.EARTH_EQUATOR));
    SpatialContext spatialContext = new SpatialContext(true);
    GeohashPrefixTree geohashPrefixTree = new GeohashPrefixTree(spatialContext, GeohashPrefixTree.getMaxLevelsPossible() / 2);
    Cell gNode = geohashPrefixTree.getWorldCell();
    for (int i = 0; i < geohashPrefixTree.getMaxLevels(); i++) {
        double width = GeoUtils.geoHashCellWidth(i);
        double height = GeoUtils.geoHashCellHeight(i);
        double size = GeoUtils.geoHashCellSize(i);
        double degrees = 360.0 * width / GeoUtils.EARTH_EQUATOR;
        int level = GeoUtils.quadTreeLevelsForPrecision(size);
        assertThat(GeoUtils.quadTreeCellWidth(level), lessThanOrEqualTo(width));
        assertThat(GeoUtils.quadTreeCellHeight(level), lessThanOrEqualTo(height));
        assertThat(GeoUtils.geoHashLevelsForPrecision(size), equalTo(geohashPrefixTree.getLevelForDistance(degrees)));
        assertThat("width at level " + i, gNode.getShape().getBoundingBox().getWidth(), equalTo(360.d * width / GeoUtils.EARTH_EQUATOR));
        assertThat("height at level " + i, gNode.getShape().getBoundingBox().getHeight(), equalTo(180.d * height / GeoUtils.EARTH_POLAR_DISTANCE));
        gNode = gNode.getNextLevelCells(null).next();
    }
    QuadPrefixTree quadPrefixTree = new QuadPrefixTree(spatialContext);
    Cell qNode = quadPrefixTree.getWorldCell();
    for (int i = 0; i < quadPrefixTree.getMaxLevels(); i++) {
        double degrees = 360.0 / (1L << i);
        double width = GeoUtils.quadTreeCellWidth(i);
        double height = GeoUtils.quadTreeCellHeight(i);
        double size = GeoUtils.quadTreeCellSize(i);
        int level = GeoUtils.quadTreeLevelsForPrecision(size);
        assertThat(GeoUtils.quadTreeCellWidth(level), lessThanOrEqualTo(width));
        assertThat(GeoUtils.quadTreeCellHeight(level), lessThanOrEqualTo(height));
        assertThat(GeoUtils.quadTreeLevelsForPrecision(size), equalTo(quadPrefixTree.getLevelForDistance(degrees)));
        assertThat("width at level " + i, qNode.getShape().getBoundingBox().getWidth(), equalTo(360.d * width / GeoUtils.EARTH_EQUATOR));
        assertThat("height at level " + i, qNode.getShape().getBoundingBox().getHeight(), equalTo(180.d * height / GeoUtils.EARTH_POLAR_DISTANCE));
        qNode = qNode.getNextLevelCells(null).next();
    }
}
Also used : SpatialContext(org.locationtech.spatial4j.context.SpatialContext) QuadPrefixTree(org.apache.lucene.spatial.prefix.tree.QuadPrefixTree) Cell(org.apache.lucene.spatial.prefix.tree.Cell) GeoPoint(org.elasticsearch.common.geo.GeoPoint) GeohashPrefixTree(org.apache.lucene.spatial.prefix.tree.GeohashPrefixTree)

Example 7 with QuadPrefixTree

use of org.apache.lucene.spatial.prefix.tree.QuadPrefixTree 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 8 with QuadPrefixTree

use of org.apache.lucene.spatial.prefix.tree.QuadPrefixTree in project lucene-solr by apache.

the class PortedSolr3Test method parameters.

@ParametersFactory(argumentFormatting = "strategy=%s")
public static Iterable<Object[]> parameters() {
    List<Object[]> ctorArgs = new ArrayList<>();
    SpatialContext ctx = SpatialContext.GEO;
    SpatialPrefixTree grid;
    SpatialStrategy strategy;
    grid = new GeohashPrefixTree(ctx, 12);
    strategy = new RecursivePrefixTreeStrategy(grid, "recursive_geohash");
    ctorArgs.add(new Object[] { strategy.getFieldName(), strategy });
    grid = new QuadPrefixTree(ctx, 25);
    strategy = new RecursivePrefixTreeStrategy(grid, "recursive_quad");
    ctorArgs.add(new Object[] { strategy.getFieldName(), strategy });
    grid = new GeohashPrefixTree(ctx, 12);
    strategy = new TermQueryPrefixTreeStrategy(grid, "termquery_geohash");
    ctorArgs.add(new Object[] { strategy.getFieldName(), strategy });
    strategy = PointVectorStrategy.newInstance(ctx, "pointvector");
    ctorArgs.add(new Object[] { strategy.getFieldName(), strategy });
    strategy = PointVectorStrategy.newInstance(ctx, "pointvector_legacy");
    ctorArgs.add(new Object[] { strategy.getFieldName(), strategy });
    return ctorArgs;
}
Also used : SpatialContext(org.locationtech.spatial4j.context.SpatialContext) QuadPrefixTree(org.apache.lucene.spatial.prefix.tree.QuadPrefixTree) ArrayList(java.util.ArrayList) RecursivePrefixTreeStrategy(org.apache.lucene.spatial.prefix.RecursivePrefixTreeStrategy) SpatialPrefixTree(org.apache.lucene.spatial.prefix.tree.SpatialPrefixTree) TermQueryPrefixTreeStrategy(org.apache.lucene.spatial.prefix.TermQueryPrefixTreeStrategy) GeohashPrefixTree(org.apache.lucene.spatial.prefix.tree.GeohashPrefixTree) ParametersFactory(com.carrotsearch.randomizedtesting.annotations.ParametersFactory)

Example 9 with QuadPrefixTree

use of org.apache.lucene.spatial.prefix.tree.QuadPrefixTree in project lucene-solr by apache.

the class QueryEqualsHashCodeTest method testEqualsHashCode.

@Test
public void testEqualsHashCode() {
    switch(//0-3
    random().nextInt(4)) {
        case 0:
            predicate = SpatialOperation.Contains;
            break;
        case 1:
            predicate = SpatialOperation.IsWithin;
            break;
        default:
            predicate = SpatialOperation.Intersects;
            break;
    }
    final SpatialPrefixTree gridQuad = new QuadPrefixTree(ctx, 10);
    final SpatialPrefixTree gridGeohash = new GeohashPrefixTree(ctx, 10);
    Collection<SpatialStrategy> strategies = new ArrayList<>();
    RecursivePrefixTreeStrategy recursive_geohash = new RecursivePrefixTreeStrategy(gridGeohash, "recursive_geohash");
    strategies.add(recursive_geohash);
    strategies.add(new TermQueryPrefixTreeStrategy(gridQuad, "termquery_quad"));
    strategies.add(PointVectorStrategy.newInstance(ctx, "pointvector"));
    strategies.add(BBoxStrategy.newInstance(ctx, "bbox"));
    final SerializedDVStrategy serialized = new SerializedDVStrategy(ctx, "serialized");
    strategies.add(serialized);
    strategies.add(new CompositeSpatialStrategy("composite", recursive_geohash, serialized));
    for (SpatialStrategy strategy : strategies) {
        testEqualsHashcode(strategy);
    }
}
Also used : CompositeSpatialStrategy(org.apache.lucene.spatial.composite.CompositeSpatialStrategy) QuadPrefixTree(org.apache.lucene.spatial.prefix.tree.QuadPrefixTree) ArrayList(java.util.ArrayList) RecursivePrefixTreeStrategy(org.apache.lucene.spatial.prefix.RecursivePrefixTreeStrategy) SpatialPrefixTree(org.apache.lucene.spatial.prefix.tree.SpatialPrefixTree) CompositeSpatialStrategy(org.apache.lucene.spatial.composite.CompositeSpatialStrategy) TermQueryPrefixTreeStrategy(org.apache.lucene.spatial.prefix.TermQueryPrefixTreeStrategy) SerializedDVStrategy(org.apache.lucene.spatial.serialized.SerializedDVStrategy) GeohashPrefixTree(org.apache.lucene.spatial.prefix.tree.GeohashPrefixTree) Test(org.junit.Test)

Example 10 with QuadPrefixTree

use of org.apache.lucene.spatial.prefix.tree.QuadPrefixTree in project lucene-solr by apache.

the class HeatmapFacetCounterTest method testLucene7291Dateline.

@Test
public void testLucene7291Dateline() throws IOException {
    // only 2, and we wind up with some big leaf cells
    grid = new QuadPrefixTree(ctx, 2);
    strategy = new RecursivePrefixTreeStrategy(grid, getTestClass().getSimpleName());
    adoc("0", ctx.makeRectangle(-102, -83, 43, 52));
    commit();
    // HM crosses dateline
    validateHeatmapResultLoop(ctx.makeRectangle(179, -179, 62, 63), 2, 100);
}
Also used : QuadPrefixTree(org.apache.lucene.spatial.prefix.tree.QuadPrefixTree) Test(org.junit.Test)

Aggregations

QuadPrefixTree (org.apache.lucene.spatial.prefix.tree.QuadPrefixTree)11 Test (org.junit.Test)5 GeohashPrefixTree (org.apache.lucene.spatial.prefix.tree.GeohashPrefixTree)4 SpatialPrefixTree (org.apache.lucene.spatial.prefix.tree.SpatialPrefixTree)4 SpatialContext (org.locationtech.spatial4j.context.SpatialContext)4 ArrayList (java.util.ArrayList)3 RecursivePrefixTreeStrategy (org.apache.lucene.spatial.prefix.RecursivePrefixTreeStrategy)3 TermQueryPrefixTreeStrategy (org.apache.lucene.spatial.prefix.TermQueryPrefixTreeStrategy)3 SpatialContextFactory (org.locationtech.spatial4j.context.SpatialContextFactory)3 RectangleImpl (org.locationtech.spatial4j.shape.impl.RectangleImpl)3 ParametersFactory (com.carrotsearch.randomizedtesting.annotations.ParametersFactory)2 Document (org.apache.lucene.document.Document)2 Field (org.apache.lucene.document.Field)2 PackedQuadPrefixTree (org.apache.lucene.spatial.prefix.tree.PackedQuadPrefixTree)2 SerializedDVStrategy (org.apache.lucene.spatial.serialized.SerializedDVStrategy)2 Point (org.locationtech.spatial4j.shape.Point)2 Shape (org.locationtech.spatial4j.shape.Shape)2 StoredField (org.apache.lucene.document.StoredField)1 StringField (org.apache.lucene.document.StringField)1 TextField (org.apache.lucene.document.TextField)1