Esempio n. 1
0
        /// <summary>
        /// Computes a <c>Geometry</c> representing the point-set
        /// which is contained in both input <c>Geometry</c>s .
        /// </summary>
        /// <param name="a">The 1st <c>Geometry</c></param>
        /// <param name="b">The 2nd <c>Geometry</c></param>
        /// <returns>A point-set combining the points of
        /// <c>Geometry</c>'s <c>a</c> and <c>b</c>.
        /// </returns>
        /// <seealso cref="Geometry.Union(Geometry)"/>
        public virtual Geometry Union(Geometry a, Geometry b)
        {
            // handle empty geometry cases
            if (a.IsEmpty || (b == null || b.IsEmpty))
            {
                // both empty - check dimensions
                if (a.IsEmpty && (b == null || b.IsEmpty))
                {
                    return(OverlayOp.CreateEmptyResult(SpatialFunction.Union, a, b, a.Factory));
                }

                // special case: if either input is empty ==> result = other arg
                if (a.IsEmpty)
                {
                    return(b.Copy());
                }
                if (b == null || b.IsEmpty)
                {
                    return(a.Copy());
                }
            }

            // TODO: optimize if envelopes of geometries do not intersect

            CheckNotGeometryCollection(a, b);

            return(Overlay(a, b, SpatialFunction.Union));
        }
Esempio n. 2
0
        /// <summary>
        /// Computes a <c>Geometry</c> representing the closure of the point-set
        /// which is the union of the points in <c>Geometry</c> <c>a</c> which are not
        /// contained in the Geometry  <c>b</c>,
        /// with the points in the <c>b</c> Geometry not contained in the <c>Geometry</c> <c>a</c>.
        /// </summary>
        /// <param name="a">The 1st <c>Geometry</c></param>
        /// <param name="b">The 2nd <c>Geometry</c></param>
        /// <returns>
        /// A Geometry representing the point-set symmetric difference
        /// of <c>Geometry</c>'s <c>a</c> and <c>b</c>.
        /// </returns>
        /// <seealso cref="Geometry.SymmetricDifference(Geometry)"/>
        public virtual Geometry SymmetricDifference(Geometry a, Geometry b)
        {
            // handle empty geometry cases
            if (a.IsEmpty || (b == null || b.IsEmpty))
            {
                // both empty - check dimensions
                if (a.IsEmpty && (b == null || b.IsEmpty))
                {
                    return(OverlayOp.CreateEmptyResult(SpatialFunction.SymDifference, a, b, a.Factory));
                }

                // special case: if either input is empty ==> result = other arg
                if (a.IsEmpty)
                {
                    return(b.Copy());
                }
                if (b == null || b.IsEmpty)
                {
                    return(a.Copy());
                }
            }

            CheckNotGeometryCollection(a, b);

            return(Overlay(a, b, SpatialFunction.SymDifference));
        }
Esempio n. 3
0
        /// <summary>
        /// Computes a <c>Geometry</c> representing the point-set which is
        /// common to both <c>a</c> and <c>b</c> Geometry.
        /// </summary>
        /// <param name="a">The 1st <c>Geometry</c></param>
        /// <param name="b">The 2nd <c>Geometry</c></param>
        /// <returns>A geometry representing the point-set common to the two <c>Geometry</c>s.</returns>
        /// <seealso cref="Geometry.Intersection"/>
        public virtual Geometry Intersection(Geometry a, Geometry b)
        {
            /**
             * TODO: MD - add optimization for P-A case using Point-In-Polygon
             */
            // special case: if one input is empty ==> empty
            if (a.IsEmpty || b.IsEmpty)
            {
                return(OverlayOp.CreateEmptyResult(SpatialFunction.Intersection, a, b, a.Factory));
            }

            // compute for GCs
            // (An inefficient algorithm, but will work)
            // TODO: improve efficiency of computation for GCs
            if (a.OgcGeometryType == OgcGeometryType.GeometryCollection)
            {
                var g2 = b;
                return(GeometryCollectionMapper.Map(
                           (GeometryCollection)a, g => g.Intersection(g2)));
            }

            // No longer needed since GCs are handled by previous code
            //CheckNotGeometryCollection(a, b);

            return(Overlay(a, b, SpatialFunction.Intersection));
        }
Esempio n. 4
0
        /// <summary>
        /// Computes a <c>Geometry</c> representing the closure of the point-set
        /// of the points contained in this <c>Geometry</c> that are not contained in
        /// the <c>other</c> Geometry.
        /// </summary>
        /// <param name="a">The 1st <c>Geometry</c></param>
        /// <param name="b">The 2nd <c>Geometry</c></param>
        /// <returns>
        /// A Geometry representing the point-set difference
        /// of <c>Geometry</c>'s <c>a</c> and <c>b</c>.
        /// </returns>
        /// <seealso cref="Geometry.Difference(Geometry)"/>
        public virtual Geometry Difference(Geometry a, Geometry b)
        {
            // special case: if A.isEmpty ==> empty; if B.isEmpty ==> A
            if (a.IsEmpty)
            {
                return(OverlayOp.CreateEmptyResult(SpatialFunction.Difference, a, b, a.Factory));
            }
            if (b == null || b.IsEmpty)
            {
                return(a.Copy());
            }

            CheckNotGeometryCollection(a, b);

            return(Overlay(a, b, SpatialFunction.Difference));
        }