Search in sources :

Example 46 with LinearRing

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

the class GeoWaveIndexerTest method testDcSearchWithSubject.

@Test
public void testDcSearchWithSubject() throws Exception {
    // test a ring around dc
    try (final GeoWaveGeoIndexer f = new GeoWaveGeoIndexer()) {
        f.setConf(conf);
        f.purge(conf);
        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 subject
        Assert.assertEquals(Sets.newHashSet(statement), getSet(f.queryWithin(p1, new StatementConstraints().setSubject(subject))));
        // query with wrong subject
        Assert.assertEquals(Sets.newHashSet(), getSet(f.queryWithin(p1, new StatementConstraints().setSubject(vf.createURI("foo:subj2")))));
    }
}
Also used : ContextStatementImpl(org.openrdf.model.impl.ContextStatementImpl) 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 47 with LinearRing

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

the class GeoWaveIndexerTest method testPrimeMeridianSearch.

@Test
public void testPrimeMeridianSearch() throws Exception {
    try (final GeoWaveGeoIndexer f = new GeoWaveGeoIndexer()) {
        f.setConf(conf);
        f.purge(conf);
        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[] {});
        Assert.assertEquals(Sets.newHashSet(statement), getSet(f.queryWithin(p1, EMPTY_CONSTRAINTS)));
        Assert.assertEquals(Sets.newHashSet(statement), getSet(f.queryWithin(p2, EMPTY_CONSTRAINTS)));
        Assert.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 });
        Assert.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[] {});
        Assert.assertEquals(Sets.newHashSet(), getSet(f.queryWithin(pOut, EMPTY_CONSTRAINTS)));
    }
}
Also used : ContextStatementImpl(org.openrdf.model.impl.ContextStatementImpl) 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 48 with LinearRing

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

the class GeoWaveIndexerTest method testDcSearchWithContext.

@Test
public void testDcSearchWithContext() throws Exception {
    // test a ring around dc
    try (final GeoWaveGeoIndexer f = new GeoWaveGeoIndexer()) {
        f.setConf(conf);
        f.purge(conf);
        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
        Assert.assertEquals(Sets.newHashSet(statement), getSet(f.queryWithin(p1, new StatementConstraints().setContext(context))));
        // query with wrong context
        Assert.assertEquals(Sets.newHashSet(), getSet(f.queryWithin(p1, new StatementConstraints().setContext(vf.createURI("foo:context2")))));
    }
}
Also used : ContextStatementImpl(org.openrdf.model.impl.ContextStatementImpl) 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 49 with LinearRing

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

the class EventDocumentConverter method fromDocument.

