Search in sources :

Example 16 with CoordinatesBuilder

use of org.elasticsearch.common.geo.builders.CoordinatesBuilder 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"));
}
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 17 with CoordinatesBuilder

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

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

the class ShapeBuilderTests method testNewPolygon_coordinate.

public void testNewPolygon_coordinate() {
    Polygon polygon = ShapeBuilders.newPolygon(new CoordinatesBuilder().coordinate(new Coordinate(-45, 30)).coordinate(new Coordinate(45, 30)).coordinate(new Coordinate(45, -30)).coordinate(new Coordinate(-45, -30)).coordinate(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 19 with CoordinatesBuilder

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

the class ShapeBuilderTests method testLineStringWrapping.

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

Example 20 with CoordinatesBuilder

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

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