/** * Clips a polygon using the Liang-Barsky helper routine. Does not generate, in general, valid * polygons (but still does generate polygons good enough for rendering) * * @param polygon * @return */ private Geometry clipPolygon(Polygon polygon) { final GeometryFactory gf = polygon.getFactory(); LinearRing exterior = (LinearRing) polygon.getExteriorRing(); LinearRing shell = polygonClip(exterior); shell = cleanupRings(shell); if (shell == null) { return null; } List<LinearRing> holes = new ArrayList<LinearRing>(); for (int i = 0; i < polygon.getNumInteriorRing(); i++) { LinearRing hole = (LinearRing) polygon.getInteriorRingN(i); hole = polygonClip(hole); hole = cleanupRings(hole); if (hole != null) { holes.add(hole); } } return gf.createPolygon(shell, (LinearRing[]) holes.toArray(new LinearRing[holes.size()])); }