Search in sources :

Example 1 with EnvelopeBuilder

use of org.opensearch.common.geo.builders.EnvelopeBuilder in project OpenSearch by opensearch-project.

the class GeoShapeQueryBuilderTests method testThatXContentSerializationInsideOfArrayWorks.

// see #3878
public void testThatXContentSerializationInsideOfArrayWorks() throws Exception {
    EnvelopeBuilder envelopeBuilder = new EnvelopeBuilder(new Coordinate(0, 10), new Coordinate(10, 0));
    GeoShapeQueryBuilder geoQuery = randomBoolean() ? QueryBuilders.geoShapeQuery("searchGeometry", envelopeBuilder) : QueryBuilders.geoShapeQuery("searchGeometry", envelopeBuilder.buildGeometry());
    JsonXContent.contentBuilder().startArray().value(geoQuery).endArray();
}
Also used : Coordinate(org.locationtech.jts.geom.Coordinate) EnvelopeBuilder(org.opensearch.common.geo.builders.EnvelopeBuilder)

Example 2 with EnvelopeBuilder

use of org.opensearch.common.geo.builders.EnvelopeBuilder in project OpenSearch by opensearch-project.

the class ShapeBuilderTests method testNewRectangle.

public void testNewRectangle() {
    EnvelopeBuilder eb = new EnvelopeBuilder(new Coordinate(-45, 30), new Coordinate(45, -30));
    Rectangle rectangle = eb.buildS4J();
    assertEquals(-45D, rectangle.getMinX(), 0.0d);
    assertEquals(-30D, rectangle.getMinY(), 0.0d);
    assertEquals(45D, rectangle.getMaxX(), 0.0d);
    assertEquals(30D, rectangle.getMaxY(), 0.0d);
    org.opensearch.geometry.Rectangle luceneRectangle = eb.buildGeometry();
    assertEquals(-45D, luceneRectangle.getMinX(), 0.0d);
    assertEquals(-30D, luceneRectangle.getMinY(), 0.0d);
    assertEquals(45D, luceneRectangle.getMaxX(), 0.0d);
    assertEquals(30D, luceneRectangle.getMaxY(), 0.0d);
}
Also used : Coordinate(org.locationtech.jts.geom.Coordinate) Rectangle(org.locationtech.spatial4j.shape.Rectangle) EnvelopeBuilder(org.opensearch.common.geo.builders.EnvelopeBuilder)

Example 3 with EnvelopeBuilder

use of org.opensearch.common.geo.builders.EnvelopeBuilder in project OpenSearch by opensearch-project.

the class GeoWKTShapeParserTests method testParseEnvelope.

@Override
public void testParseEnvelope() throws IOException, ParseException {
    org.apache.lucene.geo.Rectangle r = GeoTestUtil.nextBox();
    EnvelopeBuilder builder = new EnvelopeBuilder(new Coordinate(r.minLon, r.maxLat), new Coordinate(r.maxLon, r.minLat));
    Rectangle expected = SPATIAL_CONTEXT.makeRectangle(r.minLon, r.maxLon, r.minLat, r.maxLat);
    assertExpected(expected, builder, true);
    assertExpected(new org.opensearch.geometry.Rectangle(r.minLon, r.maxLon, r.maxLat, r.minLat), builder, false);
    assertMalformed(builder);
}
Also used : Coordinate(org.locationtech.jts.geom.Coordinate) Rectangle(org.locationtech.spatial4j.shape.Rectangle) EnvelopeBuilder(org.opensearch.common.geo.builders.EnvelopeBuilder)

Example 4 with EnvelopeBuilder

use of org.opensearch.common.geo.builders.EnvelopeBuilder in project OpenSearch by opensearch-project.

the class GeoShapeQueryTests method testIndexedShapeReferenceSourceDisabled.

