Closed xommmax closed 1 month ago
I think that is wrong lib for my purposes
For the record, JTS does not give you the desired result because your input set is not fully noded in your failure case. You can achieve this by unioning your input to the polygonizer:
LineString[] lines = new LineString[4];
lines[0] = (LineString) read("LINESTRING (0 0 , 10 0)");
lines[1] = (LineString) read("LINESTRING (10 0 , 10 10)");
lines[2] = (LineString) read("LINESTRING (10 10 , 0 10)");
lines[3] = (LineString) read("LINESTRING (0 10 , 0 -1)");
Geometry geom;
geom = getGeometryFactory().createMultiLineString(lines);
System.out.println(geom);
geom = geom.union();
System.out.println(geom);
Polygonizer polygonizer = new Polygonizer();
polygonizer.add(geom);
Collection polys = polygonizer.getPolygons();
System.out.println("Polygons formed (" + polys.size() + "):");
System.out.println(polys);```
This gives you:
MULTILINESTRING ((0 0, 10 0), (10 0, 10 10), (10 10, 0 10), (0 10, 0 -1))
MULTILINESTRING ((0 0, 10 0), (10 0, 10 10), (10 10, 0 10), (0 10, 0 0), (0 0, 0 -1))
Polygons formed (1):
[POLYGON ((10 10, 10 0, 0 0, 0 10, 10 10))]
Can someone tell me, why in case I use following multistring ( (0 0, 10 0), (10 0, 10 10), (10 10, 0 10), (0 10, 0 0), )
then
Polygonizer.polygonize
returns[POLYGON ((10 0, 0 0, 0 10, 10 10, 10 0))]
But when I use something like this: ( (0 0, 10 0), (10 0, 10 10), (10 10, 0 10), (0 10, 0 -1), )
it doesnt return polygon.
I use the following code from example project:
It seems like polygonizer doesnt count intersection points