Search in sources :

Example 1 with Shape

use of org.locationtech.spatial4j.shape.Shape 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 Shape

use of org.locationtech.spatial4j.shape.Shape 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 Shape

use of org.locationtech.spatial4j.shape.Shape 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 Shape

use of org.locationtech.spatial4j.shape.Shape 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 5 with Shape

use of org.locationtech.spatial4j.shape.Shape in project elasticsearch by elastic.

the class GeoJSONShapeParserTests method testParseOGCPolygonWithoutHoles.

public void testParseOGCPolygonWithoutHoles() throws IOException {
    // test 1: ccw poly not crossing dateline
    String polygonGeoJson = XContentFactory.jsonBuilder().startObject().field("type", "Polygon").startArray("coordinates").startArray().startArray().value(176.0).value(15.0).endArray().startArray().value(-177.0).value(10.0).endArray().startArray().value(-177.0).value(-10.0).endArray().startArray().value(176.0).value(-15.0).endArray().startArray().value(172.0).value(0.0).endArray().startArray().value(176.0).value(15.0).endArray().endArray().endArray().endObject().string();
    XContentParser parser = createParser(JsonXContent.jsonXContent, polygonGeoJson);
    parser.nextToken();
    Shape shape = ShapeBuilder.parse(parser).build();
    ElasticsearchGeoAssertions.assertPolygon(shape);
    // test 2: ccw poly crossing dateline
    polygonGeoJson = XContentFactory.jsonBuilder().startObject().field("type", "Polygon").startArray("coordinates").startArray().startArray().value(-177.0).value(10.0).endArray().startArray().value(176.0).value(15.0).endArray().startArray().value(172.0).value(0.0).endArray().startArray().value(176.0).value(-15.0).endArray().startArray().value(-177.0).value(-10.0).endArray().startArray().value(-177.0).value(10.0).endArray().endArray().endArray().endObject().string();
    parser = createParser(JsonXContent.jsonXContent, polygonGeoJson);
    parser.nextToken();
    shape = ShapeBuilder.parse(parser).build();
    ElasticsearchGeoAssertions.assertMultiPolygon(shape);
    // test 3: cw poly not crossing dateline
    polygonGeoJson = XContentFactory.jsonBuilder().startObject().field("type", "Polygon").startArray("coordinates").startArray().startArray().value(176.0).value(15.0).endArray().startArray().value(180.0).value(10.0).endArray().startArray().value(180.0).value(-10.0).endArray().startArray().value(176.0).value(-15.0).endArray().startArray().value(172.0).value(0.0).endArray().startArray().value(176.0).value(15.0).endArray().endArray().endArray().endObject().string();
    parser = createParser(JsonXContent.jsonXContent, polygonGeoJson);
    parser.nextToken();
    shape = ShapeBuilder.parse(parser).build();
    ElasticsearchGeoAssertions.assertPolygon(shape);
    // test 4: cw poly crossing dateline
    polygonGeoJson = XContentFactory.jsonBuilder().startObject().field("type", "Polygon").startArray("coordinates").startArray().startArray().value(176.0).value(15.0).endArray().startArray().value(184.0).value(15.0).endArray().startArray().value(184.0).value(0.0).endArray().startArray().value(176.0).value(-15.0).endArray().startArray().value(174.0).value(-10.0).endArray().startArray().value(176.0).value(15.0).endArray().endArray().endArray().endObject().string();
    parser = createParser(JsonXContent.jsonXContent, polygonGeoJson);
    parser.nextToken();
    shape = ShapeBuilder.parse(parser).build();
    ElasticsearchGeoAssertions.assertMultiPolygon(shape);
}
Also used : Shape(org.locationtech.spatial4j.shape.Shape) LineString(com.vividsolutions.jts.geom.LineString) MultiLineString(com.vividsolutions.jts.geom.MultiLineString) XContentParser(org.elasticsearch.common.xcontent.XContentParser)

Aggregations

Shape (org.locationtech.spatial4j.shape.Shape)76 Test (org.junit.Test)17 Point (org.locationtech.spatial4j.shape.Point)15 ArrayList (java.util.ArrayList)14 CoordinatesBuilder (org.elasticsearch.common.geo.builders.CoordinatesBuilder)13 SpatialArgs (org.apache.lucene.spatial.query.SpatialArgs)12 PolygonBuilder (org.elasticsearch.common.geo.builders.PolygonBuilder)11 Document (org.apache.lucene.document.Document)10 Field (org.apache.lucene.document.Field)9 Query (org.apache.lucene.search.Query)9 StoredField (org.apache.lucene.document.StoredField)7 LineStringBuilder (org.elasticsearch.common.geo.builders.LineStringBuilder)7 Rectangle (org.locationtech.spatial4j.shape.Rectangle)7 UnitNRShape (org.apache.lucene.spatial.prefix.tree.NumberRangePrefixTree.UnitNRShape)6 SpatialOperation (org.apache.lucene.spatial.query.SpatialOperation)6 StringField (org.apache.lucene.document.StringField)5 IndexableField (org.apache.lucene.index.IndexableField)5 TextField (org.apache.lucene.document.TextField)4 UnsupportedSpatialOperation (org.apache.lucene.spatial.query.UnsupportedSpatialOperation)4 LineString (com.vividsolutions.jts.geom.LineString)3