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"))))));
}
}
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)));
}
}
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;
}
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;
}
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;
}
Aggregations