use of org.opensearch.geometry.LinearRing 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.geometry.LinearRing in project OpenSearch by opensearch-project.
the class GeoJsonParserTests method testParsePolygonWithHole.
public void testParsePolygonWithHole() throws IOException {
XContentBuilder polygonGeoJson = XContentFactory.jsonBuilder().startObject().field("type", "Polygon").startArray("coordinates").startArray().startArray().value(100.0).value(1.0).endArray().startArray().value(101.0).value(1.0).endArray().startArray().value(101.0).value(0.0).endArray().startArray().value(100.0).value(0.0).endArray().startArray().value(100.0).value(1.0).endArray().endArray().startArray().startArray().value(100.2).value(0.8).endArray().startArray().value(100.2).value(0.2).endArray().startArray().value(100.8).value(0.2).endArray().startArray().value(100.8).value(0.8).endArray().startArray().value(100.2).value(0.8).endArray().endArray().endArray().endObject();
LinearRing hole = new LinearRing(new double[] { 100.2d, 100.2d, 100.8d, 100.8d, 100.2d }, new double[] { 0.8d, 0.2d, 0.2d, 0.8d, 0.8d });
Polygon p = new Polygon(new LinearRing(new double[] { 100d, 101d, 101d, 100d, 100d }, new double[] { 1d, 1d, 0d, 0d, 1d }), Collections.singletonList(hole));
assertGeometryEquals(p, polygonGeoJson);
}
use of org.opensearch.geometry.LinearRing in project OpenSearch by opensearch-project.
the class GeoJsonParserTests method testParsePolygon.
@Override
public void testParsePolygon() throws IOException {
XContentBuilder polygonGeoJson = XContentFactory.jsonBuilder().startObject().field("type", "Polygon").startArray("coordinates").startArray().startArray().value(100.0).value(1.0).endArray().startArray().value(101.0).value(1.0).endArray().startArray().value(101.0).value(0.0).endArray().startArray().value(100.0).value(0.0).endArray().startArray().value(100.0).value(1.0).endArray().endArray().endArray().endObject();
Polygon p = new Polygon(new LinearRing(new double[] { 100d, 101d, 101d, 100d, 100d }, new double[] { 1d, 1d, 0d, 0d, 1d }));
assertGeometryEquals(p, polygonGeoJson);
}
use of org.opensearch.geometry.LinearRing in project OpenSearch by opensearch-project.
the class GeoJsonParserTests method testParseMultiPolygon.
@Override
public void testParseMultiPolygon() throws IOException {
// two polygons; one without hole, one with hole
XContentBuilder multiPolygonGeoJson = XContentFactory.jsonBuilder().startObject().field("type", "MultiPolygon").startArray("coordinates").startArray().startArray().startArray().value(102.0).value(2.0).endArray().startArray().value(103.0).value(2.0).endArray().startArray().value(103.0).value(3.0).endArray().startArray().value(102.0).value(3.0).endArray().startArray().value(102.0).value(2.0).endArray().endArray().endArray().startArray().startArray().startArray().value(100.0).value(0.0).endArray().startArray().value(101.0).value(0.0).endArray().startArray().value(101.0).value(1.0).endArray().startArray().value(100.0).value(1.0).endArray().startArray().value(100.0).value(0.0).endArray().endArray().startArray().startArray().value(100.2).value(0.8).endArray().startArray().value(100.2).value(0.2).endArray().startArray().value(100.8).value(0.2).endArray().startArray().value(100.8).value(0.8).endArray().startArray().value(100.2).value(0.8).endArray().endArray().endArray().endArray().endObject();
LinearRing hole = new LinearRing(new double[] { 100.2d, 100.2d, 100.8d, 100.8d, 100.2d }, new double[] { 0.8d, 0.2d, 0.2d, 0.8d, 0.8d });
MultiPolygon polygons = new MultiPolygon(Arrays.asList(new Polygon(new LinearRing(new double[] { 102d, 103d, 103d, 102d, 102d }, new double[] { 2d, 2d, 3d, 3d, 2d })), new Polygon(new LinearRing(new double[] { 100d, 101d, 101d, 100d, 100d }, new double[] { 0d, 0d, 1d, 1d, 0d }), Collections.singletonList(hole))));
assertGeometryEquals(polygons, multiPolygonGeoJson);
}
use of org.opensearch.geometry.LinearRing in project OpenSearch by opensearch-project.
the class GeoJsonParserTests method testParseOrientationOption.
public void testParseOrientationOption() throws IOException {
// test 1: valid ccw (right handed system) poly not crossing dateline (with 'right' field)
XContentBuilder polygonGeoJson = XContentFactory.jsonBuilder().startObject().field("type", "Polygon").field("orientation", randomFrom("ccw", "right")).startArray("coordinates").startArray().startArray().value(176.0).value(15.0).endArray().startArray().value(-177.0).value(10.0).endArray().startArray().value(-177.0).value(-10.0).endArray().startArray().value(176.0).value(-15.0).endArray().startArray().value(172.0).value(0.0).endArray().startArray().value(176.0).value(15.0).endArray().endArray().startArray().startArray().value(-172.0).value(8.0).endArray().startArray().value(174.0).value(10.0).endArray().startArray().value(-172.0).value(-8.0).endArray().startArray().value(-172.0).value(8.0).endArray().endArray().endArray().endObject();
Polygon expected = new Polygon(new LinearRing(new double[] { 176.0, -177.0, -177.0, 176.0, 172.0, 176.0 }, new double[] { 15.0, 10.0, -10.0, -15.0, 0.0, 15.0 }), Collections.singletonList(new LinearRing(new double[] { -172.0, 174.0, -172.0, -172.0 }, new double[] { 8.0, 10.0, -8.0, 8.0 })));
assertGeometryEquals(expected, polygonGeoJson);
// test 2: valid cw poly
polygonGeoJson = XContentFactory.jsonBuilder().startObject().field("type", "Polygon").field("orientation", randomFrom("cw", "left")).startArray("coordinates").startArray().startArray().value(176.0).value(15.0).endArray().startArray().value(-177.0).value(10.0).endArray().startArray().value(-177.0).value(-10.0).endArray().startArray().value(176.0).value(-15.0).endArray().startArray().value(172.0).value(0.0).endArray().startArray().value(176.0).value(15.0).endArray().endArray().startArray().startArray().value(-172.0).value(8.0).endArray().startArray().value(174.0).value(10.0).endArray().startArray().value(-172.0).value(-8.0).endArray().startArray().value(-172.0).value(8.0).endArray().endArray().endArray().endObject();
expected = new Polygon(new LinearRing(new double[] { 176.0, 172.0, 176.0, -177.0, -177.0, 176.0 }, new double[] { 15.0, 0.0, -15.0, -10.0, 10.0, 15.0 }), Collections.singletonList(new LinearRing(new double[] { -172.0, -172.0, 174.0, -172.0 }, new double[] { 8.0, -8.0, 10.0, 8.0 })));
assertGeometryEquals(expected, polygonGeoJson);
}
Aggregations