コード例 #1
0
        /// <summary>
        /// Computes a union operation on
        /// the given geometry, with the supplied precision model.
        /// <para/>
        /// The input must be a valid geometry.
        /// Collections must be homogeneous.
        /// <para/>
        /// To union an overlapping set of polygons in a more performant way use <see cref="UnaryUnionNG"/>.
        /// To union a polygonal coverage or linear network in a more performant way,
        /// use <see cref="CoverageUnion"/>.
        /// </summary>
        /// <param name="geom">The geometry</param>
        /// <param name="pm">The precision model to use</param>
        /// <returns>The result of the union operation</returns>
        /// <seealso cref="OverlayMixedPoints"/>
        internal static Geometry Union(Geometry geom, PrecisionModel pm)
        {
            var ov     = new OverlayNG(geom, null, pm, SpatialFunction.Union);
            var geomOv = ov.GetResult();

            return(geomOv);
        }
コード例 #2
0
        /// <summary>
        /// Reduces the precision of a geometry by rounding and snapping it to the
        /// supplied <see cref="PrecisionModel"/>.<br/>
        /// The input geometry must be polygonal or linear.
        /// <para/>
        /// The output is always a valid geometry.  This implies that input components
        /// may be merged if they are closer than the grid precision.
        /// if merging is not desired, then the individual geometry components
        /// should be processed separately.
        /// <para/>
        /// The output is fully noded (i.e. coincident lines are merged and noded).
        /// This provides an effective way to node / snap-round a collection of <see cref="LineString"/>s.
        /// </summary>
        /// <param name="geom">The geometry to reduce</param>
        /// <param name="pm">The precision model to use</param>
        /// <returns>The precision-reduced geometry</returns>
        public static Geometry ReducePrecision(Geometry geom, PrecisionModel pm)
        {
            if (geom == null)
            {
                throw new ArgumentNullException(nameof(geom));
            }

            var ov = new OverlayNG(geom, null, pm, SpatialFunction.Union);

            /*
             * Ensure reducing a area only produces polygonal result.
             * (I.e. collapse lines are not output)
             */
            if (geom.Dimension == Dimension.Surface)
            {
                ov.AreaResultOnly = true;
            }
            try
            {
                var reduced = ov.GetResult();
                return(reduced);
            }
            catch (TopologyException ex)
            {
                throw new ArgumentException("Reduction failed, possible invalid input", ex);
            }
        }
コード例 #3
0
        /// <summary>
        /// Computes an overlay operation for
        /// the given geometry operands, with the
        /// noding strategy determined by the precision model.
        /// </summary>
        /// <param name="geom0">The first geometry argument</param>
        /// <param name="geom1">The second geometry argument</param>
        /// <param name="opCode">The code for the desired overlay operation</param>
        /// <param name="pm">The precision model to use</param>
        /// <returns>The result of the overlay operation</returns>
        public static Geometry Overlay(Geometry geom0, Geometry geom1,
                                       SpatialFunction opCode, PrecisionModel pm)
        {
            var ov     = new OverlayNG(geom0, geom1, pm, opCode);
            var geomOv = ov.GetResult();

            return(geomOv);
        }
コード例 #4
0
        /// <summary>
        /// Computes a union of a single geometry using a custom noder.
        /// <para/>
        /// The primary use of this is to support coverage union.
        /// Because of this the overlay is performed using strict mode.
        /// </summary>
        /// <param name="geom">The geometry to union</param>
        /// <param name="pm">The precision model to use (maybe be <c>null</c>)</param>
        /// <param name="noder">The noder to use</param>
        /// <returns>the result geometry</returns>
        /// <seealso cref="CoverageUnion"/>
        internal static Geometry Union(Geometry geom, PrecisionModel pm, INoder noder)
        {
            var ov = new OverlayNG(geom, null, pm, SpatialFunction.Union);

            ov.Noder      = noder;
            ov.StrictMode = true;
            var geomOv = ov.GetResult();

            return(geomOv);
        }
コード例 #5
0
        /// <summary>
        /// Computes an overlay operation on the given geometry operands,
        /// using a supplied <see cref="INoder"/>.
        /// </summary>
        /// <param name="geom0">The first geometry argument</param>
        /// <param name="geom1">The second geometry argument</param>
        /// <param name="opCode">The code for the desired overlay operation</param>
        /// <param name="noder">The noder to use</param>
        /// <returns>The result of the overlay operation</returns>
        public static Geometry Overlay(Geometry geom0, Geometry geom1,
                                       SpatialFunction opCode, INoder noder)
        {
            var ov = new OverlayNG(geom0, geom1, null, opCode);

            ov.Noder = noder;
            var geomOv = ov.GetResult();

            return(geomOv);
        }
コード例 #6
0
        /// <summary>
        /// Self-snaps a geometry by running a union operation with it as the only input.
        /// This helps to remove narrow spike/gore artifacts to simplify the geometry,
        /// which improves robustness.
        /// Collapsed artifacts are removed from the result to allow using
        /// it in further overlay operations.
        /// </summary>
        /// <param name="geom">Geometry to self-snap</param>
        /// <param name="snapTol">Snap tolerance</param>
        /// <returns>The snapped geometry (homogenous)</returns>
        private static Geometry SnapSelf(Geometry geom, double snapTol)
        {
            var ov        = new OverlayNG(geom, null);
            var snapNoder = new SnappingNoder(snapTol);

            ov.Noder = snapNoder;

            /*
             * Ensure the result is not mixed-dimension,
             * since it will be used in further overlay computation.
             * It may however be lower dimension, if it collapses completely due to snapping.
             */
            ov.StrictMode = true;
            return(ov.GetResult());
        }
コード例 #7
0
        /// <summary>
        /// Computes an overlay operation on
        /// the given geometry operands,
        /// using the precision model of the geometry.
        /// and an appropriate noder.
        /// <para/>
        /// The noder is chosen according to the precision model specified.
        /// <list type="bullet">
        /// <item><description>For <see cref="PrecisionModels.Fixed"/>
        /// a snap-rounding noder is used, and the computation is robust.</description></item>
        /// <item><description>For <see cref="PrecisionModels.Floating"/>
        /// a non-snapping noder is used,
        /// and this computation may not be robust.
        /// If errors occur a <see cref="TopologyException"/> is thrown.</description></item>
        /// </list>
        /// </summary>
        /// <param name="geom0">The first geometry argument</param>
        /// <param name="geom1">The second geometry argument</param>
        /// <param name="opCode">The code for the desired overlay operation</param>
        /// <returns>The result of the overlay operation</returns>
        public static Geometry Overlay(Geometry geom0, Geometry geom1, SpatialFunction opCode)
        {
            var ov = new OverlayNG(geom0, geom1, opCode);

            return(ov.GetResult());
        }