GeometryEdit { public static Geometry splitPolygonWithLine(Polygon polygon, LineString lineString) { Collection<Polygon> pols = polygonWithLineSplitter(polygon, lineString); if (pols != null) { return FACTORY.buildGeometry(pols); } return null; } 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 testSplitPolygon() throws Exception { Polygon polygon = (Polygon) wKTReader.read("POLYGON (( 0 0, 10 0, 10 10 , 0 10, 0 0))"); LineString line = (LineString) wKTReader.read("LINESTRING (5 0, 5 10)"); Geometry pols = GeometryEdit.splitPolygonWithLine(polygon, line); assertEquals(pols.getNumGeometries(), 2); Polygon pol1 = (Polygon) wKTReader.read("POLYGON (( 0 0, 5 0, 5 10 , 0 10, 0 0))"); Polygon pol2 = (Polygon) wKTReader.read("POLYGON ((5 0, 10 0 , 10 10, 5 10, 5 0))"); for (int i = 0; i < pols.getNumGeometries(); i++) { Geometry pol = pols.getGeometryN(i); if (!pol.getEnvelopeInternal().equals(pol1.getEnvelopeInternal()) && !pol.getEnvelopeInternal().equals(pol2.getEnvelopeInternal())) { fail(); } } line = (LineString) wKTReader.read("LINESTRING (5 1, 5 8)"); pols = GeometryEdit.splitPolygonWithLine(polygon, line); assertNull(pols); line = (LineString) wKTReader.read("LINESTRING (5 1, 5 12)"); pols = GeometryEdit.splitPolygonWithLine(polygon, line); assertNull(pols); polygon = (Polygon) wKTReader.read("POLYGON (( 0 0, 10 0, 10 10 , 0 10, 0 0), (2 2, 7 2, 7 7, 2 7, 2 2))"); line = (LineString) wKTReader.read("LINESTRING (5 0, 5 10)"); pols = GeometryEdit.splitPolygonWithLine(polygon, line); pol1 = (Polygon) wKTReader.read("POLYGON (( 0 0, 5 0, 5 2 ,2 2, 2 7, 5 7, 5 10, 0 10, 0 0))"); pol2 = (Polygon) wKTReader.read("POLYGON ((5 0, 5 2, 7 2, 7 7 , 5 7, 5 10, 10 10, 10 0, 5 0))"); for (int i = 0; i < pols.getNumGeometries(); i++) { Geometry pol = pols.getGeometryN(i); if (!pol.getEnvelopeInternal().equals(pol1.getEnvelopeInternal()) && !pol.getEnvelopeInternal().equals(pol2.getEnvelopeInternal())) { fail(); } } polygon = (Polygon) wKTReader.read("POLYGON (( 0 0 1, 10 0 5, 10 10 8 , 0 10 12, 0 0 12))"); line = (LineString) wKTReader.read("LINESTRING (5 0, 5 10)"); pols = GeometryEdit.splitPolygonWithLine(polygon, line); for (int i = 0; i < pols.getNumGeometries(); i++) { Geometry pol = pols.getGeometryN(i); assertTrue(GeometryTypeUtil.is25Geometry(pol)); } }