Search in sources :

Example 21 with CoordinatesBuilder

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

the class ShapeBuilderTests method testNewPolygon_coordinate.

public void testNewPolygon_coordinate() {
    PolygonBuilder pb = new PolygonBuilder(new CoordinatesBuilder().coordinate(new Coordinate(-45, 30)).coordinate(new Coordinate(45, 30)).coordinate(new Coordinate(45, -30)).coordinate(new Coordinate(-45, -30)).coordinate(new Coordinate(-45, 30)));
    Polygon poly = pb.toPolygonS4J();
    LineString exterior = poly.getExteriorRing();
    assertEquals(exterior.getCoordinateN(0), new Coordinate(-45, 30));
    assertEquals(exterior.getCoordinateN(1), new Coordinate(45, 30));
    assertEquals(exterior.getCoordinateN(2), new Coordinate(45, -30));
    assertEquals(exterior.getCoordinateN(3), new Coordinate(-45, -30));
    LinearRing polygon = pb.toPolygonGeometry().getPolygon();
    assertEquals(polygon.getY(0), 30, 0d);
    assertEquals(polygon.getX(0), -45, 0d);
    assertEquals(polygon.getY(1), 30, 0d);
    assertEquals(polygon.getX(1), 45, 0d);
    assertEquals(polygon.getY(2), -30, 0d);
    assertEquals(polygon.getX(2), 45, 0d);
    assertEquals(polygon.getY(3), -30, 0d);
    assertEquals(polygon.getX(3), -45, 0d);
}
Also used : CoordinatesBuilder(org.opensearch.common.geo.builders.CoordinatesBuilder) Coordinate(org.locationtech.jts.geom.Coordinate) OpenSearchGeoAssertions.assertMultiLineString(org.opensearch.test.hamcrest.OpenSearchGeoAssertions.assertMultiLineString) LineString(org.locationtech.jts.geom.LineString) OpenSearchGeoAssertions.assertPolygon(org.opensearch.test.hamcrest.OpenSearchGeoAssertions.assertPolygon) OpenSearchGeoAssertions.assertMultiPolygon(org.opensearch.test.hamcrest.OpenSearchGeoAssertions.assertMultiPolygon) Polygon(org.locationtech.jts.geom.Polygon) LinearRing(org.opensearch.geometry.LinearRing) PolygonBuilder(org.opensearch.common.geo.builders.PolygonBuilder)

Example 22 with CoordinatesBuilder

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

the class ShapeBuilderTests method testBoundaryShape.

/**
 * Test an enveloping polygon around the max mercator bounds
 */
public void testBoundaryShape() {
    PolygonBuilder builder = new PolygonBuilder(new CoordinatesBuilder().coordinate(-180, 90).coordinate(180, 90).coordinate(180, -90).coordinate(-180, 90));
    assertPolygon(builder.close().buildS4J(), true);
    assertPolygon(buildGeometry(builder.close()), false);
}
Also used : CoordinatesBuilder(org.opensearch.common.geo.builders.CoordinatesBuilder) PolygonBuilder(org.opensearch.common.geo.builders.PolygonBuilder)

Example 23 with CoordinatesBuilder

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

the class ShapeBuilderTests method testShapeWithHoleAtEdgeEndPoints.

public void testShapeWithHoleAtEdgeEndPoints() {
    PolygonBuilder builder = new PolygonBuilder(new CoordinatesBuilder().coordinate(-4, 2).coordinate(4, 2).coordinate(6, 0).coordinate(4, -2).coordinate(-4, -2).coordinate(-6, 0).coordinate(-4, 2));
    builder.hole(new LineStringBuilder(new CoordinatesBuilder().coordinate(4, 1).coordinate(4, -1).coordinate(-4, -1).coordinate(-4, 1).coordinate(4, 1)));
    assertPolygon(builder.close().buildS4J(), true);
    assertPolygon(buildGeometry(builder.close()), false);
}
Also used : CoordinatesBuilder(org.opensearch.common.geo.builders.CoordinatesBuilder) PolygonBuilder(org.opensearch.common.geo.builders.PolygonBuilder) MultiLineStringBuilder(org.opensearch.common.geo.builders.MultiLineStringBuilder) LineStringBuilder(org.opensearch.common.geo.builders.LineStringBuilder)

Example 24 with CoordinatesBuilder

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

the class ShapeBuilderTests method testDateline.

