Search in sources :

Example 16 with LineStringBuilder

use of org.opensearch.common.geo.builders.LineStringBuilder 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 17 with LineStringBuilder

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

the class ShapeBuilderTests method testMultiLineString.

public void testMultiLineString() {
    MultiLineStringBuilder mlsb = new MultiLineStringBuilder().linestring(new LineStringBuilder(new CoordinatesBuilder().coordinate(-100.0, 50.0).coordinate(50.0, 50.0).coordinate(50.0, 20.0).coordinate(-100.0, 20.0))).linestring(new LineStringBuilder(new CoordinatesBuilder().coordinate(-100.0, 20.0).coordinate(50.0, 20.0).coordinate(50.0, 0.0).coordinate(-100.0, 0.0)));
    mlsb.buildS4J();
    buildGeometry(mlsb);
    // LineString that needs to be wrapped
    new MultiLineStringBuilder().linestring(new LineStringBuilder(new CoordinatesBuilder().coordinate(150.0, 60.0).coordinate(200.0, 60.0).coordinate(200.0, 40.0).coordinate(150.0, 40.0))).linestring(new LineStringBuilder(new CoordinatesBuilder().coordinate(150.0, 20.0).coordinate(200.0, 20.0).coordinate(200.0, 0.0).coordinate(150.0, 0.0)));
    mlsb.buildS4J();
    buildGeometry(mlsb);
}
Also used : CoordinatesBuilder(org.opensearch.common.geo.builders.CoordinatesBuilder) MultiLineStringBuilder(org.opensearch.common.geo.builders.MultiLineStringBuilder) MultiLineStringBuilder(org.opensearch.common.geo.builders.MultiLineStringBuilder) LineStringBuilder(org.opensearch.common.geo.builders.LineStringBuilder)

Example 18 with LineStringBuilder

use of org.opensearch.common.geo.builders.LineStringBuilder 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 19 with LineStringBuilder

use of org.opensearch.common.geo.builders.LineStringBuilder 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)

Example 20 with LineStringBuilder

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

the class ShapeBuilderTests method testBoundaryShapeWithTangentialHole.

public void testBoundaryShapeWithTangentialHole() {
    // test a shape with one tangential (shared) vertex for each hole (should pass)
    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(-178, -10).coordinate(-180, -5).coordinate(-180, 5).coordinate(-177, 10)));
    builder.hole(new LineStringBuilder(new CoordinatesBuilder().coordinate(172, 0).coordinate(176, 10).coordinate(176, -5).coordinate(172, 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) MultiLineStringBuilder(org.opensearch.common.geo.builders.MultiLineStringBuilder) LineStringBuilder(org.opensearch.common.geo.builders.LineStringBuilder)

Aggregations

LineStringBuilder (org.opensearch.common.geo.builders.LineStringBuilder)23 CoordinatesBuilder (org.opensearch.common.geo.builders.CoordinatesBuilder)21 MultiLineStringBuilder (org.opensearch.common.geo.builders.MultiLineStringBuilder)20 PolygonBuilder (org.opensearch.common.geo.builders.PolygonBuilder)17 Coordinate (org.locationtech.jts.geom.Coordinate)7 MultiPolygonBuilder (org.opensearch.common.geo.builders.MultiPolygonBuilder)6 InvalidShapeException (org.locationtech.spatial4j.exception.InvalidShapeException)5 PointBuilder (org.opensearch.common.geo.builders.PointBuilder)5 ArrayList (java.util.ArrayList)4 MultiPointBuilder (org.opensearch.common.geo.builders.MultiPointBuilder)4 ShapeBuilder (org.opensearch.common.geo.builders.ShapeBuilder)4 XContentBuilder (org.opensearch.common.xcontent.XContentBuilder)4 OpenSearchException (org.opensearch.OpenSearchException)3 OpenSearchParseException (org.opensearch.OpenSearchParseException)3 MultiLine (org.opensearch.geometry.MultiLine)3 LineString (org.locationtech.jts.geom.LineString)2 LinearRing (org.locationtech.jts.geom.LinearRing)2 MultiLineString (org.locationtech.jts.geom.MultiLineString)2 Point (org.locationtech.jts.geom.Point)2 Polygon (org.locationtech.jts.geom.Polygon)2