Search in sources :

Example 6 with CoordinatesBuilder

use of org.elasticsearch.common.geo.builders.CoordinatesBuilder 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 7 with CoordinatesBuilder

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

the class ShapeBuilderTests method testPolygonWrapping.

public void testPolygonWrapping() {
    Shape shape = ShapeBuilders.newPolygon(new CoordinatesBuilder().coordinate(-150.0, 65.0).coordinate(-250.0, 65.0).coordinate(-250.0, -65.0).coordinate(-150.0, -65.0).close()).build();
    assertMultiPolygon(shape);
}
Also used : CoordinatesBuilder(org.elasticsearch.common.geo.builders.CoordinatesBuilder) Shape(org.locationtech.spatial4j.shape.Shape)

Example 8 with CoordinatesBuilder

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

the class ShapeBuilderTests method testNewPolygon_coordinates.

public void testNewPolygon_coordinates() {
    Polygon polygon = ShapeBuilders.newPolygon(new CoordinatesBuilder().coordinates(new Coordinate(-45, 30), new Coordinate(45, 30), new Coordinate(45, -30), new Coordinate(-45, -30), new Coordinate(-45, 30))).toPolygon();
    LineString exterior = polygon.getExteriorRing();
    assertEquals(exterior.getCoordinateN(0), new Coordinate(-45, 30));
    assertEquals(exterior.getCoordinateN(1), new Coordinate(45, 30));
    assertEquals(exterior.getCoordinateN(2), new Coordinate(45, -30));
    assertEquals(exterior.getCoordinateN(3), new Coordinate(-45, -30));
}
Also used : CoordinatesBuilder(org.elasticsearch.common.geo.builders.CoordinatesBuilder) Coordinate(com.vividsolutions.jts.geom.Coordinate) LineString(com.vividsolutions.jts.geom.LineString) ElasticsearchGeoAssertions.assertMultiLineString(org.elasticsearch.test.hamcrest.ElasticsearchGeoAssertions.assertMultiLineString) ElasticsearchGeoAssertions.assertPolygon(org.elasticsearch.test.hamcrest.ElasticsearchGeoAssertions.assertPolygon) ElasticsearchGeoAssertions.assertMultiPolygon(org.elasticsearch.test.hamcrest.ElasticsearchGeoAssertions.assertMultiPolygon) Polygon(com.vividsolutions.jts.geom.Polygon)

Example 9 with CoordinatesBuilder

use of org.elasticsearch.common.geo.builders.CoordinatesBuilder 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 10 with CoordinatesBuilder

use of org.elasticsearch.common.geo.builders.CoordinatesBuilder 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)26 PolygonBuilder (org.elasticsearch.common.geo.builders.PolygonBuilder)18 LineStringBuilder (org.elasticsearch.common.geo.builders.LineStringBuilder)14 Shape (org.locationtech.spatial4j.shape.Shape)13 InvalidShapeException (org.locationtech.spatial4j.exception.InvalidShapeException)6 Coordinate (com.vividsolutions.jts.geom.Coordinate)4 LineString (com.vividsolutions.jts.geom.LineString)3 Polygon (com.vividsolutions.jts.geom.Polygon)3 ElasticsearchGeoAssertions.assertMultiLineString (org.elasticsearch.test.hamcrest.ElasticsearchGeoAssertions.assertMultiLineString)3 ElasticsearchGeoAssertions.assertMultiPolygon (org.elasticsearch.test.hamcrest.ElasticsearchGeoAssertions.assertMultiPolygon)3 ElasticsearchGeoAssertions.assertPolygon (org.elasticsearch.test.hamcrest.ElasticsearchGeoAssertions.assertPolygon)3 SearchResponse (org.elasticsearch.action.search.SearchResponse)2 MultiPolygonBuilder (org.elasticsearch.common.geo.builders.MultiPolygonBuilder)2 ConvexHull (com.vividsolutions.jts.algorithm.ConvexHull)1 Geometry (com.vividsolutions.jts.geom.Geometry)1 ElasticsearchException (org.elasticsearch.ElasticsearchException)1 CreateIndexRequestBuilder (org.elasticsearch.action.admin.indices.create.CreateIndexRequestBuilder)1 BytesReference (org.elasticsearch.common.bytes.BytesReference)1 CoordinateCollection (org.elasticsearch.common.geo.builders.CoordinateCollection)1 MultiLineStringBuilder (org.elasticsearch.common.geo.builders.MultiLineStringBuilder)1