Search in sources :

Example 16 with Rectangle

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

the class HeatmapFacetCounterTest method validateHeatmapResult.

private void validateHeatmapResult(Rectangle inputRange, int facetLevel, HeatmapFacetCounter.Heatmap heatmap) throws IOException {
    final Rectangle heatRect = heatmap.region;
    assertTrue(heatRect.relate(inputRange) == SpatialRelation.CONTAINS || heatRect.equals(inputRange));
    final double cellWidth = heatRect.getWidth() / heatmap.columns;
    final double cellHeight = heatRect.getHeight() / heatmap.rows;
    for (int c = 0; c < heatmap.columns; c++) {
        for (int r = 0; r < heatmap.rows; r++) {
            final int facetCount = heatmap.getCount(c, r);
            double x = DistanceUtils.normLonDEG(heatRect.getMinX() + c * cellWidth + cellWidth / 2);
            double y = DistanceUtils.normLatDEG(heatRect.getMinY() + r * cellHeight + cellHeight / 2);
            Point pt = ctx.makePoint(x, y);
            assertEquals(countMatchingDocsAtLevel(pt, facetLevel), facetCount);
        }
    }
}
Also used : Rectangle(org.locationtech.spatial4j.shape.Rectangle) Point(org.locationtech.spatial4j.shape.Point) Point(org.locationtech.spatial4j.shape.Point)

Example 17 with Rectangle

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

the class Geo3dRptTest method testFailure1.

@Test
public void testFailure1() throws IOException {
    setupStrategy();
    final List<GeoPoint> points = new ArrayList<GeoPoint>();
    points.add(new GeoPoint(PlanetModel.SPHERE, 18 * DEGREES_TO_RADIANS, -27 * DEGREES_TO_RADIANS));
    points.add(new GeoPoint(PlanetModel.SPHERE, -57 * DEGREES_TO_RADIANS, 146 * DEGREES_TO_RADIANS));
    points.add(new GeoPoint(PlanetModel.SPHERE, 14 * DEGREES_TO_RADIANS, -180 * DEGREES_TO_RADIANS));
    points.add(new GeoPoint(PlanetModel.SPHERE, -15 * DEGREES_TO_RADIANS, 153 * DEGREES_TO_RADIANS));
    final Shape triangle = new Geo3dShape(GeoPolygonFactory.makeGeoPolygon(PlanetModel.SPHERE, points), ctx);
    final Rectangle rect = ctx.makeRectangle(-49, -45, 73, 86);
    testOperation(rect, SpatialOperation.Intersects, triangle, false);
}
Also used : GeoPoint(org.apache.lucene.spatial3d.geom.GeoPoint) GeoShape(org.apache.lucene.spatial3d.geom.GeoShape) Shape(org.locationtech.spatial4j.shape.Shape) ArrayList(java.util.ArrayList) Rectangle(org.locationtech.spatial4j.shape.Rectangle) Test(org.junit.Test)

Example 18 with Rectangle

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

the class RandomizedShapeTestCase method divisible.

/** reset()'s p, and confines to world bounds. Might not be divisible if
   * the world bound isn't divisible too.
   */
protected Point divisible(Point p) {
    Rectangle bounds = ctx.getWorldBounds();
    double newX = boundX(divisible(p.getX()), bounds);
    double newY = boundY(divisible(p.getY()), bounds);
    p.reset(newX, newY);
    return p;
}
Also used : Rectangle(org.locationtech.spatial4j.shape.Rectangle)

Example 19 with Rectangle

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

the class RandomizedShapeTestCase method _assertIntersect.

