/// <summary> /// Computes the set-theoretic union 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 <see cref="Geometry"/> representing the set-theoretic union /// of the input Geometries. /// </returns> public static Geometry Union(Geometry geom0, Geometry geom1) { Exception originalEx; try { Geometry result = geom0.Union(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.Union(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; } }
/// <summary> /// Computes the set-theoretic union 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 union of the input Geometries. /// </returns> public static Geometry GetUnion(Geometry geom0, Geometry geom1) { if (geom0 == null) { throw new ArgumentNullException("geom0"); } if (geom1 == null) { throw new ArgumentNullException("geom1"); } Exception originalEx; try { Geometry result = geom0.Union(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.Union(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; } }