Search in sources :

Example 1 with Polygonizer

use of org.locationtech.jts.operation.polygonize.Polygonizer in project Universal-G-Code-Sender by winder.

the class ToolPathUtils method convertAreaToGeometry.

public static Geometry convertAreaToGeometry(final Area area, final GeometryFactory factory) {
    PathIterator iter = area.getPathIterator(null, FLATNESS_PRECISION);
    PrecisionModel precisionModel = factory.getPrecisionModel();
    Polygonizer polygonizer = new Polygonizer(true);
    List<Coordinate[]> coords = ShapeReader.toCoordinates(iter);
    List<Geometry> geometries = new ArrayList<>();
    for (Coordinate[] array : coords) {
        for (Coordinate c : array) precisionModel.makePrecise(c);
        LineString lineString = factory.createLineString(array);
        geometries.add(lineString);
    }
    polygonizer.add(factory.buildGeometry(geometries).union());
    return polygonizer.getGeometry();
}
Also used : Polygonizer(org.locationtech.jts.operation.polygonize.Polygonizer) PathIterator(java.awt.geom.PathIterator) ArrayList(java.util.ArrayList)

Aggregations

PathIterator (java.awt.geom.PathIterator)1 ArrayList (java.util.ArrayList)1 Polygonizer (org.locationtech.jts.operation.polygonize.Polygonizer)1