Exemplo n.º 1
0
        public void Cut([NotNull] IList <CutSubcurve> cutSubcurves,
                        [CanBeNull] ITrackCancel trackCancel = null)
        {
            Assert.ArgumentNotNull(cutSubcurves, nameof(cutSubcurves));
            Assert.ArgumentCondition(_featuresToCut.Count > 0, "No polygon to cut");

            if (cutSubcurves.Count == 0)
            {
                return;
            }

            // simplify the curves to connect several yellow cut subcurves into a proper path
            IGeometry geometryPrototype = _featuresToCut[0].Shape;

            IGeometryCollection simplifiedCurves =
                ReshapeUtils.GetSimplifiedReshapeCurves(
                    cutSubcurves, geometryPrototype.SpatialReference);

            if (simplifiedCurves.GeometryCount == 0)
            {
                return;
            }

            Cut((IPolyline)simplifiedCurves, trackCancel);

            if (TargetFeatures != null && ResultGeometriesByFeature.Count > 0)
            {
                InsertIntersectingVerticesInTargets(TargetFeatures,
                                                    (IGeometry)simplifiedCurves);
            }
        }
Exemplo n.º 2
0
        private static CutSubcurve Replace(CutSubcurve cutSubcurve1,
                                           CutSubcurve cutSubcurve2,
                                           SubcurveNode mergeNode)
        {
            IGeometryCollection mergedCollection =
                ReshapeUtils.GetSimplifiedReshapeCurves(
                    new List <CutSubcurve> {
                cutSubcurve1, cutSubcurve2
            });

            Assert.AreEqual(1, mergedCollection.GeometryCount,
                            "Unexpected number of geometries after merging adjacent subcurves");

            var newPath = (IPath)mergedCollection.get_Geometry(0);

            bool         touchAtFrom;
            SubcurveNode oldNodeAtFrom = GetNodeAt(newPath.FromPoint, cutSubcurve1,
                                                   cutSubcurve2,
                                                   out touchAtFrom);

            bool         touchAtTo;
            SubcurveNode oldNodeAtTo = GetNodeAt(newPath.ToPoint, cutSubcurve1,
                                                 cutSubcurve2,
                                                 out touchAtTo);

            if (oldNodeAtFrom.ConnectedSubcurves.Contains(cutSubcurve1))
            {
                oldNodeAtFrom.ConnectedSubcurves.Remove(cutSubcurve1);
            }

            if (oldNodeAtFrom.ConnectedSubcurves.Contains(cutSubcurve2))
            {
                oldNodeAtFrom.ConnectedSubcurves.Remove(cutSubcurve2);
            }

            if (oldNodeAtTo.ConnectedSubcurves.Contains(cutSubcurve1))
            {
                oldNodeAtTo.ConnectedSubcurves.Remove(cutSubcurve1);
            }

            if (oldNodeAtTo.ConnectedSubcurves.Contains(cutSubcurve2))
            {
                oldNodeAtTo.ConnectedSubcurves.Remove(cutSubcurve2);
            }

            var result = new CutSubcurve(newPath, touchAtFrom, touchAtTo, oldNodeAtFrom,
                                         oldNodeAtTo);

            result.Source = cutSubcurve1.Source;

            oldNodeAtFrom.ConnectedSubcurves.Add(result);
            oldNodeAtTo.ConnectedSubcurves.Add(result);

            // Old target intersection points: Add them if they were not stitch points removed after simplify:
            IPoint connectPoint = GeometryFactory.CreatePoint(mergeNode.X, mergeNode.Y,
                                                              newPath.SpatialReference);

            int partIdx;
            int?connectIndex = GeometryUtils.FindHitVertexIndex(
                newPath, connectPoint, GeometryUtils.GetXyTolerance(newPath),
                out partIdx);

            if (connectIndex != null)
            {
                result.AddExtraPotentialTargetInsertPoint(
                    ((IPointCollection)newPath).get_Point((int)connectIndex));
            }

            return(result);
        }