Exemple #1
0
        private IPolyline GetNonLinearSubpart(int startSegmentIndex, double startFraction,
                                              int endSegmentIndex, double endFraction)
        {
            var subpart = new PolylineClass();
            IPointCollection4  points = subpart;
            ISegmentCollection segs   = subpart;

            subpart.SpatialReference = SpatialReference;

            bool hasNonLinearParts = false;

            object         missing = Type.Missing;
            SegmentProxy   segProxy;
            AoSegmentProxy aoSegProxy;

            #region startSegment

            var currentWksPoints = new List <WKSPointZ>();
            if (_nonLinearSegments.TryGetValue(startSegmentIndex, out aoSegProxy))
            {
                hasNonLinearParts = true;
                ISegment seg = aoSegProxy.InnerSegment;
                ICurve   part;

                double end = 1;
                if (endSegmentIndex == startSegmentIndex)
                {
                    end = endFraction;
                }

                seg.GetSubcurve(startFraction, end, true, out part);

                segs.AddSegment((ISegment)part, ref missing, ref missing);
            }
            else
            {
                segProxy = GetSegment(startSegmentIndex);
                IPnt p = segProxy.GetPointAt(startFraction, as3D: true);
                currentWksPoints.Add(QaGeometryUtils.GetWksPoint(p));
            }

            #endregion

            #region segments

            for (int i = startSegmentIndex + 1; i < endSegmentIndex; i++)
            {
                if (_nonLinearSegments.TryGetValue(i, out aoSegProxy))
                {
                    hasNonLinearParts = true;

                    if (currentWksPoints.Count > 0)
                    {
                        currentWksPoints.Add(_points[i]);
                        WKSPointZ[] add = currentWksPoints.ToArray();
                        GeometryUtils.AddWKSPointZs(points, add);
                        currentWksPoints.Clear();
                    }

                    ISegment seg = GeometryFactory.Clone(aoSegProxy.InnerSegment);
                    segs.AddSegment(seg, ref missing, ref missing);
                }
                else
                {
                    currentWksPoints.Add(_points[i]);
                }
            }

            #endregion

            #region endsegment

            if (startSegmentIndex == endSegmentIndex)
            {
                if (currentWksPoints.Count > 0)
                {
                    segProxy = GetSegment(endSegmentIndex);
                    IPnt p = segProxy.GetPointAt(endFraction, as3D: true);
                    currentWksPoints.Add(QaGeometryUtils.GetWksPoint(p));
                    WKSPointZ[] add = currentWksPoints.ToArray();
                    GeometryUtils.AddWKSPointZs(points, add);
                }
            }
            else
            {
                if (_nonLinearSegments.TryGetValue(endSegmentIndex, out aoSegProxy))
                {
                    hasNonLinearParts = false;
                    if (currentWksPoints.Count > 0)
                    {
                        currentWksPoints.Add(_points[endSegmentIndex]);
                        WKSPointZ[] add = currentWksPoints.ToArray();
                        GeometryUtils.AddWKSPointZs(points, add);
                        currentWksPoints.Clear();
                    }

                    ISegment seg = aoSegProxy.InnerSegment;
                    ICurve   part;
                    seg.GetSubcurve(0, endFraction, true, out part);
                    segs.AddSegment((ISegment)part, ref missing, ref missing);
                }
                else
                {
                    currentWksPoints.Add(_points[endSegmentIndex]);
                    segProxy = GetSegment(endSegmentIndex);

                    IPnt p = segProxy.GetPointAt(endFraction, as3D: true);
                    currentWksPoints.Add(QaGeometryUtils.GetWksPoint(p));

                    WKSPointZ[] add = currentWksPoints.ToArray();
                    GeometryUtils.AddWKSPointZs(points, add);
                }
            }

            #endregion

            if (hasNonLinearParts)
            {
                var topoOp = (ITopologicalOperator2)subpart;
                topoOp.IsKnownSimple_2 = false;
                topoOp.Simplify();
            }

            return(subpart);
        }