private void _assertIntersect(String msg, SpatialRelation expected, Shape a, Shape b) {
    SpatialRelation sect = a.relate(b);
    if (sect == expected)
        return;
    msg = ((msg == null) ? "" : msg + "\r") + a + " intersect " + b;
    if (expected == WITHIN || expected == CONTAINS) {
        if (// they are the same shape type
        a.getClass().equals(b.getClass()))
            assertEquals(msg, a, b);
        else {
            //they are effectively points or lines that are the same location
            assertTrue(msg, !a.hasArea());
            assertTrue(msg, !b.hasArea());
            Rectangle aBBox = a.getBoundingBox();
            Rectangle bBBox = b.getBoundingBox();
            if (aBBox.getHeight() == 0 && bBBox.getHeight() == 0 && (aBBox.getMaxY() == 90 && bBBox.getMaxY() == 90 || aBBox.getMinY() == -90 && bBBox.getMinY() == -90))
                //== a point at the pole
                ;
            else
                assertEquals(msg, aBBox, bBBox);
        }
    } else {
        //always fails
        assertEquals(msg, expected, sect);
    }
}
Also used : Rectangle(org.locationtech.spatial4j.shape.Rectangle) SpatialRelation(org.locationtech.spatial4j.shape.SpatialRelation)

Example 20 with Rectangle

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

the class HeatmapFacetCounterTest method testRandom.

@Test
@Repeat(iterations = 20)
public void testRandom() throws IOException {
    // Tests using random index shapes & query shapes. This has found all sorts of edge case bugs (e.g. dateline,
    // cell border, overflow(?)).
    final int numIndexedShapes = 1 + atMost(9);
    List<Shape> indexedShapes = new ArrayList<>(numIndexedShapes);
    for (int i = 0; i < numIndexedShapes; i++) {
        indexedShapes.add(randomIndexedShape());
    }
    //Main index loop:
    for (int i = 0; i < indexedShapes.size(); i++) {
        Shape shape = indexedShapes.get(i);
        adoc("" + i, shape);
        if (random().nextInt(10) == 0)
            //intermediate commit, produces extra segments
            commit();
    }
    //delete some documents randomly
    for (int id = 0; id < indexedShapes.size(); id++) {
        if (random().nextInt(10) == 0) {
            deleteDoc("" + id);
            indexedShapes.set(id, null);
        }
    }
    commit();
    // once without dateline wrap
    final Rectangle rect = randomRectangle();
    queryHeatmapRecursive(usually() ? ctx.getWorldBounds() : rect, 1);
    // and once with dateline wrap
    if (rect.getWidth() > 0) {
        double shift = random().nextDouble() % rect.getWidth();
        queryHeatmapRecursive(ctx.makeRectangle(DistanceUtils.normLonDEG(rect.getMinX() - shift), DistanceUtils.normLonDEG(rect.getMaxX() - shift), rect.getMinY(), rect.getMaxY()), 1);
    }
}
Also used : Shape(org.locationtech.spatial4j.shape.Shape) ArrayList(java.util.ArrayList) Rectangle(org.locationtech.spatial4j.shape.Rectangle) Point(org.locationtech.spatial4j.shape.Point) Test(org.junit.Test) Repeat(com.carrotsearch.randomizedtesting.annotations.Repeat)

Aggregations

Rectangle (org.locationtech.spatial4j.shape.Rectangle)36 Point (org.locationtech.spatial4j.shape.Point)10 Test (org.junit.Test)8 Shape (org.locationtech.spatial4j.shape.Shape)7 ArrayList (java.util.ArrayList)5 Query (org.apache.lucene.search.Query)5 Coordinate (com.vividsolutions.jts.geom.Coordinate)3 FunctionValues (org.apache.lucene.queries.function.FunctionValues)3 BooleanQuery (org.apache.lucene.search.BooleanQuery)3 SpatialArgs (org.apache.lucene.spatial.query.SpatialArgs)3 SpatialOperation (org.apache.lucene.spatial.query.SpatialOperation)3 GeoShape (org.apache.lucene.spatial3d.geom.GeoShape)3 SpatialContext (org.locationtech.spatial4j.context.SpatialContext)3 Map (java.util.Map)2 LeafReader (org.apache.lucene.index.LeafReader)2 NumericDocValues (org.apache.lucene.index.NumericDocValues)2 ConstantScoreQuery (org.apache.lucene.search.ConstantScoreQuery)2 TermQuery (org.apache.lucene.search.TermQuery)2 UnsupportedSpatialOperation (org.apache.lucene.spatial.query.UnsupportedSpatialOperation)2 GeoPoint (org.apache.lucene.spatial3d.geom.GeoPoint)2