# How to split the polygon, operation using of JSTS?

I'm use JSTS 0.17.0 (https://github.com/bjornharrtell/jsts).
How to split the polygon (polygon to multipolygon or two polygons) ?

Input:

• `POLYGON ((1 1, 1 9, 9 9, 9 1, 1 1))`
• `LINESTRING (0.5 5, 9.6 5, 9.6 3.9)`

Result (or):

• `MULTIPOLYGON (((9 5, 9 1, 1 1, 1 5, 9 5)),((9 9, 9 5, 1 5, 1 9, 9 9)))`
• `GEOMETRYCOLLECTION ( POLYGON ((9 5, 9 1, 1 1, 1 5, 9 5)), POLYGON ((9 9, 9 5, 1 5, 1 9, 9 9)) )`

JTS does so:

How do too JSTS ?

PS2
Sorry for my English.

• Do you mean this library github.com/bjornharrtell/jsts? Nov 8, 2016 at 7:59
• Yes, it library.
– t1nk
Nov 8, 2016 at 9:07
• @t1nk do you have any feedback upon my answer? Nov 21, 2016 at 12:27
• Where did you get that GUI interface? Aug 3, 2018 at 13:30
• I figured it out. Its included with the JTS github code. You have to build the project using maven and then run testbuilder.bat. Aug 3, 2018 at 15:25

Something like this:

``````// Output:
// POLYGON((1 1,1 5,9 5,9 1,1 1))
// POLYGON((1 5,1 9,9 9,9 5,1 5))

var writer = new jsts.io.WKTWriter();

var a = reader.read('POLYGON ((1 1, 1 9, 9 9, 9 1, 1 1))');
var union = a.getExteriorRing().union(b);

var polygonizer = new jsts.operation.polygonize.Polygonizer();

var polygons = polygonizer.getPolygons();
for (var i = polygons.iterator(); i.hasNext();) {
var polygon = i.next();
console.log(writer.write(polygon));
}
``````
• As a result, multipolygon is needed, and it is not valid: self-intersections :( For the separation of polygons - suit
– t1nk
Nov 25, 2016 at 7:54
• In my answer I've got two simple valid polygons. What self-intersection do you mean? Or you have to split not only simple polygons as you pointed in your question? Nov 25, 2016 at 10:03
• The result coincides with that obtained in TestBuild, thank you. But I cut multipolygon, and the result will be a multipolygon. The geometry of the cut is perfect - there are no objections, but calculating it fall down because the validity check.
– t1nk
Nov 25, 2016 at 13:27