3

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

enter image description here

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:

enter image description here

How do too JSTS ?

PS2
Sorry for my English.

  • Do you mean this library github.com/bjornharrtell/jsts? – user30184 Nov 8 '16 at 7:59
  • Yes, it library. – t1nk Nov 8 '16 at 9:07
  • @t1nk do you have any feedback upon my answer? – drnextgis Nov 21 '16 at 12:27
  • Where did you get that GUI interface? – Donny V. Aug 3 '18 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. – Donny V. Aug 3 '18 at 15:25
2

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 reader = new jsts.io.WKTReader();
var writer = new jsts.io.WKTWriter();

var a = reader.read('POLYGON ((1 1, 1 9, 9 9, 9 1, 1 1))');
var b = reader.read('LINESTRING (0.5 5, 9.6 5, 9.6 3.9)');
var union = a.getExteriorRing().union(b);

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

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 '16 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? – drnextgis Nov 25 '16 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 '16 at 13:27

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.