Search in sources :

Example 26 with PolygonBuilder

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

the class ShapeBuilderTests method testPolygonSelfIntersection.

public void testPolygonSelfIntersection() {
    PolygonBuilder newPolygon = new PolygonBuilder(new CoordinatesBuilder().coordinate(-40.0, 50.0).coordinate(40.0, 50.0).coordinate(-40.0, -50.0).coordinate(40.0, -50.0).close());
    Exception e = expectThrows(InvalidShapeException.class, () -> newPolygon.buildS4J());
    assertThat(e.getMessage(), containsString("Self-intersection at or near point (0.0"));
}
Also used : CoordinatesBuilder(org.opensearch.common.geo.builders.CoordinatesBuilder) PolygonBuilder(org.opensearch.common.geo.builders.PolygonBuilder) InvalidShapeException(org.locationtech.spatial4j.exception.InvalidShapeException)

Example 27 with PolygonBuilder

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

the class ShapeBuilderTests method testShapeWithInvalidTangentialHole.

public void testShapeWithInvalidTangentialHole() {
    // test a shape with one invalid tangential (shared) vertex (should throw exception)
    PolygonBuilder builder = new PolygonBuilder(new CoordinatesBuilder().coordinate(179, 10).coordinate(168, 15).coordinate(164, 0).coordinate(166, -15).coordinate(179, -10).coordinate(179, 10));
    builder.hole(new LineStringBuilder(new CoordinatesBuilder().coordinate(164, 0).coordinate(175, 10).coordinate(175, 5).coordinate(179, -10).coordinate(164, 0)));
    Exception e;
    e = expectThrows(InvalidShapeException.class, () -> builder.close().buildS4J());
    assertThat(e.getMessage(), containsString("interior cannot share more than one point with the exterior"));
    e = expectThrows(IllegalArgumentException.class, () -> buildGeometry(builder.close()));
    assertThat(e.getMessage(), containsString("interior cannot share more than one point with the exterior"));
}
Also used : CoordinatesBuilder(org.opensearch.common.geo.builders.CoordinatesBuilder) InvalidShapeException(org.locationtech.spatial4j.exception.InvalidShapeException) PolygonBuilder(org.opensearch.common.geo.builders.PolygonBuilder) MultiLineStringBuilder(org.opensearch.common.geo.builders.MultiLineStringBuilder) LineStringBuilder(org.opensearch.common.geo.builders.LineStringBuilder) InvalidShapeException(org.locationtech.spatial4j.exception.InvalidShapeException)

Example 28 with PolygonBuilder

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

the class ShapeBuilderTests method testShapeWithAlternateOrientation.

public void testShapeWithAlternateOrientation() {
    // cw: should produce a multi polygon spanning hemispheres
    PolygonBuilder builder = new PolygonBuilder(new CoordinatesBuilder().coordinate(180, 0).coordinate(176, 4).coordinate(-176, 4).coordinate(180, 0));
    assertPolygon(builder.close().buildS4J(), true);
    assertPolygon(buildGeometry(builder.close()), false);
    // cw: geo core will convert to ccw across the dateline
    builder = new PolygonBuilder(new CoordinatesBuilder().coordinate(180, 0).coordinate(-176, 4).coordinate(176, 4).coordinate(180, 0));
    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)

Example 29 with PolygonBuilder

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

the class ShapeBuilderTests method testShapeWithBoundaryHoles.

public void testShapeWithBoundaryHoles() {
    // test case 1: test the positive side of the dateline
    PolygonBuilder builder = new PolygonBuilder(new CoordinatesBuilder().coordinate(-177, 10).coordinate(176, 15).coordinate(172, 0).coordinate(176, -15).coordinate(-177, -10).coordinate(-177, 10));
    builder.hole(new LineStringBuilder(new CoordinatesBuilder().coordinate(176, 10).coordinate(180, 5).coordinate(180, -5).coordinate(176, -10).coordinate(176, 10)));
    assertMultiPolygon(builder.close().buildS4J(), true);
    assertMultiPolygon(buildGeometry(builder.close()), false);
    // test case 2: test the negative side of the dateline
    builder = new PolygonBuilder(new CoordinatesBuilder().coordinate(-176, 15).coordinate(179, 10).coordinate(179, -10).coordinate(-176, -15).coordinate(-172, 0).close());
    builder.hole(new LineStringBuilder(new CoordinatesBuilder().coordinate(-176, 10).coordinate(-176, -10).coordinate(-180, -5).coordinate(-180, 5).coordinate(-176, 10).close()));
    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 30 with PolygonBuilder

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

the class ShapeBuilderTests method testShapeWithTangentialHole.

public void testShapeWithTangentialHole() {
    // test a shape with one tangential (shared) vertex (should pass)
    PolygonBuilder builder = new PolygonBuilder(new CoordinatesBuilder().coordinate(179, 10).coordinate(168, 15).coordinate(164, 0).coordinate(166, -15).coordinate(179, -10).coordinate(179, 10));
    builder.hole(new LineStringBuilder(new CoordinatesBuilder().coordinate(-177, 10).coordinate(-178, -10).coordinate(-180, -5).coordinate(-180, 5).coordinate(-177, 10)));
    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)

Aggregations

PolygonBuilder (org.opensearch.common.geo.builders.PolygonBuilder)39 CoordinatesBuilder (org.opensearch.common.geo.builders.CoordinatesBuilder)37 LineStringBuilder (org.opensearch.common.geo.builders.LineStringBuilder)17 Coordinate (org.locationtech.jts.geom.Coordinate)14 MultiLineStringBuilder (org.opensearch.common.geo.builders.MultiLineStringBuilder)14 MultiPolygonBuilder (org.opensearch.common.geo.builders.MultiPolygonBuilder)13 XContentBuilder (org.opensearch.common.xcontent.XContentBuilder)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 Polygon (org.locationtech.jts.geom.Polygon)6 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 MultiPointBuilder (org.opensearch.common.geo.builders.MultiPointBuilder)4 Settings (org.opensearch.common.settings.Settings)4 OpenSearchGeoAssertions.assertMultiLineString (org.opensearch.test.hamcrest.OpenSearchGeoAssertions.assertMultiLineString)4