Search in sources :

Example 36 with Polygon

use of com.vividsolutions.jts.geom.Polygon in project incubator-rya by apache.

the class MongoGeoIndexerIT method testDcSearchWithSubjectAndContext.

@Test
public void testDcSearchWithSubjectAndContext() throws Exception {
    // test a ring around dc
    try (final MongoGeoIndexer f = new MongoGeoIndexer()) {
        f.setConf(conf);
        f.init();
        final ValueFactory vf = new ValueFactoryImpl();
        final Resource subject = vf.createURI("foo:subj");
        final URI predicate = GeoConstants.GEO_AS_WKT;
        final Value object = vf.createLiteral("Point(-77.03524 38.889468)", GeoConstants.XMLSCHEMA_OGC_WKT);
        final Resource context = vf.createURI("foo:context");
        final Statement statement = new ContextStatementImpl(subject, predicate, object, context);
        f.storeStatement(convertStatement(statement));
        f.flush();
        final double[] IN = { -78, 39, -77, 39, -77, 38, -78, 38, -78, 39 };
        final LinearRing r1 = gf.createLinearRing(new PackedCoordinateSequence.Double(IN, 2));
        final Polygon p1 = gf.createPolygon(r1, new LinearRing[] {});
        // query with correct context subject
        assertEquals(Sets.newHashSet(statement), getSet(f.queryWithin(p1, new StatementConstraints().setContext(context).setSubject(subject))));
        // query with wrong context
        assertEquals(Sets.newHashSet(), getSet(f.queryWithin(p1, new StatementConstraints().setContext(vf.createURI("foo:context2")))));
        // query with wrong subject
        assertEquals(Sets.newHashSet(), getSet(f.queryWithin(p1, new StatementConstraints().setSubject(vf.createURI("foo:subj2")))));
    }
}
Also used : ContextStatementImpl(org.openrdf.model.impl.ContextStatementImpl) MongoGeoIndexer(org.apache.rya.indexing.mongodb.geo.MongoGeoIndexer) Statement(org.openrdf.model.Statement) RdfToRyaConversions.convertStatement(org.apache.rya.api.resolver.RdfToRyaConversions.convertStatement) ValueFactoryImpl(org.openrdf.model.impl.ValueFactoryImpl) Resource(org.openrdf.model.Resource) ValueFactory(org.openrdf.model.ValueFactory) URI(org.openrdf.model.URI) StatementConstraints(org.apache.rya.indexing.StatementConstraints) Value(org.openrdf.model.Value) LinearRing(com.vividsolutions.jts.geom.LinearRing) Polygon(com.vividsolutions.jts.geom.Polygon) PackedCoordinateSequence(com.vividsolutions.jts.geom.impl.PackedCoordinateSequence) Test(org.junit.Test)

Example 37 with Polygon

use of com.vividsolutions.jts.geom.Polygon in project incubator-rya by apache.

the class MongoGeoIndexerIT method testPrimeMeridianSearch.

