Search in sources :

Example 81 with Polygon

use of org.locationtech.jts.geom.Polygon in project OpenSearch by opensearch-project.

the class ShapeBuilderTests method testNewPolygon_coordinates.

public void testNewPolygon_coordinates() {
    PolygonBuilder pb = new PolygonBuilder(new CoordinatesBuilder().coordinates(new Coordinate(-45, 30), new Coordinate(45, 30), new Coordinate(45, -30), new Coordinate(-45, -30), new Coordinate(-45, 30)));
    Polygon poly = pb.toPolygonS4J();
    LineString exterior = poly.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));
    LinearRing polygon = pb.toPolygonGeometry().getPolygon();
    assertEquals(polygon.getY(0), 30, 0d);
    assertEquals(polygon.getX(0), -45, 0d);
    assertEquals(polygon.getY(1), 30, 0d);
    assertEquals(polygon.getX(1), 45, 0d);
    assertEquals(polygon.getY(2), -30, 0d);
    assertEquals(polygon.getX(2), 45, 0d);
    assertEquals(polygon.getY(3), -30, 0d);
    assertEquals(polygon.getX(3), -45, 0d);
}
Also used : CoordinatesBuilder(org.opensearch.common.geo.builders.CoordinatesBuilder) Coordinate(org.locationtech.jts.geom.Coordinate) OpenSearchGeoAssertions.assertMultiLineString(org.opensearch.test.hamcrest.OpenSearchGeoAssertions.assertMultiLineString) LineString(org.locationtech.jts.geom.LineString) OpenSearchGeoAssertions.assertPolygon(org.opensearch.test.hamcrest.OpenSearchGeoAssertions.assertPolygon) OpenSearchGeoAssertions.assertMultiPolygon(org.opensearch.test.hamcrest.OpenSearchGeoAssertions.assertMultiPolygon) Polygon(org.locationtech.jts.geom.Polygon) LinearRing(org.opensearch.geometry.LinearRing) PolygonBuilder(org.opensearch.common.geo.builders.PolygonBuilder)

Example 82 with Polygon

use of org.locationtech.jts.geom.Polygon in project OpenSearch by opensearch-project.

the class ShapeBuilderTests method testNewPolygon.

public void testNewPolygon() {
    PolygonBuilder pb = new PolygonBuilder(new CoordinatesBuilder().coordinate(-45, 30).coordinate(45, 30).coordinate(45, -30).coordinate(-45, -30).coordinate(-45, 30));
    Polygon poly = pb.toPolygonS4J();
    LineString exterior = poly.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));
    LinearRing polygon = pb.toPolygonGeometry().getPolygon();
    assertEquals(polygon.getY(0), 30, 0d);
    assertEquals(polygon.getX(0), -45, 0d);
    assertEquals(polygon.getY(1), 30, 0d);
    assertEquals(polygon.getX(1), 45, 0d);
    assertEquals(polygon.getY(2), -30, 0d);
    assertEquals(polygon.getX(2), 45, 0d);
    assertEquals(polygon.getY(3), -30, 0d);
    assertEquals(polygon.getX(3), -45, 0d);
}
Also used : CoordinatesBuilder(org.opensearch.common.geo.builders.CoordinatesBuilder) OpenSearchGeoAssertions.assertMultiLineString(org.opensearch.test.hamcrest.OpenSearchGeoAssertions.assertMultiLineString) LineString(org.locationtech.jts.geom.LineString) Coordinate(org.locationtech.jts.geom.Coordinate) OpenSearchGeoAssertions.assertPolygon(org.opensearch.test.hamcrest.OpenSearchGeoAssertions.assertPolygon) OpenSearchGeoAssertions.assertMultiPolygon(org.opensearch.test.hamcrest.OpenSearchGeoAssertions.assertMultiPolygon) Polygon(org.locationtech.jts.geom.Polygon) LinearRing(org.opensearch.geometry.LinearRing) PolygonBuilder(org.opensearch.common.geo.builders.PolygonBuilder)

Example 83 with Polygon

use of org.locationtech.jts.geom.Polygon in project OpenSearch by opensearch-project.

the class GeoWKTShapeParserTests method testParseMultiPolygon.

@Override
public void testParseMultiPolygon() throws IOException, ParseException {
    int numPolys = randomIntBetween(0, 8);
    MultiPolygonBuilder builder = new MultiPolygonBuilder();
    PolygonBuilder pb;
    Coordinate[] coordinates;
    Polygon[] shapes = new Polygon[numPolys];
    LinearRing shell;
    for (int i = 0; i < numPolys; ++i) {
        pb = PolygonBuilder.class.cast(RandomShapeGenerator.createShape(random(), RandomShapeGenerator.ShapeType.POLYGON));
        builder.polygon(pb);
        coordinates = pb.coordinates()[0][0];
        shell = GEOMETRY_FACTORY.createLinearRing(coordinates);
        shapes[i] = GEOMETRY_FACTORY.createPolygon(shell, null);
    }
    assumeTrue("JTS test path cannot handle empty multipolygon", numPolys > 1);
    Shape expected = shapeCollection(shapes);
    assertExpected(expected, builder, true);
    assertMalformed(builder);
}
Also used : Shape(org.locationtech.spatial4j.shape.Shape) Coordinate(org.locationtech.jts.geom.Coordinate) MultiPolygonBuilder(org.opensearch.common.geo.builders.MultiPolygonBuilder) Polygon(org.locationtech.jts.geom.Polygon) LinearRing(org.locationtech.jts.geom.LinearRing) MultiPoint(org.opensearch.geometry.MultiPoint) JtsPoint(org.locationtech.spatial4j.shape.jts.JtsPoint) Point(org.locationtech.jts.geom.Point) MultiPolygonBuilder(org.opensearch.common.geo.builders.MultiPolygonBuilder) PolygonBuilder(org.opensearch.common.geo.builders.PolygonBuilder)

