Search in sources :

Example 1 with MultiPolygon

use of org.opensearch.geometry.MultiPolygon in project OpenSearch by opensearch-project.

the class GeometryIO method readMultiPolygon.

private static MultiPolygon readMultiPolygon(StreamInput in) throws IOException {
    // orientation for BWC
    in.readBoolean();
    int size = in.readVInt();
    List<Polygon> polygons = new ArrayList<>(size);
    for (int i = 0; i < size; i++) {
        polygons.add(readPolygon(in));
    }
    return new MultiPolygon(polygons);
}
Also used : MultiPolygon(org.opensearch.geometry.MultiPolygon) ArrayList(java.util.ArrayList) Polygon(org.opensearch.geometry.Polygon) MultiPolygon(org.opensearch.geometry.MultiPolygon) Point(org.opensearch.geometry.Point) MultiPoint(org.opensearch.geometry.MultiPoint)

Example 2 with MultiPolygon

use of org.opensearch.geometry.MultiPolygon in project OpenSearch by opensearch-project.

the class GeometryIndexerTests method testPolygon.

public void testPolygon() {
    Polygon polygon = new Polygon(new LinearRing(new double[] { 160, 200, 200, 160, 160 }, new double[] { 10, 10, 20, 20, 10 }));
    Geometry indexed = new MultiPolygon(Arrays.asList(new Polygon(new LinearRing(new double[] { 180, 180, 160, 160, 180 }, new double[] { 10, 20, 20, 10, 10 })), new Polygon(new LinearRing(new double[] { -180, -180, -160, -160, -180 }, new double[] { 20, 10, 10, 20, 20 }))));
    assertEquals(indexed, indexer.prepareForIndexing(polygon));
    polygon = new Polygon(new LinearRing(new double[] { 160, 200, 200, 160, 160 }, new double[] { 10, 10, 20, 20, 10 }), Collections.singletonList(new LinearRing(new double[] { 165, 165, 195, 195, 165 }, new double[] { 12, 18, 18, 12, 12 })));
    indexed = new MultiPolygon(Arrays.asList(new Polygon(new LinearRing(new double[] { 180, 180, 165, 165, 180, 180, 160, 160, 180 }, new double[] { 10, 12, 12, 18, 18, 20, 20, 10, 10 })), new Polygon(new LinearRing(new double[] { -180, -180, -160, -160, -180, -180, -165, -165, -180 }, new double[] { 12, 10, 10, 20, 20, 18, 18, 12, 12 }))));
    assertEquals(indexed, indexer.prepareForIndexing(polygon));
}
Also used : Geometry(org.opensearch.geometry.Geometry) MultiPolygon(org.opensearch.geometry.MultiPolygon) Polygon(org.opensearch.geometry.Polygon) MultiPolygon(org.opensearch.geometry.MultiPolygon) LinearRing(org.opensearch.geometry.LinearRing)

Example 3 with MultiPolygon

use of org.opensearch.geometry.MultiPolygon in project OpenSearch by opensearch-project.

the class GeometryTestUtils method randomMultiPolygon.

public static MultiPolygon randomMultiPolygon(boolean hasAlt) {
    int size = OpenSearchTestCase.randomIntBetween(3, 10);
    List<Polygon> polygons = new ArrayList<>();
    for (int i = 0; i < size; i++) {
        polygons.add(randomPolygon(hasAlt));
    }
    return new MultiPolygon(polygons);
}
Also used : MultiPolygon(org.opensearch.geometry.MultiPolygon) ArrayList(java.util.ArrayList) Polygon(org.opensearch.geometry.Polygon) MultiPolygon(org.opensearch.geometry.MultiPolygon) Point(org.opensearch.geometry.Point) MultiPoint(org.opensearch.geometry.MultiPoint)

Example 4 with MultiPolygon

use of org.opensearch.geometry.MultiPolygon in project OpenSearch by opensearch-project.

the class GeoJsonParserTests method testParseMultiPolygon.

@Override
public void testParseMultiPolygon() throws IOException {
    // two polygons; one without hole, one with hole
    XContentBuilder multiPolygonGeoJson = XContentFactory.jsonBuilder().startObject().field("type", "MultiPolygon").startArray("coordinates").startArray().startArray().startArray().value(102.0).value(2.0).endArray().startArray().value(103.0).value(2.0).endArray().startArray().value(103.0).value(3.0).endArray().startArray().value(102.0).value(3.0).endArray().startArray().value(102.0).value(2.0).endArray().endArray().endArray().startArray().startArray().startArray().value(100.0).value(0.0).endArray().startArray().value(101.0).value(0.0).endArray().startArray().value(101.0).value(1.0).endArray().startArray().value(100.0).value(1.0).endArray().startArray().value(100.0).value(0.0).endArray().endArray().startArray().startArray().value(100.2).value(0.8).endArray().startArray().value(100.2).value(0.2).endArray().startArray().value(100.8).value(0.2).endArray().startArray().value(100.8).value(0.8).endArray().startArray().value(100.2).value(0.8).endArray().endArray().endArray().endArray().endObject();
    LinearRing hole = new LinearRing(new double[] { 100.2d, 100.2d, 100.8d, 100.8d, 100.2d }, new double[] { 0.8d, 0.2d, 0.2d, 0.8d, 0.8d });
    MultiPolygon polygons = new MultiPolygon(Arrays.asList(new Polygon(new LinearRing(new double[] { 102d, 103d, 103d, 102d, 102d }, new double[] { 2d, 2d, 3d, 3d, 2d })), new Polygon(new LinearRing(new double[] { 100d, 101d, 101d, 100d, 100d }, new double[] { 0d, 0d, 1d, 1d, 0d }), Collections.singletonList(hole))));
    assertGeometryEquals(polygons, multiPolygonGeoJson);
}
Also used : MultiPolygon(org.opensearch.geometry.MultiPolygon) LinearRing(org.opensearch.geometry.LinearRing) Polygon(org.opensearch.geometry.Polygon) MultiPolygon(org.opensearch.geometry.MultiPolygon) XContentBuilder(org.opensearch.common.xcontent.XContentBuilder)

Aggregations

MultiPolygon (org.opensearch.geometry.MultiPolygon)4 Polygon (org.opensearch.geometry.Polygon)4 ArrayList (java.util.ArrayList)2 LinearRing (org.opensearch.geometry.LinearRing)2 MultiPoint (org.opensearch.geometry.MultiPoint)2 Point (org.opensearch.geometry.Point)2 XContentBuilder (org.opensearch.common.xcontent.XContentBuilder)1 Geometry (org.opensearch.geometry.Geometry)1