/// <summary>
        /// Computes the set-theoretic intersection of two
        /// <see cref="Geometry"/>s, using enhanced precision.
        /// </summary>
        /// <param name="geom0">The first <see cref="Geometry"/>.</param>
        /// <param name="geom1">The second <see cref="Geometry"/>.</param>
        /// <returns>
        /// The Geometry representing the set-theoretic intersection of
        /// the input Geometries.
        /// </returns>
        public static Geometry Intersection(Geometry geom0, Geometry geom1)
        {
            Exception originalEx;

            try
            {
                Geometry result = geom0.Intersection(geom1);
                return(result);
            }
            catch (Exception ex)
            {
                originalEx = ex;
            }

            // If we are here, the original op encountered a precision
            // problem (or some other problem).  Retry the operation with
            // enhanced precision to see if it succeeds
            try
            {
                CommonBitsOp cbo      = new CommonBitsOp(true);
                Geometry     resultEP = cbo.Intersection(geom0, geom1);
                // check that result is a valid geometry after the reshift
                // to orginal precision
                if (!resultEP.IsValid)
                {
                    throw originalEx;
                }

                return(resultEP);
            }
            catch
            {
                throw originalEx;
            }
        }
Exemple #2
0
        /// <summary>
        /// Computes the set-theoretic symmetric difference of two <see cref="Geometry"/> instances, using enhanced precision.</summary>
        /// <param name="geom0">the first Geometry
        /// </param>
        /// <param name="geom1">the second Geometry
        /// </param>
        /// <returns> the Geometry representing the set-theoretic symmetric difference of the input Geometries.
        /// </returns>
        public static Geometry GetSymmetricDifference(Geometry geom0, Geometry geom1)
        {
            if (geom0 == null)
            {
                throw new ArgumentNullException("geom0");
            }
            if (geom1 == null)
            {
                throw new ArgumentNullException("geom1");
            }

            Exception originalEx;

            try
            {
                Geometry result = geom0.SymmetricDifference(geom1);
                return(result);
            }
            catch (GeometryException ex)
            {
                ExceptionManager.Publish(ex);

                originalEx = ex;
            }

            /*
             * If we are here, the original op encountered a precision problem
             * (or some other problem).  Retry the operation with
             * enhanced precision to see if it succeeds
             */
            try
            {
                CommonBitsOp cbo      = new CommonBitsOp(true);
                Geometry     resultEP = cbo.SymmetricDifference(geom0, geom1);
                // check that result is a valid geometry after the reshift to orginal precision
                if (!resultEP.IsValid)
                {
                    throw originalEx;
                }
                return(resultEP);
            }
            catch (GeometryException ex2)
            {
                ExceptionManager.Publish(ex2);

                throw originalEx;
            }
        }