Search in sources :

Example 1 with LinearRing

use of com.vividsolutions.jts.geom.LinearRing in project elasticsearch by elastic.

the class PolygonBuilder method polygon.

protected static Polygon polygon(GeometryFactory factory, Coordinate[][] polygon) {
    LinearRing shell = factory.createLinearRing(polygon[0]);
    LinearRing[] holes;
    if (polygon.length > 1) {
        holes = new LinearRing[polygon.length - 1];
        for (int i = 0; i < holes.length; i++) {
            holes[i] = factory.createLinearRing(polygon[i + 1]);
        }
    } else {
        holes = null;
    }
    return factory.createPolygon(shell, holes);
}
Also used : LinearRing(com.vividsolutions.jts.geom.LinearRing)

Example 2 with LinearRing

use of com.vividsolutions.jts.geom.LinearRing in project elasticsearch by elastic.

the class GeoJSONShapeParserTests method testParsePolygonWithHole.

public void testParsePolygonWithHole() throws IOException {
    XContentBuilder polygonGeoJson = XContentFactory.jsonBuilder().startObject().field("type", "Polygon").startArray("coordinates").startArray().startArray().value(100.0).value(1.0).endArray().startArray().value(101.0).value(1.0).endArray().startArray().value(101.0).value(0.0).endArray().startArray().value(100.0).value(0.0).endArray().startArray().value(100.0).value(1.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().endObject();
    // add 3d point to test ISSUE #10501
    List<Coordinate> shellCoordinates = new ArrayList<>();
    shellCoordinates.add(new Coordinate(100, 0, 15.0));
    shellCoordinates.add(new Coordinate(101, 0));
    shellCoordinates.add(new Coordinate(101, 1));
    shellCoordinates.add(new Coordinate(100, 1, 10.0));
    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));
    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);
    assertGeometryEquals(jtsGeom(expected), polygonGeoJson);
}
Also used : Coordinate(com.vividsolutions.jts.geom.Coordinate) ArrayList(java.util.ArrayList) LinearRing(com.vividsolutions.jts.geom.LinearRing) Polygon(com.vividsolutions.jts.geom.Polygon) XContentBuilder(org.elasticsearch.common.xcontent.XContentBuilder)

Example 3 with LinearRing

use of com.vividsolutions.jts.geom.LinearRing in project hale by halestudio.

the class PolygonHandlerTest method init.

// XXX no test for geometry properties
@Override
public void init() {
    super.init();
    LinearRing shell = geomFactory.createLinearRing(new Coordinate[] { new Coordinate(0.01, 3.2), new Coordinate(3.33, 3.33), new Coordinate(0.01, -3.2), new Coordinate(-3.33, -3.2), new Coordinate(0.01, 3.2) });
    LinearRing[] holes = new LinearRing[2];
    LinearRing hole1 = geomFactory.createLinearRing(new Coordinate[] { new Coordinate(0, 1), new Coordinate(1, 1), new Coordinate(0, -1), new Coordinate(-1, -1), new Coordinate(0, 1) });
    LinearRing hole2 = geomFactory.createLinearRing(new Coordinate[] { new Coordinate(0, 2), new Coordinate(2, 2), new Coordinate(0, -2), new Coordinate(-2, -2), new Coordinate(0, 2) });
    holes[0] = hole1;
    holes[1] = hole2;
    reference = geomFactory.createPolygon(shell, holes);
    checker = combine(noCoordinatePairs(), referenceChecker(reference));
    gridChecker = combine(noCoordinatePairs(), referenceChecker(reference, InterpolationHelper.DEFAULT_MAX_POSITION_ERROR), gridConfig.geometryChecker());
}
Also used : Coordinate(com.vividsolutions.jts.geom.Coordinate) LinearRing(com.vividsolutions.jts.geom.LinearRing)

Example 4 with LinearRing

use of com.vividsolutions.jts.geom.LinearRing in project hale by halestudio.

the class CompositeSurfaceGeometryTest method init.