public void testDateline() {
    // tests that the following shape (defined in clockwise non-OGC order)
    // https://gist.github.com/anonymous/7f1bb6d7e9cd72f5977c crosses the dateline
    // expected results: 3 polygons, 1 with a hole
    // a giant c shape
    PolygonBuilder builder = new PolygonBuilder(new CoordinatesBuilder().coordinate(-186, 0).coordinate(-176, 0).coordinate(-176, 3).coordinate(-183, 3).coordinate(-183, 5).coordinate(-176, 5).coordinate(-176, 8).coordinate(-186, 8).coordinate(-186, 0));
    // 3/4 of an embedded 'c', crossing dateline once
    builder.hole(new LineStringBuilder(new CoordinatesBuilder().coordinate(-185, 1).coordinate(-181, 1).coordinate(-181, 2).coordinate(-184, 2).coordinate(-184, 6).coordinate(-178, 6).coordinate(-178, 7).coordinate(-185, 7).coordinate(-185, 1)));
    // embedded hole right of the dateline
    builder.hole(new LineStringBuilder(new CoordinatesBuilder().coordinate(-179, 1).coordinate(-177, 1).coordinate(-177, 2).coordinate(-179, 2).coordinate(-179, 1)));
    assertMultiPolygon(builder.close().buildS4J(), true);
    assertMultiPolygon(buildGeometry(builder.close()), false);
}
Also used : CoordinatesBuilder(org.opensearch.common.geo.builders.CoordinatesBuilder) PolygonBuilder(org.opensearch.common.geo.builders.PolygonBuilder) MultiLineStringBuilder(org.opensearch.common.geo.builders.MultiLineStringBuilder) LineStringBuilder(org.opensearch.common.geo.builders.LineStringBuilder)

Example 25 with CoordinatesBuilder

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

the class ShapeBuilderTests method testInvalidShapeWithConsecutiveDuplicatePoints.

public void testInvalidShapeWithConsecutiveDuplicatePoints() {
    PolygonBuilder builder = new PolygonBuilder(new CoordinatesBuilder().coordinate(180, 0).coordinate(176, 4).coordinate(176, 4).coordinate(-176, 4).coordinate(180, 0));
    Exception e = expectThrows(InvalidShapeException.class, () -> builder.close().buildS4J());
    assertThat(e.getMessage(), containsString("duplicate consecutive coordinates at: ("));
    e = expectThrows(InvalidShapeException.class, () -> buildGeometry(builder.close()));
    assertThat(e.getMessage(), containsString("duplicate consecutive coordinates at: ("));
}
Also used : CoordinatesBuilder(org.opensearch.common.geo.builders.CoordinatesBuilder) InvalidShapeException(org.locationtech.spatial4j.exception.InvalidShapeException) PolygonBuilder(org.opensearch.common.geo.builders.PolygonBuilder) InvalidShapeException(org.locationtech.spatial4j.exception.InvalidShapeException)

Aggregations

CoordinatesBuilder (org.opensearch.common.geo.builders.CoordinatesBuilder)42 PolygonBuilder (org.opensearch.common.geo.builders.PolygonBuilder)37 LineStringBuilder (org.opensearch.common.geo.builders.LineStringBuilder)21 MultiLineStringBuilder (org.opensearch.common.geo.builders.MultiLineStringBuilder)18 Coordinate (org.locationtech.jts.geom.Coordinate)12 XContentBuilder (org.opensearch.common.xcontent.XContentBuilder)12 MultiPolygonBuilder (org.opensearch.common.geo.builders.MultiPolygonBuilder)11 SearchResponse (org.opensearch.action.search.SearchResponse)8 GeometryCollectionBuilder (org.opensearch.common.geo.builders.GeometryCollectionBuilder)8 InvalidShapeException (org.locationtech.spatial4j.exception.InvalidShapeException)7 OpenSearchAssertions.assertSearchResponse (org.opensearch.test.hamcrest.OpenSearchAssertions.assertSearchResponse)7 ArrayList (java.util.ArrayList)5 PointBuilder (org.opensearch.common.geo.builders.PointBuilder)5 ShapeBuilder (org.opensearch.common.geo.builders.ShapeBuilder)5 GeoShapeQueryBuilder (org.opensearch.index.query.GeoShapeQueryBuilder)5 LineString (org.locationtech.jts.geom.LineString)4 Polygon (org.locationtech.jts.geom.Polygon)4 MultiPointBuilder (org.opensearch.common.geo.builders.MultiPointBuilder)4 Settings (org.opensearch.common.settings.Settings)4 OpenSearchGeoAssertions.assertMultiLineString (org.opensearch.test.hamcrest.OpenSearchGeoAssertions.assertMultiLineString)4