Search in sources :

Example 1 with Circle

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

the class TestPointVectorStrategy method testCircleShapeSupport.

@Test
public void testCircleShapeSupport() {
    this.strategy = PointVectorStrategy.newInstance(ctx, getClass().getSimpleName());
    Circle circle = ctx.makeCircle(ctx.makePoint(0, 0), 10);
    SpatialArgs args = new SpatialArgs(SpatialOperation.Intersects, circle);
    Query query = this.strategy.makeQuery(args);
    assertNotNull(query);
}
Also used : Circle(org.locationtech.spatial4j.shape.Circle) SpatialArgs(org.apache.lucene.spatial.query.SpatialArgs) Query(org.apache.lucene.search.Query) MatchAllDocsQuery(org.apache.lucene.search.MatchAllDocsQuery) Test(org.junit.Test)

Example 2 with Circle

use of org.locationtech.spatial4j.shape.Circle 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 Circle

use of org.locationtech.spatial4j.shape.Circle in project elasticsearch by elastic.

the class GeoJSONShapeParserTests method testParseCircle.

public void testParseCircle() throws IOException {
    XContentBuilder multilinesGeoJson = XContentFactory.jsonBuilder().startObject().field("type", "circle").startArray("coordinates").value(100.0).value(0.0).endArray().field("radius", "100m").endObject();
    Circle expected = SPATIAL_CONTEXT.makeCircle(100.0, 0.0, 360 * 100 / GeoUtils.EARTH_EQUATOR);
    assertGeometryEquals(expected, multilinesGeoJson);
}
Also used : Circle(org.locationtech.spatial4j.shape.Circle) XContentBuilder(org.elasticsearch.common.xcontent.XContentBuilder)

Example 4 with Circle

use of org.locationtech.spatial4j.shape.Circle in project elasticsearch by elastic.

the class ShapeBuilderTests method testGeoCircle.

public void testGeoCircle() {
    double earthCircumference = 40075016.69;
    Circle circle = ShapeBuilders.newCircleBuilder().center(0, 0).radius("100m").build();
    assertEquals((360 * 100) / earthCircumference, circle.getRadius(), 0.00000001);
    assertEquals(new PointImpl(0, 0, ShapeBuilder.SPATIAL_CONTEXT), circle.getCenter());
    circle = ShapeBuilders.newCircleBuilder().center(+180, 0).radius("100m").build();
    assertEquals((360 * 100) / earthCircumference, circle.getRadius(), 0.00000001);
    assertEquals(new PointImpl(180, 0, ShapeBuilder.SPATIAL_CONTEXT), circle.getCenter());
    circle = ShapeBuilders.newCircleBuilder().center(-180, 0).radius("100m").build();
    assertEquals((360 * 100) / earthCircumference, circle.getRadius(), 0.00000001);
    assertEquals(new PointImpl(-180, 0, ShapeBuilder.SPATIAL_CONTEXT), circle.getCenter());
    circle = ShapeBuilders.newCircleBuilder().center(0, 90).radius("100m").build();
    assertEquals((360 * 100) / earthCircumference, circle.getRadius(), 0.00000001);
    assertEquals(new PointImpl(0, 90, ShapeBuilder.SPATIAL_CONTEXT), circle.getCenter());
    circle = ShapeBuilders.newCircleBuilder().center(0, -90).radius("100m").build();
    assertEquals((360 * 100) / earthCircumference, circle.getRadius(), 0.00000001);
    assertEquals(new PointImpl(0, -90, ShapeBuilder.SPATIAL_CONTEXT), circle.getCenter());
    double randomLat = (randomDouble() * 180) - 90;
    double randomLon = (randomDouble() * 360) - 180;
    double randomRadius = randomIntBetween(1, (int) earthCircumference / 4);
    circle = ShapeBuilders.newCircleBuilder().center(randomLon, randomLat).radius(randomRadius + "m").build();
    assertEquals((360 * randomRadius) / earthCircumference, circle.getRadius(), 0.00000001);
    assertEquals(new PointImpl(randomLon, randomLat, ShapeBuilder.SPATIAL_CONTEXT), circle.getCenter());
}
Also used : Circle(org.locationtech.spatial4j.shape.Circle) PointImpl(org.locationtech.spatial4j.shape.impl.PointImpl)

Aggregations

Circle (org.locationtech.spatial4j.shape.Circle)4 Test (org.junit.Test)2 MatchAllDocsQuery (org.apache.lucene.search.MatchAllDocsQuery)1 Query (org.apache.lucene.search.Query)1 QuadPrefixTree (org.apache.lucene.spatial.prefix.tree.QuadPrefixTree)1 SpatialArgs (org.apache.lucene.spatial.query.SpatialArgs)1 XContentBuilder (org.elasticsearch.common.xcontent.XContentBuilder)1 SpatialContextFactory (org.locationtech.spatial4j.context.SpatialContextFactory)1 Point (org.locationtech.spatial4j.shape.Point)1 PointImpl (org.locationtech.spatial4j.shape.impl.PointImpl)1 RectangleImpl (org.locationtech.spatial4j.shape.impl.RectangleImpl)1