@Override
public void init() {
    super.init();
    LinearRing shell = geomFactory.createLinearRing(new Coordinate[] { new Coordinate(0.01, 3.2), new Coordinate(3.33, 3.33), new Coordinate(0.01, -3.2), new Coordinate(-3.33, -3.2), new Coordinate(0.01, 3.2) });
    LinearRing[] holes = new LinearRing[2];
    LinearRing hole1 = geomFactory.createLinearRing(new Coordinate[] { new Coordinate(0, 1), new Coordinate(1, 1), new Coordinate(0, -1), new Coordinate(-1, -1), new Coordinate(0, 1) });
    LinearRing hole2 = geomFactory.createLinearRing(new Coordinate[] { new Coordinate(0, 2), new Coordinate(2, 2), new Coordinate(0, -2), new Coordinate(-2, -2), new Coordinate(0, 2) });
    holes[0] = hole1;
    holes[1] = hole2;
    Polygon polygon1 = geomFactory.createPolygon(shell, holes);
    shell = geomFactory.createLinearRing(new Coordinate[] { new Coordinate(6.01, 9.2), new Coordinate(9.33, 9.33), new Coordinate(6.01, -9.2), new Coordinate(-9.33, -9.2), new Coordinate(6.01, 9.2) });
    holes = new LinearRing[2];
    hole1 = geomFactory.createLinearRing(new Coordinate[] { new Coordinate(2, 3), new Coordinate(3, 3), new Coordinate(2, -3), new Coordinate(-3, -3), new Coordinate(2, 3) });
    hole2 = geomFactory.createLinearRing(new Coordinate[] { new Coordinate(2, 4), new Coordinate(4, 4), new Coordinate(2, -4), new Coordinate(-4, -4), new Coordinate(2, 4) });
    holes[0] = hole1;
    holes[1] = hole2;
    Polygon polygon2 = geomFactory.createPolygon(shell, holes);
    Polygon[] polygons = new Polygon[] { polygon1, polygon2 };
    reference = geomFactory.createMultiPolygon(polygons);
    checker = referenceChecker(reference);
    gridChecker = combine(referenceChecker(reference, InterpolationHelper.DEFAULT_MAX_POSITION_ERROR), gridConfig.geometryChecker());
}
Also used : Coordinate(com.vividsolutions.jts.geom.Coordinate) LinearRing(com.vividsolutions.jts.geom.LinearRing) MultiPolygon(com.vividsolutions.jts.geom.MultiPolygon) Polygon(com.vividsolutions.jts.geom.Polygon)

Example 5 with LinearRing

use of com.vividsolutions.jts.geom.LinearRing in project hale by halestudio.

the class OrientableSurfaceGeometryTest method init.

@Override
public void init() {
    super.init();
    LinearRing shell = geomFactory.createLinearRing(new Coordinate[] { new Coordinate(-122.44, 37.80), new Coordinate(-122.45, 37.80), new Coordinate(-122.45, 37.78), new Coordinate(-122.44, 37.78), new Coordinate(-122.44, 37.80) });
    LinearRing[] holes = new LinearRing[1];
    LinearRing hole1 = geomFactory.createLinearRing(new Coordinate[] { new Coordinate(-122.24, 37.60), new Coordinate(-122.25, 37.60), new Coordinate(-122.25, 37.58), new Coordinate(-122.24, 37.58), new Coordinate(-122.24, 37.60) });
    holes[0] = hole1;
    reference = geomFactory.createPolygon(shell, holes);
    checker = referenceChecker(reference);
    gridChecker = combine(referenceChecker(reference, maxPositionalError), gridConfig.geometryChecker());
}
Also used : Coordinate(com.vividsolutions.jts.geom.Coordinate) LinearRing(com.vividsolutions.jts.geom.LinearRing)

Aggregations

LinearRing (com.vividsolutions.jts.geom.LinearRing)101 Polygon (com.vividsolutions.jts.geom.Polygon)72 Coordinate (com.vividsolutions.jts.geom.Coordinate)52 Test (org.junit.Test)42 MultiPolygon (com.vividsolutions.jts.geom.MultiPolygon)28 PackedCoordinateSequence (com.vividsolutions.jts.geom.impl.PackedCoordinateSequence)27 RdfToRyaConversions.convertStatement (org.apache.rya.api.resolver.RdfToRyaConversions.convertStatement)24 Resource (org.openrdf.model.Resource)24 Statement (org.openrdf.model.Statement)24 URI (org.openrdf.model.URI)24 Value (org.openrdf.model.Value)24 ValueFactory (org.openrdf.model.ValueFactory)24 ContextStatementImpl (org.openrdf.model.impl.ContextStatementImpl)24 ValueFactoryImpl (org.openrdf.model.impl.ValueFactoryImpl)24 ArrayList (java.util.ArrayList)22 StatementConstraints (org.apache.rya.indexing.StatementConstraints)12 LineString (com.vividsolutions.jts.geom.LineString)10 Point (com.vividsolutions.jts.geom.Point)10 GeometryFactory (com.vividsolutions.jts.geom.GeometryFactory)9 Geometry (com.vividsolutions.jts.geom.Geometry)8