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);
}
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);
}
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);
}
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);
}
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: ("));
}
Aggregations