Search in sources :

Example 11 with PolygonBuilder

use of org.elasticsearch.common.geo.builders.PolygonBuilder in project elasticsearch by elastic.

the class ShapeBuilderTests method testPolygonSelfIntersection.

public void testPolygonSelfIntersection() {
    PolygonBuilder newPolygon = ShapeBuilders.newPolygon(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.build());
    assertThat(e.getMessage(), containsString("Self-intersection at or near point (0.0"));
}
Also used : CoordinatesBuilder(org.elasticsearch.common.geo.builders.CoordinatesBuilder) PolygonBuilder(org.elasticsearch.common.geo.builders.PolygonBuilder) InvalidShapeException(org.locationtech.spatial4j.exception.InvalidShapeException)

Example 12 with PolygonBuilder

use of org.elasticsearch.common.geo.builders.PolygonBuilder 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);
}
Also used : CoordinatesBuilder(org.elasticsearch.common.geo.builders.CoordinatesBuilder) Shape(org.locationtech.spatial4j.shape.Shape) PolygonBuilder(org.elasticsearch.common.geo.builders.PolygonBuilder) LineStringBuilder(org.elasticsearch.common.geo.builders.LineStringBuilder)

Example 13 with PolygonBuilder

use of org.elasticsearch.common.geo.builders.PolygonBuilder 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);
}
Also used : CoordinatesBuilder(org.elasticsearch.common.geo.builders.CoordinatesBuilder) Shape(org.locationtech.spatial4j.shape.Shape) PolygonBuilder(org.elasticsearch.common.geo.builders.PolygonBuilder) LineStringBuilder(org.elasticsearch.common.geo.builders.LineStringBuilder)

Example 14 with PolygonBuilder

use of org.elasticsearch.common.geo.builders.PolygonBuilder in project elasticsearch by elastic.

the class ShapeBuilderTests method testShapeWithHoleAtEdgeEndPoints.

public void testShapeWithHoleAtEdgeEndPoints() {
    PolygonBuilder builder = ShapeBuilders.newPolygon(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)));
    Shape shape = builder.close().build();
    assertPolygon(shape);
}
Also used : CoordinatesBuilder(org.elasticsearch.common.geo.builders.CoordinatesBuilder) Shape(org.locationtech.spatial4j.shape.Shape) PolygonBuilder(org.elasticsearch.common.geo.builders.PolygonBuilder) LineStringBuilder(org.elasticsearch.common.geo.builders.LineStringBuilder)

Example 15 with PolygonBuilder

use of org.elasticsearch.common.geo.builders.PolygonBuilder in project elasticsearch by elastic.

the class ShapeBuilderTests method testShapeWithAlternateOrientation.

public void testShapeWithAlternateOrientation() {
    // cw: should produce a multi polygon spanning hemispheres
    PolygonBuilder builder = ShapeBuilders.newPolygon(new CoordinatesBuilder().coordinate(180, 0).coordinate(176, 4).coordinate(-176, 4).coordinate(180, 0));
    Shape shape = builder.close().build();
    assertPolygon(shape);
    // cw: geo core will convert to ccw across the dateline
    builder = ShapeBuilders.newPolygon(new CoordinatesBuilder().coordinate(180, 0).coordinate(-176, 4).coordinate(176, 4).coordinate(180, 0));
    shape = builder.close().build();
    assertMultiPolygon(shape);
}
Also used : CoordinatesBuilder(org.elasticsearch.common.geo.builders.CoordinatesBuilder) Shape(org.locationtech.spatial4j.shape.Shape) PolygonBuilder(org.elasticsearch.common.geo.builders.PolygonBuilder)

Aggregations

CoordinatesBuilder (org.elasticsearch.common.geo.builders.CoordinatesBuilder)18 PolygonBuilder (org.elasticsearch.common.geo.builders.PolygonBuilder)18 LineStringBuilder (org.elasticsearch.common.geo.builders.LineStringBuilder)12 Shape (org.locationtech.spatial4j.shape.Shape)11 InvalidShapeException (org.locationtech.spatial4j.exception.InvalidShapeException)6 MultiPolygonBuilder (org.elasticsearch.common.geo.builders.MultiPolygonBuilder)2 ConvexHull (com.vividsolutions.jts.algorithm.ConvexHull)1 Coordinate (com.vividsolutions.jts.geom.Coordinate)1 Geometry (com.vividsolutions.jts.geom.Geometry)1 ElasticsearchException (org.elasticsearch.ElasticsearchException)1 CreateIndexRequestBuilder (org.elasticsearch.action.admin.indices.create.CreateIndexRequestBuilder)1 SearchResponse (org.elasticsearch.action.search.SearchResponse)1 BytesReference (org.elasticsearch.common.bytes.BytesReference)1 CoordinateCollection (org.elasticsearch.common.geo.builders.CoordinateCollection)1 MultiLineStringBuilder (org.elasticsearch.common.geo.builders.MultiLineStringBuilder)1 MultiPointBuilder (org.elasticsearch.common.geo.builders.MultiPointBuilder)1 PointBuilder (org.elasticsearch.common.geo.builders.PointBuilder)1 Point (org.locationtech.spatial4j.shape.Point)1