/// <summary>
        /// Gets the result of the overlay.
        /// </summary>
        public Geometry GetResult()
        {
            var map0 = BuildPointMap(_geom0);
            var map1 = BuildPointMap(_geom1);

            _resultList = new List <Point>();
            switch (_opCode)
            {
            case OverlayNG.INTERSECTION:
                ComputeIntersection(map0, map1, _resultList);
                break;

            case OverlayNG.UNION:
                ComputeUnion(map0, map1, _resultList);
                break;

            case OverlayNG.DIFFERENCE:
                ComputeDifference(map0, map1, _resultList);
                break;

            case OverlayNG.SYMDIFFERENCE:
                ComputeDifference(map0, map1, _resultList);
                ComputeDifference(map1, map0, _resultList);
                break;
            }

            if (_resultList.Count == 0)
            {
                return(OverlayUtility.CreateEmptyResult(0, _geometryFactory));
            }

            return(_geometryFactory.BuildGeometry(_resultList));
        }
        private Point CopyPoint(Point pt)
        {
            // if pm is floating, the point coordinate is not changed
            if (OverlayUtility.IsFloating(_pm))
            {
                return((Point)pt.Copy());
            }

            // pm is fixed.  Round off X&Y ordinates, copy other ordinates unchanged
            var seq  = pt.CoordinateSequence;
            var seq2 = seq.Copy();

            seq2.SetOrdinate(0, Ordinate.X, _pm.MakePrecise(seq.GetX(0)));
            seq2.SetOrdinate(0, Ordinate.Y, _pm.MakePrecise(seq.GetY(0)));
            return(_geometryFactory.CreatePoint(seq2));
        }
예제 #3
0
        private static Coordinate[] ExtractCoordinates(Geometry points, PrecisionModel pm)
        {
            var coords = new CoordinateList();
            int n      = points.NumGeometries;

            for (int i = 0; i < n; i++)
            {
                var point = (Point)points.GetGeometryN(i);
                if (point.IsEmpty)
                {
                    continue;
                }
                var coord = OverlayUtility.Round(point, pm);
                coords.Add(coord, true);
            }
            return(coords.ToCoordinateArray());
        }
예제 #4
0
        private Geometry ComputeUnion(Coordinate[] coords)
        {
            var resultPointList = FindPoints(false, coords);
            List <LineString> resultLineList = null;

            if (_geomNonPointDim == Dimension.Curve)
            {
                resultLineList = ExtractLines(_geomNonPoint);
            }
            List <Polygon> resultPolyList = null;

            if (_geomNonPointDim == Dimension.Surface)
            {
                resultPolyList = ExtractPolygons(_geomNonPoint);
            }

            return(OverlayUtility.CreateResultGeometry(resultPolyList, resultLineList, resultPointList, _geometryFactory));
        }
예제 #5
0
        public OverlayMixedPoints(SpatialFunction opCode, Geometry geom0, Geometry geom1, PrecisionModel pm)
        {
            _opCode          = opCode;
            _pm              = pm;
            _geometryFactory = geom0.Factory;
            _resultDim       = OverlayUtility.ResultDimension(opCode, geom0.Dimension, geom1.Dimension);


            // name the dimensional geometries

            if (geom0.Dimension == 0)
            {
                _geomPoint         = geom0;
                _geomNonPointInput = geom1;
                _isPointRhs        = false;
            }
            else
            {
                _geomPoint         = geom1;
                _geomNonPointInput = geom0;
                _isPointRhs        = true;
            }
        }
예제 #6
0
        /// <summary>
        /// Unions a collection of geometries
        /// using a given precision model.
        /// <para/>
        /// This class is most useful for performing UnaryUnion using
        /// a fixed-precision model.
        /// For unary union using floating precision,
        /// <see cref="OverlayNGRobust.Union(Geometry)"/> should be used.
        /// </summary>
        /// <param name="geom">The geometry to union</param>
        /// <param name="pm">The precision model to use</param>
        /// <returns>The union of the geometries</returns>
        /// <seealso cref="OverlayNGRobust"/>
        public static Geometry Union(Geometry geom, PrecisionModel pm)
        {
            if (geom == null)
            {
                throw new ArgumentNullException(nameof(geom));
            }

            var unionSRFun = new UnionStrategy((g0, g1) =>
                                               OverlayNG.Overlay(g0, g1, SpatialFunction.Union, pm), OverlayUtility.IsFloating(pm));

            var op = new UnaryUnionOp(geom)
            {
                UnionStrategy = unionSRFun
            };

            return(op.Union());
        }