Search in sources :

Example 51 with LinearRing

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

the class MongoGeoIndexerIT method testDcSearchWithPredicate.

@Test
public void testDcSearchWithPredicate() 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 Predicate
        assertEquals(Sets.newHashSet(statement), getSet(f.queryWithin(p1, new StatementConstraints().setPredicates(Collections.singleton(predicate)))));
        // query with wrong predicate
        assertEquals(Sets.newHashSet(), getSet(f.queryWithin(p1, new StatementConstraints().setPredicates(Collections.singleton(vf.createURI("other:pred"))))));
    }
}
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 52 with LinearRing

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

the class MongoGeoIndexerIT method testDcSearch.

@Test
public void testDcSearch() 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[] {});
        assertEquals(Sets.newHashSet(statement), getSet(f.queryWithin(p1, EMPTY_CONSTRAINTS)));
        // test a ring outside the point
        final double[] OUT = { -77, 39, -76, 39, -76, 38, -77, 38, -77, 39 };
        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 53 with LinearRing

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

the class GeoTemporalTestUtils method poly.

public static Polygon poly(final double[] arr) {
    final LinearRing r1 = gf.createLinearRing(new PackedCoordinateSequence.Double(arr, 2));
    final Polygon p1 = gf.createPolygon(r1, new LinearRing[] {});
    return p1;
}
Also used : LinearRing(com.vividsolutions.jts.geom.LinearRing) Polygon(com.vividsolutions.jts.geom.Polygon) PackedCoordinateSequence(com.vividsolutions.jts.geom.impl.PackedCoordinateSequence)

Example 54 with LinearRing

use of com.vividsolutions.jts.geom.LinearRing in project OpenTripPlanner by opentripplanner.

the class Ring method toJtsPolygon.

public Polygon toJtsPolygon() {
    if (jtsPolygon != null) {
        return jtsPolygon;
    }
    GeometryFactory factory = GeometryUtils.getGeometryFactory();
    LinearRing shell;
    try {
        shell = factory.createLinearRing(toCoordinates(geometry));
    } catch (IllegalArgumentException e) {
        throw new RingConstructionException();
    }
    // we need to merge connected holes here, because JTS does not believe in
    // holes that touch at multiple points (and, weirdly, does not have a method
    // to detect this other than this crazy DE-9IM stuff
    List<Polygon> polygonHoles = new ArrayList<Polygon>();
    for (Ring ring : holes) {
        LinearRing linearRing = factory.createLinearRing(toCoordinates(ring.geometry));
        Polygon polygon = factory.createPolygon(linearRing, new LinearRing[0]);
        for (Iterator<Polygon> it = polygonHoles.iterator(); it.hasNext(); ) {
            Polygon otherHole = it.next();
            if (otherHole.relate(polygon, "F***1****")) {
                polygon = (Polygon) polygon.union(otherHole);
                it.remove();
            }
        }
        polygonHoles.add(polygon);
    }
    ArrayList<LinearRing> lrholelist = new ArrayList<LinearRing>(polygonHoles.size());
    for (Polygon hole : polygonHoles) {
        Geometry boundary = hole.getBoundary();
        if (boundary instanceof LinearRing) {
            lrholelist.add((LinearRing) boundary);
        } else {
            // this is a case of a hole inside a hole. OSM technically
            // allows this, but it would be a giant hassle to get right. So:
            LineString line = hole.getExteriorRing();
            LinearRing ring = factory.createLinearRing(line.getCoordinates());
            lrholelist.add(ring);
        }
    }
    LinearRing[] lrholes = lrholelist.toArray(new LinearRing[lrholelist.size()]);
    jtsPolygon = factory.createPolygon(shell, lrholes);
    return jtsPolygon;
}
Also used : GeometryFactory(com.vividsolutions.jts.geom.GeometryFactory) ArrayList(java.util.ArrayList) Geometry(com.vividsolutions.jts.geom.Geometry) LineString(com.vividsolutions.jts.geom.LineString) LinearRing(com.vividsolutions.jts.geom.LinearRing) LinearRing(com.vividsolutions.jts.geom.LinearRing) VLPolygon(org.opentripplanner.visibility.VLPolygon) Polygon(com.vividsolutions.jts.geom.Polygon)

Example 55 with LinearRing

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

the class WKTUtil method getWKTBoundingRectangle.

public static Geometry getWKTBoundingRectangle(String wktString) throws ParseException {
    Geometry boundingGeo = null;
    WKTReader wktReader = new WKTReader(GEOMETRY_FACTORY);
    Geometry geo = wktReader.read(wktString);
    if (geo instanceof Point) {
        Point pt = (Point) geo;
        Coordinate[] coordinates = new Coordinate[5];
        Coordinate ptCoord = pt.getCoordinate();
        Coordinate lowerLeftCoord = ptCoord;
        Coordinate upperLeftCoord = ptCoord;
        Coordinate upperRightCoord = ptCoord;
        Coordinate lowerRightCoord = ptCoord;
        coordinates[0] = lowerLeftCoord;
        coordinates[1] = upperLeftCoord;
        coordinates[2] = upperRightCoord;
        coordinates[3] = lowerRightCoord;
        coordinates[4] = lowerLeftCoord;
        LinearRing shell = GEOMETRY_FACTORY.createLinearRing(coordinates);
        boundingGeo = new Polygon(shell, null, GEOMETRY_FACTORY);
    } else {
        boundingGeo = geo.getEnvelope();
    }
    return boundingGeo;
}
Also used : Geometry(com.vividsolutions.jts.geom.Geometry) Coordinate(com.vividsolutions.jts.geom.Coordinate) Point(com.vividsolutions.jts.geom.Point) WKTReader(com.vividsolutions.jts.io.WKTReader) LinearRing(com.vividsolutions.jts.geom.LinearRing) Polygon(com.vividsolutions.jts.geom.Polygon)

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