protected internal Worker(CascadedPolygonUnion tool, IList <Geometry> geoms, int start, int end)
 {
     _tool  = tool;
     _geoms = geoms;
     _start = start;
     _end   = end;
 }
Ejemplo n.º 2
0
        /// <summary>
        /// Gets the union of the input geometries.
        /// If no input geometries were provided but a <see cref="IGeometryFactory"/> was provided,
        /// an empty <see cref="IGeometryCollection"/> is returned.
        /// <para/>Otherwise, the return value is <c>null</c>
        /// </summary>
        /// <returns>
        /// A Geometry containing the union
        /// or an empty <see cref="IGeometryCollection"/> if no geometries were provided in the input,
        /// or <c>null</c> if not GeometryFactory was provided
        /// </returns>
        public IGeometry Union()
        {
            if (_geomFact == null)
            {
                return(null);
            }

            /**
             * For points and lines, only a single union operation is
             * required, since the OGC model allows self-intersecting
             * MultiPoint and MultiLineStrings.
             * This is not the case for polygons, so Cascaded Union is required.
             */
            IGeometry unionPoints = null;

            if (_points.Count > 0)
            {
                var ptGeom = _geomFact.BuildGeometry(_points);
                unionPoints = UnionNoOpt(ptGeom);
            }

            IGeometry unionLines = null;

            if (_lines.Count > 0)
            {
                var lineGeom = _geomFact.BuildGeometry(_lines);
                unionLines = UnionNoOpt(lineGeom);
            }

            IGeometry unionPolygons = null;

            if (_polygons.Count > 0)
            {
                unionPolygons = CascadedPolygonUnion.Union(_polygons);
            }

            /*
             * Performing two unions is somewhat inefficient,
             * but is mitigated by unioning lines and points first
             */
            var       unionLA = UnionWithNull(unionLines, unionPolygons);
            IGeometry union;

            if (unionPoints == null)
            {
                union = unionLA;
            }
            else if (unionLA == null)
            {
                union = unionPoints;
            }
            else
            {
                union = PointGeometryUnion.Union((IPuntal)unionPoints, unionLA);
            }

            if (union == null)
            {
                return(_geomFact.CreateGeometryCollection());
            }

            return(union);
        }
 /// <summary>
 /// Computes the union of
 /// a collection of <see cref="IGeometry"/>s.
 /// </summary>
 /// <param name="polys">A collection of <see cref="IPolygonal"/> <see cref="IGeometry"/>s.</param>
 /// <returns></returns>
 public static IGeometry Union(ICollection<IGeometry> polys)
 {
     var op = new CascadedPolygonUnion(polys);
     return op.Union();
 }
 protected internal Worker(CascadedPolygonUnion tool, IList<IGeometry> geoms, int start, int end)
 {
     _tool = tool;
     _geoms = geoms;
     _start = start;
     _end = end;
 }
        /// <summary>
        /// Computes the union of
        /// a collection of <see cref="Geometry"/>s.
        /// </summary>
        /// <param name="polys">A collection of <see cref="IPolygonal"/> <see cref="Geometry"/>s.</param>
        /// <returns>The union of the <paramref name="polys"/></returns>
        public static Geometry Union(ICollection <Geometry> polys)
        {
            var op = new CascadedPolygonUnion(polys);

            return(op.Union());
        }
        /// <summary>
        /// Computes the union of
        /// a collection of <see cref="Geometry"/>s.
        /// </summary>
        /// <param name="polys">A collection of <see cref="IPolygonal"/> <see cref="Geometry"/>s.</param>
        /// <param name="unionStrategy">A strategy to perform the unioning.</param>
        /// <returns>The union of the <paramref name="polys"/></returns>
        public static Geometry Union(ICollection <Geometry> polys, UnionStrategy unionStrategy)
        {
            var op = new CascadedPolygonUnion(polys, unionStrategy);

            return(op.Union());
        }
Ejemplo n.º 7
0
        /// <summary>
        /// Gets the union of the input geometries.
        /// <para/>
        /// The result of empty input is determined as follows:
        /// <list type="Bullet">
        /// <item><description>If the input is empty and a dimension can be
        /// determined (i.e. an empty geometry is present),
        /// an empty atomic geometry of that dimension is returned.</description></item>
        /// <item><description>If no input geometries were provided but a <see cref="GeometryFactory"/> was provided,
        /// an empty <see cref="GeometryCollection"/> is returned.</description></item>
        /// <item><description>Otherwise, the return value is <c>null</c>.</description></item>
        /// </list>
        /// </summary>
        /// <returns>
        /// A Geometry containing the union,
        /// or an empty atomic geometry, or an empty <c>GEOMETRYCOLLECTION</c>,
        /// or<c>null</c> if no GeometryFactory was provided
        /// </returns>
        public Geometry Union()
        {
            if (_geomFact == null)
            {
                _geomFact = _extracter.Factory;
            }

            // Case 3
            if (_geomFact == null)
            {
                return(null);
            }

            // Case 1 & 2
            if (_extracter.IsEmpty)
            {
                return(_geomFact.CreateEmpty(_extracter.Dimension));
            }

            var points   = _extracter.GetExtract(Dimension.Point);
            var lines    = _extracter.GetExtract(Dimension.Curve);
            var polygons = _extracter.GetExtract(Dimension.Surface);

            /**
             * For points and lines, only a single union operation is
             * required, since the OGC model allows self-intersecting
             * MultiPoint and MultiLineStrings.
             * This is not the case for polygons, so Cascaded Union is required.
             */
            Geometry unionPoints = null;

            if (points.Count > 0)
            {
                var ptGeom = _geomFact.BuildGeometry(points);
                unionPoints = UnionNoOpt(ptGeom);
            }

            Geometry unionLines = null;

            if (lines.Count > 0)
            {
                var lineGeom = _geomFact.BuildGeometry(lines);
                unionLines = UnionNoOpt(lineGeom);
            }

            Geometry unionPolygons = null;

            if (polygons.Count > 0)
            {
                unionPolygons = CascadedPolygonUnion.Union(polygons);
            }

            /*
             * Performing two unions is somewhat inefficient,
             * but is mitigated by unioning lines and points first
             */
            var      unionLA = UnionWithNull(unionLines, unionPolygons);
            Geometry union;

            if (unionPoints == null)
            {
                union = unionLA;
            }
            else if (unionLA == null)
            {
                union = unionPoints;
            }
            else
            {
                union = PointGeometryUnion.Union((IPuntal)unionPoints, unionLA);
            }

            if (union == null)
            {
                return(_geomFact.CreateGeometryCollection());
            }

            return(union);
        }