use of org.elasticsearch.common.geo.builders.LineStringBuilder in project elasticsearch by elastic.
the class GeoShapeQueryTests method testReusableBuilder.
public void testReusableBuilder() throws IOException {
ShapeBuilder polygon = ShapeBuilders.newPolygon(new CoordinatesBuilder().coordinate(170, -10).coordinate(190, -10).coordinate(190, 10).coordinate(170, 10).close()).hole(new LineStringBuilder(new CoordinatesBuilder().coordinate(175, -5).coordinate(185, -5).coordinate(185, 5).coordinate(175, 5).close()));
assertUnmodified(polygon);
ShapeBuilder linestring = ShapeBuilders.newLineString(new CoordinatesBuilder().coordinate(170, -10).coordinate(190, -10).coordinate(190, 10).coordinate(170, 10).close());
assertUnmodified(linestring);
}
use of org.elasticsearch.common.geo.builders.LineStringBuilder in project elasticsearch by elastic.
the class ShapeBuilderTests method testShapeWithTangentialHole.
public void testShapeWithTangentialHole() {
// test a shape with one tangential (shared) vertex (should pass)
PolygonBuilder builder = ShapeBuilders.newPolygon(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)));
Shape shape = builder.close().build();
assertMultiPolygon(shape);
}
use of org.elasticsearch.common.geo.builders.LineStringBuilder in project elasticsearch by elastic.
the class ShapeBuilderTests method testShapeWithInvalidTangentialHole.
public void testShapeWithInvalidTangentialHole() {
// test a shape with one invalid tangential (shared) vertex (should throw exception)
PolygonBuilder builder = ShapeBuilders.newPolygon(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 = expectThrows(InvalidShapeException.class, () -> builder.close().build());
assertThat(e.getMessage(), containsString("interior cannot share more than one point with the exterior"));
}
use of org.elasticsearch.common.geo.builders.LineStringBuilder in project elasticsearch by elastic.
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 = ShapeBuilders.newPolygon(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)));
Shape shape = builder.close().build();
assertMultiPolygon(shape);
}
use of org.elasticsearch.common.geo.builders.LineStringBuilder in project elasticsearch by elastic.
the class ShapeBuilderTests method testShapeWithBoundaryHoles.
public void testShapeWithBoundaryHoles() {
// test case 1: test the positive side of the dateline
PolygonBuilder builder = ShapeBuilders.newPolygon(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)));
Shape shape = builder.close().build();
assertMultiPolygon(shape);
// test case 2: test the negative side of the dateline
builder = ShapeBuilders.newPolygon(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()));
shape = builder.close().build();
assertMultiPolygon(shape);
}
Aggregations