@Test
public void testPrimeMeridianSearch() throws Exception {
    try (final MongoGeoIndexer f = new MongoGeoIndexer()) {
        f.setConf(conf);
        f.init();
        final ValueFactory vf = new ValueFactoryImpl();
        final Resource subject = vf.createURI("foo:subj");
        final URI predicate = GeoConstants.GEO_AS_WKT;
        final Value object = vf.createLiteral("Point(0 0)", GeoConstants.XMLSCHEMA_OGC_WKT);
        final Resource context = vf.createURI("foo:context");
        final Statement statement = new ContextStatementImpl(subject, predicate, object, context);
        f.storeStatement(convertStatement(statement));
        f.flush();
        final double[] ONE = { 1, 1, -1, 1, -1, -1, 1, -1, 1, 1 };
        final double[] TWO = { 2, 2, -2, 2, -2, -2, 2, -2, 2, 2 };
        final double[] THREE = { 3, 3, -3, 3, -3, -3, 3, -3, 3, 3 };
        final LinearRing r1 = gf.createLinearRing(new PackedCoordinateSequence.Double(ONE, 2));
        final LinearRing r2 = gf.createLinearRing(new PackedCoordinateSequence.Double(TWO, 2));
        final LinearRing r3 = gf.createLinearRing(new PackedCoordinateSequence.Double(THREE, 2));
        final Polygon p1 = gf.createPolygon(r1, new LinearRing[] {});
        final Polygon p2 = gf.createPolygon(r2, new LinearRing[] {});
        final Polygon p3 = gf.createPolygon(r3, new LinearRing[] {});
        assertEquals(Sets.newHashSet(statement), getSet(f.queryWithin(p1, EMPTY_CONSTRAINTS)));
        assertEquals(Sets.newHashSet(statement), getSet(f.queryWithin(p2, EMPTY_CONSTRAINTS)));
        assertEquals(Sets.newHashSet(statement), getSet(f.queryWithin(p3, EMPTY_CONSTRAINTS)));
        // Test a ring with a hole in it
        final Polygon p3m2 = gf.createPolygon(r3, new LinearRing[] { r2 });
        assertEquals(Sets.newHashSet(), getSet(f.queryWithin(p3m2, EMPTY_CONSTRAINTS)));
        // test a ring outside the point
        final double[] OUT = { 3, 3, 1, 3, 1, 1, 3, 1, 3, 3 };
        final LinearRing rOut = gf.createLinearRing(new PackedCoordinateSequence.Double(OUT, 2));
        final Polygon pOut = gf.createPolygon(rOut, new LinearRing[] {});
        assertEquals(Sets.newHashSet(), getSet(f.queryWithin(pOut, EMPTY_CONSTRAINTS)));
    }
}
Also used : ContextStatementImpl(org.openrdf.model.impl.ContextStatementImpl) MongoGeoIndexer(org.apache.rya.indexing.mongodb.geo.MongoGeoIndexer) Statement(org.openrdf.model.Statement) RdfToRyaConversions.convertStatement(org.apache.rya.api.resolver.RdfToRyaConversions.convertStatement) ValueFactoryImpl(org.openrdf.model.impl.ValueFactoryImpl) Resource(org.openrdf.model.Resource) ValueFactory(org.openrdf.model.ValueFactory) URI(org.openrdf.model.URI) Value(org.openrdf.model.Value) LinearRing(com.vividsolutions.jts.geom.LinearRing) Polygon(com.vividsolutions.jts.geom.Polygon) PackedCoordinateSequence(com.vividsolutions.jts.geom.impl.PackedCoordinateSequence) Test(org.junit.Test)

Example 38 with Polygon

use of com.vividsolutions.jts.geom.Polygon in project hibernate-orm by hibernate.

the class HANAExpectationsFactory method getTestPolygon.

@Override
public Polygon getTestPolygon() {
    WKTReader reader = new WKTReader();
    try {
        Polygon polygon = (Polygon) reader.read("POLYGON((0 0, 50 0, 90 90, 100 0, 0 0))");
        polygon.setSRID(getTestSrid());
        return polygon;
    } catch (ParseException e) {
        throw new RuntimeException(e);
    }
}
Also used : ParseException(com.vividsolutions.jts.io.ParseException) WKTReader(com.vividsolutions.jts.io.WKTReader) Polygon(com.vividsolutions.jts.geom.Polygon)

Example 39 with Polygon

use of com.vividsolutions.jts.geom.Polygon in project hibernate-orm by hibernate.

the class AbstractExpectationsFactory method getTestPolygon.

/**
 * Return a testsuite-suite polygon (filter, ...)
 *
 * @return a testsuite-suite polygon
 */
