/// <summary> /// Computes the set-theoretic intersection of two <c>Geometry</c>s, 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 intersection of the input Geometries.</returns> public static IGeometry Intersection(IGeometry geom0, IGeometry geom1) { ApplicationException originalEx = null; try { IGeometry result = geom0.Intersection(geom1); return result; } catch (ApplicationException 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); IGeometry resultEP = cbo.Intersection(geom0, geom1); // check that result is a valid point after the reshift to orginal precision if (!resultEP.IsValid) throw originalEx; return resultEP; } catch(ApplicationException) { throw originalEx; } }
public void TestPackedCoordinateSequence() { var pcsFactory = new GeometryFactory(PackedCoordinateSequenceFactory.DoubleFactory); var geom0 = Read(pcsFactory, "POLYGON ((210 210, 210 220, 220 220, 220 210, 210 210))"); var geom1 = Read("POLYGON ((225 225, 225 215, 215 215, 215 225, 225 225))"); var cbo = new CommonBitsOp(true); var result = cbo.Intersection(geom0, geom1); var expected = geom0.Intersection(geom1); //Geometry expected = read("POLYGON ((220 215, 215 215, 215 220, 220 220, 220 215))"); CheckEqual(expected, result); }