Search in sources :

Example 6 with CoordinatesBuilder

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

the class ShapeBuilderTests method testInvalidSelfCrossingPolygon.

public void testInvalidSelfCrossingPolygon() {
    PolygonBuilder builder = new PolygonBuilder(new CoordinatesBuilder().coordinate(0, 0).coordinate(0, 2).coordinate(1, 1.9).coordinate(0.5, 1.8).coordinate(1.5, 1.8).coordinate(1, 1.9).coordinate(2, 2).coordinate(2, 0).coordinate(0, 0));
    Exception e = expectThrows(InvalidShapeException.class, () -> builder.close().buildS4J());
    assertThat(e.getMessage(), containsString("Self-intersection at or near point ["));
    assertThat(e.getMessage(), not(containsString("NaN")));
    e = expectThrows(InvalidShapeException.class, () -> buildGeometry(builder.close()));
    assertThat(e.getMessage(), containsString("Self-intersection at or near point ["));
    assertThat(e.getMessage(), not(containsString("NaN")));
}
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)

Example 7 with CoordinatesBuilder

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

the class ShapeBuilderTests method testPolygonWrapping.

public void testPolygonWrapping() {
    PolygonBuilder pb = new PolygonBuilder(new CoordinatesBuilder().coordinate(-150.0, 65.0).coordinate(-250.0, 65.0).coordinate(-250.0, -65.0).coordinate(-150.0, -65.0).close());
    assertMultiPolygon(pb.buildS4J(), true);
    assertMultiPolygon(buildGeometry(pb), false);
}
Also used : CoordinatesBuilder(org.opensearch.common.geo.builders.CoordinatesBuilder) PolygonBuilder(org.opensearch.common.geo.builders.PolygonBuilder)

Example 8 with CoordinatesBuilder

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

the class ShapeBuilderTests method testDatelineOGC.

public void testDatelineOGC() {
    // tests that the following shape (defined in counterclockwise 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(174, 0).coordinate(-176, 0).coordinate(-176, 3).coordinate(177, 3).coordinate(177, 5).coordinate(-176, 5).coordinate(-176, 8).coordinate(174, 8).coordinate(174, 0));
    // 3/4 of an embedded 'c', crossing dateline once
    builder.hole(new LineStringBuilder(new CoordinatesBuilder().coordinate(175, 1).coordinate(175, 7).coordinate(-178, 7).coordinate(-178, 6).coordinate(176, 6).coordinate(176, 2).coordinate(179, 2).coordinate(179, 1).coordinate(175, 1)));
    // embedded hole right of the dateline
    builder.hole(new LineStringBuilder(new CoordinatesBuilder().coordinate(-179, 1).coordinate(-179, 2).coordinate(-177, 2).coordinate(-177, 1).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 9 with CoordinatesBuilder

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

the class ShapeBuilderTests method testBoundaryShapeWithInvalidTangentialHole.

public void testBoundaryShapeWithInvalidTangentialHole() {
    // test shape with two tangential (shared) vertices (should throw exception)
    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(-177, 10).coordinate(172, 0).coordinate(180, -5).coordinate(176, -10).coordinate(-177, 10)));
    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 10 with CoordinatesBuilder

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

the class ShapeBuilderTests method testLineStringBuilder.

public void testLineStringBuilder() {
    // Building a simple LineString
    LineStringBuilder lsb = new LineStringBuilder(new CoordinatesBuilder().coordinate(-130.0, 55.0).coordinate(-130.0, -40.0).coordinate(-15.0, -40.0).coordinate(-20.0, 50.0).coordinate(-45.0, 50.0).coordinate(-45.0, -15.0).coordinate(-110.0, -15.0).coordinate(-110.0, 55.0));
    lsb.buildS4J();
    buildGeometry(lsb);
    // Building a linestring that needs to be wrapped
    lsb = new LineStringBuilder(new CoordinatesBuilder().coordinate(100.0, 50.0).coordinate(110.0, -40.0).coordinate(240.0, -40.0).coordinate(230.0, 60.0).coordinate(200.0, 60.0).coordinate(200.0, -30.0).coordinate(130.0, -30.0).coordinate(130.0, 60.0));
    lsb.buildS4J();
    buildGeometry(lsb);
    // Building a lineString on the dateline
    lsb = new LineStringBuilder(new CoordinatesBuilder().coordinate(-180.0, 80.0).coordinate(-180.0, 40.0).coordinate(-180.0, -40.0).coordinate(-180.0, -80.0));
    lsb.buildS4J();
    buildGeometry(lsb);
    // Building a lineString on the dateline
    lsb = new LineStringBuilder(new CoordinatesBuilder().coordinate(180.0, 80.0).coordinate(180.0, 40.0).coordinate(180.0, -40.0).coordinate(180.0, -80.0));
    lsb.buildS4J();
    buildGeometry(lsb);
}
Also used : CoordinatesBuilder(org.opensearch.common.geo.builders.CoordinatesBuilder) MultiLineStringBuilder(org.opensearch.common.geo.builders.MultiLineStringBuilder) LineStringBuilder(org.opensearch.common.geo.builders.LineStringBuilder)

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