@Override
public Event fromDocument(final Document document) throws DocumentConverterException {
    requireNonNull(document);
    final boolean isInstant;
    // Preconditions.
    if (!document.containsKey(SUBJECT)) {
        throw new DocumentConverterException("Could not convert document '" + document + "' because its '" + SUBJECT + "' field is missing.");
    }
    if (document.containsKey(INSTANT)) {
        isInstant = true;
    } else {
        isInstant = false;
    }
    final String subject = document.getString(SUBJECT);
    final Event.Builder builder = new Event.Builder().setSubject(new RyaURI(subject));
    if (document.containsKey(GEO_KEY)) {
        final Document geoObj = (Document) document.get(GEO_KEY);
        final GeometryFactory geoFact = new GeometryFactory();
        final String typeString = (String) geoObj.get("type");
        final CoordinateList coords = new CoordinateList();
        final Geometry geo;
        if (typeString.equals("Point")) {
            final List<Double> point = (List<Double>) geoObj.get("coordinates");
            final Coordinate coord = new Coordinate(point.get(0), point.get(1));
            geo = geoFact.createPoint(coord);
        } else if (typeString.equals("LineString")) {
            final List<List<Double>> pointsList = (List<List<Double>>) geoObj.get("coordinates");
            for (final List<Double> point : pointsList) {
                coords.add(new Coordinate(point.get(0), point.get(1)));
            }
            geo = geoFact.createLineString(coords.toCoordinateArray());
        } else {
            final List<List<List<Double>>> pointsList = (List<List<List<Double>>>) geoObj.get("coordinates");
            if (pointsList.size() == 1) {
                final List<List<Double>> poly = pointsList.get(0);
                for (final List<Double> point : poly) {
                    coords.add(new Coordinate(point.get(0), point.get(1)));
                }
                geo = geoFact.createPolygon(coords.toCoordinateArray());
            } else {
                final List<List<Double>> first = pointsList.get(0);
                final CoordinateList shellCoords = new CoordinateList();
                for (final List<Double> point : pointsList.get(0)) {
                    shellCoords.add(new Coordinate(point.get(0), point.get(1)));
                }
                final LinearRing shell = geoFact.createLinearRing(shellCoords.toCoordinateArray());
                final List<List<List<Double>>> holesPoints = pointsList.subList(1, pointsList.size() - 1);
                final LinearRing[] holes = new LinearRing[holesPoints.size()];
                for (int ii = 0; ii < holes.length; ii++) {
                    final List<List<Double>> holePoints = holesPoints.get(ii);
                    final CoordinateList shells = new CoordinateList();
                    for (final List<Double> point : pointsList.get(0)) {
                        shells.add(new Coordinate(point.get(0), point.get(1)));
                    }
                    holes[ii] = geoFact.createLinearRing(shells.toCoordinateArray());
                }
                geo = geoFact.createPolygon(shell, holes);
            }
        }
        builder.setGeometry(geo);
    }
    if (isInstant) {
        // we already know the key exists
        final Date date = (Date) document.get(INSTANT);
        final DateTime dt = new DateTime(date.getTime());
        final TemporalInstant instant = new TemporalInstantRfc3339(dt);
        builder.setTemporalInstant(instant);
    } else if (document.containsKey(INTERVAL_START)) {
        Date date = (Date) document.get(INTERVAL_START);
        DateTime dt = new DateTime(date.getTime());
        final TemporalInstant begining = new TemporalInstantRfc3339(dt);
        date = (Date) document.get(INTERVAL_END);
        dt = new DateTime(date.getTime());
        final TemporalInstant end = new TemporalInstantRfc3339(dt);
        final TemporalInterval interval = new TemporalInterval(begining, end);
        builder.setTemporalInterval(interval);
    }
    return builder.build();
}
Also used : GeometryFactory(com.vividsolutions.jts.geom.GeometryFactory) CoordinateList(com.vividsolutions.jts.geom.CoordinateList) TemporalInstantRfc3339(org.apache.rya.indexing.TemporalInstantRfc3339) Document(org.bson.Document) TemporalInstant(org.apache.rya.indexing.TemporalInstant) Date(java.util.Date) DateTime(org.joda.time.DateTime) Geometry(com.vividsolutions.jts.geom.Geometry) RyaURI(org.apache.rya.api.domain.RyaURI) Coordinate(com.vividsolutions.jts.geom.Coordinate) Event(org.apache.rya.indexing.geotemporal.model.Event) CoordinateList(com.vividsolutions.jts.geom.CoordinateList) List(java.util.List) LinearRing(com.vividsolutions.jts.geom.LinearRing) TemporalInterval(org.apache.rya.indexing.TemporalInterval)

Example 50 with LinearRing

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

the class MongoGeoIndexerIT method testDcSearchWithSubject.

@Test
public void testDcSearchWithSubject() 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 subject
        assertEquals(Sets.newHashSet(statement), getSet(f.queryWithin(p1, new StatementConstraints().setSubject(subject))));
        // 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)

Aggregations

LinearRing (com.vividsolutions.jts.geom.LinearRing)60 Polygon (com.vividsolutions.jts.geom.Polygon)48 PackedCoordinateSequence (com.vividsolutions.jts.geom.impl.PackedCoordinateSequence)27 RdfToRyaConversions.convertStatement (org.apache.rya.api.resolver.RdfToRyaConversions.convertStatement)24 Test (org.junit.Test)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 Coordinate (com.vividsolutions.jts.geom.Coordinate)18 ArrayList (java.util.ArrayList)18 StatementConstraints (org.apache.rya.indexing.StatementConstraints)12 Point (com.vividsolutions.jts.geom.Point)8 MongoGeoIndexer (org.apache.rya.indexing.mongodb.geo.MongoGeoIndexer)8 Geometry (com.vividsolutions.jts.geom.Geometry)7 MultiPolygon (com.vividsolutions.jts.geom.MultiPolygon)7 GeometryFactory (com.vividsolutions.jts.geom.GeometryFactory)5