Example 84 with Polygon

use of org.locationtech.jts.geom.Polygon in project OpenSearch by opensearch-project.

the class GeoWKTShapeParserTests method testParsePolygon.

@Override
public void testParsePolygon() throws IOException, ParseException {
    PolygonBuilder builder = PolygonBuilder.class.cast(RandomShapeGenerator.createShape(random(), RandomShapeGenerator.ShapeType.POLYGON));
    Coordinate[] coords = builder.coordinates()[0][0];
    LinearRing shell = GEOMETRY_FACTORY.createLinearRing(coords);
    Polygon expected = GEOMETRY_FACTORY.createPolygon(shell, null);
    assertExpected(jtsGeom(expected), builder, true);
    assertMalformed(builder);
}
Also used : Coordinate(org.locationtech.jts.geom.Coordinate) LinearRing(org.locationtech.jts.geom.LinearRing) Polygon(org.locationtech.jts.geom.Polygon) MultiPolygonBuilder(org.opensearch.common.geo.builders.MultiPolygonBuilder) PolygonBuilder(org.opensearch.common.geo.builders.PolygonBuilder)

Example 85 with Polygon

use of org.locationtech.jts.geom.Polygon in project OpenSearch by opensearch-project.

the class GeoWKTShapeParserTests method testParsePolygonWithHole.

public void testParsePolygonWithHole() throws IOException, ParseException {
    // add 3d point to test ISSUE #10501
    List<Coordinate> shellCoordinates = new ArrayList<>();
    shellCoordinates.add(new Coordinate(100, 0));
    shellCoordinates.add(new Coordinate(101, 0));
    shellCoordinates.add(new Coordinate(101, 1));
    shellCoordinates.add(new Coordinate(100, 1));
    shellCoordinates.add(new Coordinate(100, 0));
    List<Coordinate> holeCoordinates = new ArrayList<>();
    holeCoordinates.add(new Coordinate(100.2, 0.2));
    holeCoordinates.add(new Coordinate(100.8, 0.2));
    holeCoordinates.add(new Coordinate(100.8, 0.8));
    holeCoordinates.add(new Coordinate(100.2, 0.8));
    holeCoordinates.add(new Coordinate(100.2, 0.2));
    PolygonBuilder polygonWithHole = new PolygonBuilder(new CoordinatesBuilder().coordinates(shellCoordinates));
    polygonWithHole.hole(new LineStringBuilder(holeCoordinates));
    LinearRing shell = GEOMETRY_FACTORY.createLinearRing(shellCoordinates.toArray(new Coordinate[shellCoordinates.size()]));
    LinearRing[] holes = new LinearRing[1];
    holes[0] = GEOMETRY_FACTORY.createLinearRing(holeCoordinates.toArray(new Coordinate[holeCoordinates.size()]));
    Polygon expected = GEOMETRY_FACTORY.createPolygon(shell, holes);
    assertExpected(jtsGeom(expected), polygonWithHole, true);
    org.opensearch.geometry.LinearRing hole = new org.opensearch.geometry.LinearRing(new double[] { 100.2d, 100.8d, 100.8d, 100.2d, 100.2d }, new double[] { 0.8d, 0.8d, 0.2d, 0.2d, 0.8d });
    org.opensearch.geometry.Polygon p = new org.opensearch.geometry.Polygon(new org.opensearch.geometry.LinearRing(new double[] { 101d, 101d, 100d, 100d, 101d }, new double[] { 0d, 1d, 1d, 0d, 0d }), Collections.singletonList(hole));
    assertExpected(p, polygonWithHole, false);
    assertMalformed(polygonWithHole);
}
Also used : ArrayList(java.util.ArrayList) MultiLineStringBuilder(org.opensearch.common.geo.builders.MultiLineStringBuilder) LineStringBuilder(org.opensearch.common.geo.builders.LineStringBuilder) CoordinatesBuilder(org.opensearch.common.geo.builders.CoordinatesBuilder) Coordinate(org.locationtech.jts.geom.Coordinate) LinearRing(org.locationtech.jts.geom.LinearRing) Polygon(org.locationtech.jts.geom.Polygon) MultiPolygonBuilder(org.opensearch.common.geo.builders.MultiPolygonBuilder) PolygonBuilder(org.opensearch.common.geo.builders.PolygonBuilder)

Aggregations

Polygon (org.locationtech.jts.geom.Polygon)179 MultiPolygon (org.locationtech.jts.geom.MultiPolygon)89 Coordinate (org.locationtech.jts.geom.Coordinate)78 LinearRing (org.locationtech.jts.geom.LinearRing)55 Point (org.locationtech.jts.geom.Point)54 Test (org.junit.Test)51 Geometry (org.locationtech.jts.geom.Geometry)48 LineString (org.locationtech.jts.geom.LineString)48 ArrayList (java.util.ArrayList)37 GeometryFactory (org.locationtech.jts.geom.GeometryFactory)30 MultiPoint (org.locationtech.jts.geom.MultiPoint)29 MultiLineString (org.locationtech.jts.geom.MultiLineString)19 List (java.util.List)15 Test (org.junit.jupiter.api.Test)15 GeometryCollection (org.locationtech.jts.geom.GeometryCollection)12 WKTReader (org.locationtech.jts.io.WKTReader)12 HashMap (java.util.HashMap)9 CustomCoordinateSequence (org.apache.jena.geosparql.implementation.jts.CustomCoordinateSequence)8 ParseException (org.locationtech.jts.io.ParseException)7 IOReport (eu.esdihumboldt.hale.common.core.io.report.IOReport)5