Class GeometryClipper


  • public class GeometryClipper
    extends Object
    A stateful geometry clipper, can clip linestring on a specified rectangle. Trivial benchmarks report a speedup factor between 20 and 60 compared to JTS generic intersection algorithm. The class is not thread safe.
    Author:
    Andrea Aime - OpenGeo
    • Constructor Detail

      • GeometryClipper

        public GeometryClipper​(Envelope bounds)
    • Method Detail

      • getBounds

        public Envelope getBounds()
      • clipSafe

        public Geometry clipSafe​(Geometry g,
                                 boolean ensureValid,
                                 double scale)
        This will try to handle failures when clipping - i.e. because of invalid input geometries (often caused by simplification).

        This attempts to do a normal clip(). If it fails, it will try to do more to ensure the clip works properly.

        1. if its a polygon/multipolygon it will try to make the polygon valid and re-try the clip
        2. it will attempt to put the geometry on a precision grid (this will move the points around) and re-try the clip
        3. will attempt to clip with ensureValid = false (ie geotools simple clipping)
        See clip
        Parameters:
        scale - Scale used to snap geometry to precision model, 0 to disable
        Returns:
        a clipped geometry, which may be empty, or null
      • clip

        public Geometry clip​(Geometry g,
                             boolean ensureValid)
        Clips the geometry on the specified bounds.
        Parameters:
        g - The geometry to be clipped
        ensureValid - If false there is no guarantee the polygons returned will be valid according to JTS rules (but should still be good enough to be used for pure rendering)