public Polygon getTestPolygon() {
    WKTReader reader = new WKTReader();
    try {
        Polygon polygon = (Polygon) reader.read(TEST_POLYGON_WKT);
        polygon.setSRID(getTestSrid());
        return polygon;
    } catch (ParseException e) {
        throw new RuntimeException(e);
    }
}
Also used : ParseException(com.vividsolutions.jts.io.ParseException) WKTReader(com.vividsolutions.jts.io.WKTReader) Polygon(com.vividsolutions.jts.geom.Polygon)

Example 40 with Polygon

use of com.vividsolutions.jts.geom.Polygon in project alliance by codice.

the class DAGConverter method convertShape.

private String convertShape(Any any, boolean swapCoordinates) {
    org.codice.alliance.nsili.common.UCO.Rectangle rectangle = RectangleHelper.extract(any);
    org.codice.alliance.nsili.common.UCO.Coordinate2d upperLeft = rectangle.upper_left;
    org.codice.alliance.nsili.common.UCO.Coordinate2d lowerRight = rectangle.lower_right;
    Geometry geom;
    final WKTWriter wktWriter = new WKTWriter();
    if (upperLeft.x == lowerRight.x && upperLeft.y == lowerRight.y) {
        // Build a Point vs Polygon
        Coordinate pointCoord;
        if (swapCoordinates) {
            pointCoord = new Coordinate(upperLeft.y, upperLeft.x);
        } else {
            pointCoord = new Coordinate(upperLeft.x, upperLeft.y);
        }
        geom = GEOMETRY_FACTORY.createPoint(pointCoord);
    } else {
        Coordinate[] coordinates = new Coordinate[5];
        Coordinate lowerLeftCoord;
        Coordinate upperLeftCoord;
        Coordinate upperRightCoord;
        Coordinate lowerRightCoord;
        if (swapCoordinates) {
            lowerLeftCoord = new Coordinate(upperLeft.y, lowerRight.x);
            upperLeftCoord = new Coordinate(upperLeft.y, upperLeft.x);
            upperRightCoord = new Coordinate(lowerRight.y, upperLeft.x);
            lowerRightCoord = new Coordinate(lowerRight.y, lowerRight.x);
        } else {
            lowerLeftCoord = new Coordinate(upperLeft.x, lowerRight.y);
            upperLeftCoord = new Coordinate(upperLeft.x, upperLeft.y);
            upperRightCoord = new Coordinate(lowerRight.x, upperLeft.y);
            lowerRightCoord = new Coordinate(lowerRight.x, lowerRight.y);
        }
        coordinates[0] = lowerLeftCoord;
        coordinates[1] = upperLeftCoord;
        coordinates[2] = upperRightCoord;
        coordinates[3] = lowerRightCoord;
        coordinates[4] = lowerLeftCoord;
        LinearRing shell = GEOMETRY_FACTORY.createLinearRing(coordinates);
        geom = new Polygon(shell, null, GEOMETRY_FACTORY);
    }
    return wktWriter.write(geom);
}
Also used : Geometry(com.vividsolutions.jts.geom.Geometry) WKTWriter(com.vividsolutions.jts.io.WKTWriter) Coordinate(com.vividsolutions.jts.geom.Coordinate) LinearRing(com.vividsolutions.jts.geom.LinearRing) Polygon(com.vividsolutions.jts.geom.Polygon)

Aggregations

Polygon (com.vividsolutions.jts.geom.Polygon)112 LinearRing (com.vividsolutions.jts.geom.LinearRing)51 MultiPolygon (com.vividsolutions.jts.geom.MultiPolygon)34 Test (org.junit.Test)32 Coordinate (com.vividsolutions.jts.geom.Coordinate)30 Point (com.vividsolutions.jts.geom.Point)27 PackedCoordinateSequence (com.vividsolutions.jts.geom.impl.PackedCoordinateSequence)27 ArrayList (java.util.ArrayList)26 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 Geometry (com.vividsolutions.jts.geom.Geometry)22 LineString (com.vividsolutions.jts.geom.LineString)22 List (java.util.List)20 PersistenceManager (javax.jdo.PersistenceManager)15