use of org.opensearch.geometry.Polygon in project OpenSearch by opensearch-project.
the class GeometryIndexerTests method testInvalidSelfCrossingPolygon.
public void testInvalidSelfCrossingPolygon() {
Polygon polygon = new Polygon(new LinearRing(new double[] { 0, 0, 1, 0.5, 1.5, 1, 2, 2, 0 }, new double[] { 0, 2, 1.9, 1.8, 1.8, 1.9, 2, 0, 0 }));
Exception e = expectThrows(InvalidShapeException.class, () -> indexer.prepareForIndexing(polygon));
assertThat(e.getMessage(), containsString("Self-intersection at or near point ["));
assertThat(e.getMessage(), not(containsString("NaN")));
}
use of org.opensearch.geometry.Polygon in project OpenSearch by opensearch-project.
the class GeoJsonParserTests method testParseGeometryCollection.
@Override
public void testParseGeometryCollection() throws IOException {
XContentBuilder geometryCollectionGeoJson = XContentFactory.jsonBuilder().startObject().field("type", "GeometryCollection").startArray("geometries").startObject().field("type", "LineString").startArray("coordinates").startArray().value(100.0).value(0.0).endArray().startArray().value(101.0).value(1.0).endArray().endArray().endObject().startObject().field("type", "Point").startArray("coordinates").value(102.0).value(2.0).endArray().endObject().startObject().field("type", "Polygon").startArray("coordinates").startArray().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().startArray().value(-177.0).value(-10.0).endArray().startArray().value(-177.0).value(10.0).endArray().endArray().endArray().endObject().endArray().endObject();
GeometryCollection<Geometry> geometryExpected = new GeometryCollection<>(Arrays.asList(new Line(new double[] { 100d, 101d }, new double[] { 0d, 1d }), new Point(102d, 2d), new Polygon(new LinearRing(new double[] { -177, 176, 172, 176, -177, -177 }, new double[] { 10, 15, 0, -15, -10, 10 }))));
assertGeometryEquals(geometryExpected, geometryCollectionGeoJson);
}
use of org.opensearch.geometry.Polygon in project OpenSearch by opensearch-project.
the class GeoJsonParserTests method testParse3DPolygon.
public void testParse3DPolygon() throws IOException {
XContentBuilder polygonGeoJson = XContentFactory.jsonBuilder().startObject().field("type", "Polygon").startArray("coordinates").startArray().startArray().value(100.0).value(1.0).value(10.0).endArray().startArray().value(101.0).value(1.0).value(10.0).endArray().startArray().value(101.0).value(0.0).value(10.0).endArray().startArray().value(100.0).value(0.0).value(10.0).endArray().startArray().value(100.0).value(1.0).value(10.0).endArray().endArray().endArray().endObject();
Polygon expected = new Polygon(new LinearRing(new double[] { 100.0, 101.0, 101.0, 100.0, 100.0 }, new double[] { 1.0, 1.0, 0.0, 0.0, 1.0 }, new double[] { 10.0, 10.0, 10.0, 10.0, 10.0 }));
try (XContentParser parser = createParser(polygonGeoJson)) {
parser.nextToken();
assertEquals(expected, new GeoJson(true, false, new GeographyValidator(true)).fromXContent(parser));
}
}
use of org.opensearch.geometry.Polygon in project OpenSearch by opensearch-project.
the class GeometryTestUtils method randomPolygon.
public static Polygon randomPolygon(boolean hasAlt) {
org.apache.lucene.geo.Polygon lucenePolygon = randomValueOtherThanMany(p -> area(p) == 0, GeoTestUtil::nextPolygon);
if (lucenePolygon.numHoles() > 0) {
org.apache.lucene.geo.Polygon[] luceneHoles = lucenePolygon.getHoles();
List<LinearRing> holes = new ArrayList<>();
for (int i = 0; i < lucenePolygon.numHoles(); i++) {
org.apache.lucene.geo.Polygon poly = luceneHoles[i];
holes.add(linearRing(poly.getPolyLons(), poly.getPolyLats(), hasAlt));
}
return new Polygon(linearRing(lucenePolygon.getPolyLons(), lucenePolygon.getPolyLats(), hasAlt), holes);
}
return new Polygon(linearRing(lucenePolygon.getPolyLons(), lucenePolygon.getPolyLats(), hasAlt));
}
use of org.opensearch.geometry.Polygon in project OpenSearch by opensearch-project.
the class GeometryTestUtils method randomMultiPolygon.
public static MultiPolygon randomMultiPolygon(boolean hasAlt) {
int size = OpenSearchTestCase.randomIntBetween(3, 10);
List<Polygon> polygons = new ArrayList<>();
for (int i = 0; i < size; i++) {
polygons.add(randomPolygon(hasAlt));
}
return new MultiPolygon(polygons);
}
Aggregations