@Test public void testCrossingOtherSide() throws Exception { Geometry g = wkt.read("POLYGON((6 2, 12 2, 12 6, 6 6, 6 2))"); Geometry clipped = clipper.clip(g, false); // assertTrue(clipped.equalsExact(wkt.read("POLYGON((0 2, 10 2, 10 10, 0 10, 0 2))"))); showResult("Donut crossing", g, clipped); }
@Test public void testPolygonCrossingSide() throws Exception { Geometry g = wkt.read("POLYGON((-2 2, 2 2, 2 4, -2 4, -2 2))"); Geometry clipped = clipper.clip(g, false); // assertTrue(clipped.equalsExact(wkt.read("POLYGON((0 2, 2 2, 2 4, 0 4, 0 2))"))); showResult("Crossing side", g, clipped); }
@Override public ROI intersect(ROI roi) { final Geometry geom = getGeometry(roi); // is it a rectangle? if (geom != null && geom.equalsExact(geom.getEnvelope())) { GeometryClipper clipper = new GeometryClipper(geom.getEnvelopeInternal()); Geometry intersect = clipper.clip(getAsGeometry(), true); return new ROIGeometry(intersect); } else { return super.intersect(roi); } }
@Override public ROI intersect(ROI roi) { final Geometry geom = getGeometry(roi); // is it a rectangle? if (geom != null && geom.equalsExact(geom.getEnvelope())) { GeometryClipper clipper = new GeometryClipper(geom.getEnvelopeInternal()); Geometry intersect = clipper.clip(getAsGeometry(), true); return new ROIGeometry(intersect, hints); } else { return super.intersect(roi); } }
@Test public void testFullyOutside() throws Exception { LineString ls = (LineString) wkt.read("LINESTRING(-5 0, -5 15, 15 15)"); LineString clipped = (LineString) clipper.clip(ls, false); assertNull(clipped); showResult("Inside touching borders", ls, clipped); }
@Test public void testTouchPoint() throws Exception { LineString ls = (LineString) wkt.read("LINESTRING(-5 5, 0 5)"); Geometry clipped = clipper.clip(ls, false); assertNull(clipped); showResult("Touch point", ls, clipped); }
@Test public void testMultiTouch() throws Exception { LineString ls = (LineString) wkt.read("LINESTRING(-5 0, 0 1, -5 2, 0 3, -5 4, 0 5)"); Geometry clipped = clipper.clip(ls, false); assertNull(clipped); showResult("Multitouch", ls, clipped); }
@Test public void testTouchLine() throws Exception { LineString ls = (LineString) wkt.read("LINESTRING(0 0, 0 10)"); LineString clipped = (LineString) clipper.clip(ls, false); assertTrue(clipped.equalsExact(ls)); showResult("Touch border", ls, clipped); }
@Test public void testFullyInside() throws Exception { LineString ls = (LineString) wkt.read("LINESTRING(1 1, 2 5, 9 1)"); LineString clipped = (LineString) clipper.clip(ls, false); assertTrue(ls.equalsExact(clipped)); showResult("Fully inside", ls, clipped); }
@Test public void testInsideBorders() throws Exception { LineString ls = (LineString) wkt.read("LINESTRING(0 0, 2 5, 10 0)"); LineString clipped = (LineString) clipper.clip(ls, false); assertTrue(ls.equalsExact(clipped)); showResult("Inside touching borders", ls, clipped); }
@Test public void testTouchAndCross() throws Exception { LineString ls = (LineString) wkt.read("LINESTRING(-5 0, 0 1, -5 2, 5 2, 5 3, -5 3, 0 4)"); Geometry clipped = clipper.clip(ls, false); assertTrue(clipped.equalsExact(wkt.read("LINESTRING(0 2, 5 2, 5 3, 0 3)"))); showResult("Touch and cross", ls, clipped); }
@Test public void testTouchAndParallel() throws Exception { LineString ls = (LineString) wkt.read("LINESTRING(-5 0, 0 1, -5 2, 0 2, 0 3, -5 3, 0 4)"); Geometry clipped = clipper.clip(ls, false); assertTrue(clipped.equalsExact(wkt.read("LINESTRING(0 2, 0 3)"))); showResult("Touch and parallel", ls, clipped); }
@Test public void testPolygonCrossingTwoSides() throws Exception { Geometry g = wkt.read("POLYGON((-2 2, 2 2, 2 12, -2 12, -2 2))"); Geometry clipped = clipper.clip(g, false); assertTrue(clipped.equalsExact(wkt.read("POLYGON((0 2, 2 2, 2 10, 0 10, 0 2))"))); showResult("Crossing two sides", g, clipped); }
@Test public void testPolygonCrossingThreeSides() throws Exception { Geometry g = wkt.read("POLYGON((-2 2, 12 2, 12 12, -2 12, -2 2))"); Geometry clipped = clipper.clip(g, false); assertTrue(clipped.equalsExact(wkt.read("POLYGON((0 2, 10 2, 10 10, 0 10, 0 2))"))); showResult("Crossing three sides", g, clipped); }
@Test public void testCross() throws Exception { LineString ls = (LineString) wkt.read("LINESTRING(-5 -5, 15 15)"); LineString clipped = (LineString) clipper.clip(ls, false); assertTrue(clipped.equalsExact(wkt.read("LINESTRING(0 0, 10 10)"))); showResult("Cross", ls, clipped); }
@Test public void testFullyOutsideCircle() throws Exception { Point p = (Point) wkt.read("POINT(5 5)"); LineString ls = ((Polygon) p.buffer(10)).getExteriorRing(); Geometry clipped = clipper.clip(ls, false); assertNull(clipped); showResult("Circle around", ls, clipped); }
@Test public void testInsidePolygon() throws Exception { Geometry g = wkt.read("POINT(5 5)").buffer(2); Geometry clipped = clipper.clip(g, false); assertTrue(g.equalsExact(clipped)); showResult("Polygon inside", g, clipped); }
@Test public void testOutsidePolygon() throws Exception { Geometry g = wkt.read("POINT(5 5)").buffer(10); Geometry clipped = clipper.clip(g, false); assertTrue(boundsPoly.equalsTopo(clipped)); showResult("Polygon outside", g, clipped); }
@Test public void testDonutCrossingInvalid() throws Exception { Geometry g = wkt.read("POLYGON((6 2, 14 2, 14 8, 6 8, 6 2), (8 4, 12 4, 12 6, 8 6, 8 4))"); Geometry clipped = clipper.clip(g, false); // System.out.println(clipped); assertTrue( clipped.equalsExact( wkt.read( "POLYGON ((10 2, 10 8, 6 8, 6 2, 10 2), (10 4, 10 6, 8 6, 8 4, 10 4))"))); showResult("Donut crossing, invalid geom", g, clipped); }
@Test public void testCrossingCircle() throws Exception { Point p = (Point) wkt.read("POINT(5 5)"); LineString ls = ((Polygon) p.buffer(6)).getExteriorRing(); MultiLineString clipped = (MultiLineString) clipper.clip(ls, false); assertEquals(4, clipped.getNumGeometries()); showResult("Circle around", ls, clipped); }