public void testIndexedShapeReferenceSourceDisabled() throws Exception {
    XContentBuilder mapping = createDefaultMapping();
    client().admin().indices().prepareCreate("test").addMapping("type1", mapping).get();
    createIndex("shapes", Settings.EMPTY, "shape_type", "_source", "enabled=false");
    ensureGreen();
    EnvelopeBuilder shape = new EnvelopeBuilder(new Coordinate(-45, 45), new Coordinate(45, -45));
    client().prepareIndex("shapes").setId("Big_Rectangle").setSource(jsonBuilder().startObject().field("shape", shape).endObject()).setRefreshPolicy(IMMEDIATE).get();
    try {
        client().prepareSearch("test").setQuery(geoIntersectionQuery("geo", "Big_Rectangle")).get();
    } catch (IllegalArgumentException e) {
        assertThat(e.getMessage(), containsString("source disabled"));
    }
}
Also used : Coordinate(org.locationtech.jts.geom.Coordinate) EnvelopeBuilder(org.opensearch.common.geo.builders.EnvelopeBuilder) XContentBuilder(org.opensearch.common.xcontent.XContentBuilder)

Example 5 with EnvelopeBuilder

use of org.opensearch.common.geo.builders.EnvelopeBuilder in project OpenSearch by opensearch-project.

the class GeoShapeQueryTests method testIndexRectangleSpanningDateLine.

public void testIndexRectangleSpanningDateLine() throws Exception {
    String mapping = Strings.toString(createRandomMapping());
    client().admin().indices().prepareCreate("test").addMapping("type1", mapping, XContentType.JSON).get();
    ensureGreen();
    EnvelopeBuilder envelopeBuilder = new EnvelopeBuilder(new Coordinate(178, 10), new Coordinate(-178, -10));
    XContentBuilder docSource = envelopeBuilder.toXContent(jsonBuilder().startObject().field("geo"), null).endObject();
    client().prepareIndex("test").setId("1").setSource(docSource).setRefreshPolicy(IMMEDIATE).get();
    ShapeBuilder filterShape = new PointBuilder(179, 0);
    GeoShapeQueryBuilder geoShapeQueryBuilder = QueryBuilders.geoShapeQuery("geo", filterShape);
    geoShapeQueryBuilder.relation(ShapeRelation.INTERSECTS);
    SearchResponse result = client().prepareSearch("test").setQuery(geoShapeQueryBuilder).get();
    assertSearchResponse(result);
    assertHitCount(result, 1);
}
Also used : ShapeBuilder(org.opensearch.common.geo.builders.ShapeBuilder) MultiPointBuilder(org.opensearch.common.geo.builders.MultiPointBuilder) PointBuilder(org.opensearch.common.geo.builders.PointBuilder) GeoShapeQueryBuilder(org.opensearch.index.query.GeoShapeQueryBuilder) Coordinate(org.locationtech.jts.geom.Coordinate) EnvelopeBuilder(org.opensearch.common.geo.builders.EnvelopeBuilder) Matchers.containsString(org.hamcrest.Matchers.containsString) XContentBuilder(org.opensearch.common.xcontent.XContentBuilder) OpenSearchAssertions.assertSearchResponse(org.opensearch.test.hamcrest.OpenSearchAssertions.assertSearchResponse) SearchResponse(org.opensearch.action.search.SearchResponse)

Aggregations

Coordinate (org.locationtech.jts.geom.Coordinate)13 EnvelopeBuilder (org.opensearch.common.geo.builders.EnvelopeBuilder)13 SearchResponse (org.opensearch.action.search.SearchResponse)8 OpenSearchAssertions.assertSearchResponse (org.opensearch.test.hamcrest.OpenSearchAssertions.assertSearchResponse)8 XContentBuilder (org.opensearch.common.xcontent.XContentBuilder)7 Matchers.containsString (org.hamcrest.Matchers.containsString)4 Rectangle (org.locationtech.spatial4j.shape.Rectangle)3 GeometryCollectionBuilder (org.opensearch.common.geo.builders.GeometryCollectionBuilder)3 MultiPointBuilder (org.opensearch.common.geo.builders.MultiPointBuilder)3 GeoShapeQueryBuilder (org.opensearch.index.query.GeoShapeQueryBuilder)3 IndexRequest (org.opensearch.action.index.IndexRequest)2 PointBuilder (org.opensearch.common.geo.builders.PointBuilder)2 ShapeBuilder (org.opensearch.common.geo.builders.ShapeBuilder)2 IOException (java.io.IOException)1 XContentParser (org.opensearch.common.xcontent.XContentParser)1 Geometry (org.opensearch.geometry.Geometry)1 RandomShapeGenerator.xRandomPoint (org.opensearch.test.geo.RandomShapeGenerator.xRandomPoint)1 RandomShapeGenerator.xRandomRectangle (org.opensearch.test.geo.RandomShapeGenerator.xRandomRectangle)1