GeometryEdit { public static List<Polygon> cutPolygonWithPolygon(Polygon polygon, Polygon extrudePolygon) { Geometry geom = polygon.difference(extrudePolygon); ArrayList<Polygon> polygons = new ArrayList<Polygon>(); for (int i = 0; i < geom.getNumGeometries(); i++) { Polygon subGeom = (Polygon) geom.getGeometryN(i); polygons.add(subGeom); } return polygons; } private  GeometryEdit(); static LineString linearZInterpolation(LineString lineString, double startz, double endz); static LineString linearZInterpolation(LineString lineString); static MultiLineString linearZInterpolation(MultiLineString multiLineString); static Geometry force3DStartEnd(Geometry geom, final double startZ,
            final double endZ); static MultiLineString reverse3D(MultiLineString multiLineString); static LineString reverse3D(LineString lineString); static Geometry reverse3D(Geometry geometry); static Geometry force2D(Geometry geom); static Geometry force3D(Geometry geom, final double value, final boolean addZ); static MultiLineString splitLineWithPoint(LineString line, Point pointToSplit); static MultiLineString splitLineWithPoint(LineString line, Point pointToSplit, double tolerance); static LineString[] splitLineStringWithPoint(LineString line, Point pointToSplit); static LineString[] splitLineStringWithPoint(LineString line, Point pointToSplit, double tolerance); static MultiLineString splitMultiLineStringWithPoint(MultiLineString multiLineString, Point pointToSplit); static MultiLineString splitMultiLineStringWithPoint(MultiLineString multiLineString, Point pointToSplit, double tolerance); static Geometry geometryNoders(Geometry tobeNodes); static List<NodedSegmentString> createNodedSegmentStrings(Geometry geom); static Geometry fromSegmentStrings(Collection<NodedSegmentString> segStrings); static Geometry splitLineStringWithLine(LineString input, LineString cut); static MultiLineString splitMultiLineStringWithLine(MultiLineString input, LineString cut); static GeometryLocation getVertexToSnap(Geometry g, Point p, double tolerance); static GeometryLocation getVertexToSnap(Geometry g, Point p); static Geometry insertVertexInLineString(LineString lineString, Point vertexPoint); static LineString insertVertexInLineString(LineString lineString, Point vertexPoint,
            double tolerance); static LinearRing insertVertexInLinearRing(LineString lineString,
            Point vertexPoint); static LinearRing insertVertexInLinearRing(LineString lineString,
            Point vertexPoint, double tolerance); static Geometry insertVertexInPolygon(Polygon polygon,
            Point vertexPoint); static Polygon insertVertexInPolygon(Polygon polygon,
            Point vertexPoint, double tolerance); static Geometry insertVertexInMultipoint(Geometry g, Point vertexPoint); static Geometry insertVertex(Geometry geom, Point point); static Geometry insertVertex(Geometry geometry, Point vertexPoint, double tolerance); static Collection<Polygon> splitPolygonizer(Polygon polygon, LineString lineString); static Geometry splitPolygonWithLine(Polygon polygon, LineString lineString); static Collection<Polygon> polygonWithLineSplitter(Polygon polygon, LineString lineString); static Geometry splitMultiPolygonWithLine(MultiPolygon multiPolygon, LineString lineString); static Coordinate[] removeVertex(int vertexIndex,
            Geometry g, int minNumVertex); static MultiPoint removeVertex(MultiPoint geometry, int vertexIndex); static LineString removeVertex(LineString geometry, int vertexIndex); static Geometry moveGeometry(Geometry geometry, final double[] displacement); static Geometry moveGeometry(Geometry geometry, Coordinate start, Coordinate end); static List<Polygon> cutPolygonWithPolygon(Polygon polygon, Polygon extrudePolygon); static MultiPolygon cutMultiPolygonWithPolygon(MultiPolygon multiPolygon, Polygon extrudePolygon); static Geometry removeHole(Geometry geometry); static MultiPolygon removeHoleMultiPolygon(MultiPolygon multiPolygon); static Polygon removeHolePolygon(Polygon polygon); static final double PRECISION; }
@Test public void testCutPolygon() throws Exception { Polygon polygon = (Polygon) wKTReader.read("POLYGON (( 0 0 ,10 0, 10 10, 0 10, 0 0 ))"); Polygon cutter = (Polygon) wKTReader.read("POLYGON (( 2 2 ,7 2, 7 7, 2 7, 2 2))"); List<Polygon> result = GeometryEdit.cutPolygonWithPolygon(polygon, cutter); assertEquals(result.get(0).getNumInteriorRing(), 1); assertEquals(result.get(0).getInteriorRingN(0).getEnvelopeInternal(), cutter.getEnvelopeInternal()); cutter = (Polygon) wKTReader.read("POLYGON (( 2 -1.8153735632183903, 7.177873563218391 -1.8153735632183903, 7.177873563218391 7, 2 7, 2 -1.8153735632183903 ))"); result = GeometryEdit.cutPolygonWithPolygon(polygon, cutter); assertEquals(result.get(0), wKTReader.read("POLYGON (( 2 0, 0 0, 0 10, 10 10, 10 0, 7.177873563218391 0, 7.177873563218391 7, 2 7, 2 0 ))")); }