use of org.opensearch.common.geo.builders.CoordinatesBuilder in project OpenSearch by opensearch-project.
the class ShapeBuilderTests method testComplexShapeWithHole.
public void testComplexShapeWithHole() {
PolygonBuilder builder = new PolygonBuilder(new CoordinatesBuilder().coordinate(-85.0018514, 37.1311314).coordinate(-85.0016645, 37.1315293).coordinate(-85.0016246, 37.1317069).coordinate(-85.0016526, 37.1318183).coordinate(-85.0017119, 37.1319196).coordinate(-85.0019371, 37.1321182).coordinate(-85.0019972, 37.1322115).coordinate(-85.0019942, 37.1323234).coordinate(-85.0019543, 37.1324336).coordinate(-85.001906, 37.1324985).coordinate(-85.001834, 37.1325497).coordinate(-85.0016965, 37.1325907).coordinate(-85.0016011, 37.1325873).coordinate(-85.0014816, 37.1325353).coordinate(-85.0011755, 37.1323509).coordinate(-85.000955, 37.1322802).coordinate(-85.0006241, 37.1322529).coordinate(-85.0000002, 37.1322307).coordinate(-84.9994, 37.1323001).coordinate(-84.999109, 37.1322864).coordinate(-84.998934, 37.1322415).coordinate(-84.9988639, 37.1321888).coordinate(-84.9987841, 37.1320944).coordinate(-84.9987208, 37.131954).coordinate(-84.998736, 37.1316611).coordinate(-84.9988091, 37.131334).coordinate(-84.9989283, 37.1311337).coordinate(-84.9991943, 37.1309198).coordinate(-84.9993573, 37.1308459).coordinate(-84.9995888, 37.1307924).coordinate(-84.9998746, 37.130806).coordinate(-85.0000002, 37.1308358).coordinate(-85.0004984, 37.1310658).coordinate(-85.0008008, 37.1311625).coordinate(-85.0009461, 37.1311684).coordinate(-85.0011373, 37.1311515).coordinate(-85.0016455, 37.1310491).coordinate(-85.0018514, 37.1311314));
builder.hole(new LineStringBuilder(new CoordinatesBuilder().coordinate(-85.0000002, 37.1317672).coordinate(-85.0001983, 37.1317538).coordinate(-85.0003378, 37.1317582).coordinate(-85.0004697, 37.131792).coordinate(-85.0008048, 37.1319439).coordinate(-85.0009342, 37.1319838).coordinate(-85.0010184, 37.1319463).coordinate(-85.0010618, 37.13184).coordinate(-85.0010057, 37.1315102).coordinate(-85.000977, 37.1314403).coordinate(-85.0009182, 37.1313793).coordinate(-85.0005366, 37.1312209).coordinate(-85.000224, 37.1311466).coordinate(-85.000087, 37.1311356).coordinate(-85.0000002, 37.1311433).coordinate(-84.9995021, 37.1312336).coordinate(-84.9993308, 37.1312859).coordinate(-84.9992567, 37.1313252).coordinate(-84.9991868, 37.1314277).coordinate(-84.9991593, 37.1315381).coordinate(-84.9991841, 37.1316527).coordinate(-84.9992329, 37.1317117).coordinate(-84.9993527, 37.1317788).coordinate(-84.9994931, 37.1318061).coordinate(-84.9996815, 37.1317979).coordinate(-85.0000002, 37.1317672)));
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 testPolygonSelfIntersection.
public void testPolygonSelfIntersection() {
PolygonBuilder newPolygon = new PolygonBuilder(new CoordinatesBuilder().coordinate(-40.0, 50.0).coordinate(40.0, 50.0).coordinate(-40.0, -50.0).coordinate(40.0, -50.0).close());
Exception e = expectThrows(InvalidShapeException.class, () -> newPolygon.buildS4J());
assertThat(e.getMessage(), containsString("Self-intersection at or near point (0.0"));
}
use of org.opensearch.common.geo.builders.CoordinatesBuilder 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"));
}
use of org.opensearch.common.geo.builders.CoordinatesBuilder 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);
}
use of org.opensearch.common.geo.builders.CoordinatesBuilder in project OpenSearch by opensearch-project.
the class ShapeBuilderTests method testShapeWithAlternateOrientation.
public void testShapeWithAlternateOrientation() {
// cw: should produce a multi polygon spanning hemispheres
PolygonBuilder builder = new PolygonBuilder(new CoordinatesBuilder().coordinate(180, 0).coordinate(176, 4).coordinate(-176, 4).coordinate(180, 0));
assertPolygon(builder.close().buildS4J(), true);
assertPolygon(buildGeometry(builder.close()), false);
// cw: geo core will convert to ccw across the dateline
builder = new PolygonBuilder(new CoordinatesBuilder().coordinate(180, 0).coordinate(-176, 4).coordinate(176, 4).coordinate(180, 0));
assertMultiPolygon(builder.close().buildS4J(), true);
assertMultiPolygon(buildGeometry(builder.close()), false);
}
Aggregations