Search in sources :

Example 1 with PolygonBuilder

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

the class ShapeBuilderTests method testBoundaryShapeWithTangentialHole.

public void testBoundaryShapeWithTangentialHole() {
    // test a shape with one tangential (shared) vertex for each hole (should pass)
    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(-177, 10).coordinate(-178, -10).coordinate(-180, -5).coordinate(-180, 5).coordinate(-177, 10)));
    builder.hole(new LineStringBuilder(new CoordinatesBuilder().coordinate(172, 0).coordinate(176, 10).coordinate(176, -5).coordinate(172, 0)));
    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 2 with PolygonBuilder

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

the class ShapeBuilderTests method testShapeWithEdgeAlongDateline.

public void testShapeWithEdgeAlongDateline() {
    // test case 1: test the positive side of the dateline
    PolygonBuilder builder = ShapeBuilders.newPolygon(new CoordinatesBuilder().coordinate(180, 0).coordinate(176, 4).coordinate(180, -4).coordinate(180, 0));
    Shape shape = builder.close().build();
    assertPolygon(shape);
    // test case 2: test the negative side of the dateline
    builder = ShapeBuilders.newPolygon(new CoordinatesBuilder().coordinate(-176, 4).coordinate(-180, 0).coordinate(-180, -4).coordinate(-176, 4));
    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)

Example 3 with PolygonBuilder

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

the class ShapeBuilderTests method testBoundaryShape.

/**
     * Test an enveloping polygon around the max mercator bounds
     */
public void testBoundaryShape() {
    PolygonBuilder builder = ShapeBuilders.newPolygon(new CoordinatesBuilder().coordinate(-180, 90).coordinate(180, 90).coordinate(180, -90).coordinate(-180, 90));
    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)

Example 4 with PolygonBuilder

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

the class ShapeBuilderTests method testBoundaryShapeWithInvalidTangentialHole.

public void testBoundaryShapeWithInvalidTangentialHole() {
    // test shape with two tangential (shared) vertices (should throw exception)
    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(-177, 10).coordinate(172, 0).coordinate(180, -5).coordinate(176, -10).coordinate(-177, 10)));
    Exception e = expectThrows(InvalidShapeException.class, () -> builder.close().build());
    assertThat(e.getMessage(), containsString("interior cannot share more than one point with the exterior"));
}
Also used : CoordinatesBuilder(org.elasticsearch.common.geo.builders.CoordinatesBuilder) PolygonBuilder(org.elasticsearch.common.geo.builders.PolygonBuilder) LineStringBuilder(org.elasticsearch.common.geo.builders.LineStringBuilder) InvalidShapeException(org.locationtech.spatial4j.exception.InvalidShapeException)

Example 5 with PolygonBuilder

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

the class ShapeBuilderTests method testShapeWithPointOnDateline.

public void testShapeWithPointOnDateline() {
    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);
}
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