Class UnaryUnionOp


  • public class UnaryUnionOp
    extends java.lang.Object
    Unions a Collection of Geometrys or a single Geometry (which may be a GeoometryCollection) together. By using this special-purpose operation over a collection of geometries it is possible to take advantage of various optimizations to improve performance. Heterogeneous GeometryCollections are fully supported.

    The result obeys the following contract:

    • Unioning a set of Polygons has the effect of merging the areas (i.e. the same effect as iteratively unioning all individual polygons together).
    • Unioning a set of LineStrings has the effect of noding and dissolving the input linework. In this context "fully noded" means that there will be an endpoint or node in the result for every endpoint or line segment crossing in the input. "Dissolved" means that any duplicate (i.e. coincident) line segments or portions of line segments will be reduced to a single line segment in the result. This is consistent with the semantics of the Geometry.union(Geometry) operation. If merged linework is required, the LineMerger class can be used.
    • Unioning a set of Points has the effect of merging all identical points (producing a set with no duplicates).
    UnaryUnion always operates on the individual components of MultiGeometries. So it is possible to use it to "clean" invalid self-intersecting MultiPolygons (although the polygon components must all still be individually valid.)
    • Field Detail

      • polygons

        private java.util.List polygons
      • lines

        private java.util.List lines
      • points

        private java.util.List points
    • Constructor Detail

      • UnaryUnionOp

        public UnaryUnionOp​(java.util.Collection geoms,
                            GeometryFactory geomFact)
        Constructs a unary union operation for a Collection of Geometrys.
        Parameters:
        geoms - a collection of geometries
        geomFact - the geometry factory to use if the collection is empty
      • UnaryUnionOp

        public UnaryUnionOp​(java.util.Collection geoms)
        Constructs a unary union operation for a Collection of Geometrys, using the GeometryFactory of the input geometries.
        Parameters:
        geoms - a collection of geometries
    • Method Detail

      • union

        public static Geometry union​(java.util.Collection geoms)
        Computes the geometric union of a Collection of Geometrys.
        Parameters:
        geoms - a collection of geometries
        Returns:
        the union of the geometries, or null if the input is empty
      • union

        public static Geometry union​(java.util.Collection geoms,
                                     GeometryFactory geomFact)
        Computes the geometric union of a Collection of Geometrys. If no input geometries were provided but a GeometryFactory was provided, an empty GeometryCollection is returned.
        Parameters:
        geoms - a collection of geometries
        geomFact - the geometry factory to use if the collection is empty
        Returns:
        the union of the geometries, or an empty GEOMETRYCOLLECTION
      • union

        public static Geometry union​(Geometry geom)
        Constructs a unary union operation for a Geometry (which may be a GeometryCollection).
        Parameters:
        geom - a geometry to union
        Returns:
        the union of the elements of the geometry or an empty GEOMETRYCOLLECTION
      • extract

        private void extract​(java.util.Collection geoms)
      • extract

        private void extract​(Geometry geom)
      • union

        public Geometry union()
        Gets the union of the input geometries. If no input geometries were provided but a GeometryFactory was provided, an empty GeometryCollection is returned. Otherwise, the return value is null.
        Returns:
        a Geometry containing the union, or an empty GEOMETRYCOLLECTION if no geometries were provided in the input, or null if no GeometryFactory was provided
      • unionWithNull

        private Geometry unionWithNull​(Geometry g0,
                                       Geometry g1)
        Computes the union of two geometries, either of both of which may be null.
        Parameters:
        g0 - a Geometry
        g1 - a Geometry
        Returns:
        the union of the input(s) or null if both inputs are null
      • unionNoOpt

        private Geometry unionNoOpt​(Geometry g0)
        Computes a unary union with no extra optimization, and no short-circuiting. Due to the way the overlay operations are implemented, this is still efficient in the case of linear and puntal geometries. Uses robust version of overlay operation to ensure identical behaviour to the union(Geometry) operation.
        Parameters:
        g0 - a geometry
        Returns:
        the union of the input geometry