コード例 #1
0
        }//获取夹角的辅助

        private double AngleToPoint(IGeometry pGeometry)
        {
            double             pAngle       = 0;
            ISegmentCollection pSC          = pGeometry as ISegmentCollection;//可能用到的东西:FromPoint、ToPoint、EnumCurve、EnumSegments---IEnumSegment
            IEnumSegment       pEnumSegment = pSC.EnumSegments;

            pEnumSegment.Reset();
            ISegment pSegment;
            int      partIndex    = 0;
            int      segmentIndex = 0;

            pEnumSegment.Next(out pSegment, ref partIndex, ref segmentIndex);
            int i = 0;

            while (!pEnumSegment.IsLastInPart())
            {
                pEnumSegment.SetAt(0, i);
                pEnumSegment.Next(out pSegment, ref partIndex, ref segmentIndex);
                i++;
            }
            pEnumSegment.SetAt(0, i - 1);
            pEnumSegment.Next(out pSegment, ref partIndex, ref segmentIndex);
            ILine  pLine = pSegment as ILine;
            double a     = pLine.Angle;

            if (a > 0 && a <= Math.PI)
            {
                pAngle = a - Math.PI;
            }
            if (a > -Math.PI && a <= 0)
            {
                pAngle = a + Math.PI;
            }
            return(pAngle);
        }//获取夹角的辅助
コード例 #2
0
        public SegmentProxy GetSegment(int partIndex, int segmentIndex)
        {
            IEnumSegment enumSegs = _segments.EnumSegments;

            enumSegs.SetAt(partIndex, segmentIndex);

            ISegment segment;

            enumSegs.Next(out segment, ref partIndex, ref segmentIndex);

            ISegment proxiedSegment;

            if (enumSegs.IsRecycling)
            {
                proxiedSegment = GeometryFactory.Clone(segment);

                // release the segment, otherwise "pure virtual function call" occurs
                // when there are certain circular arcs (IsLine == true ?)
                Marshal.ReleaseComObject(segment);
            }
            else
            {
                proxiedSegment = segment;
            }

            return(new AoSegmentProxy(proxiedSegment, partIndex, segmentIndex));
        }
コード例 #3
0
 public SegmentCollectionLengthProvider([NotNull] ISegmentCollection segments, bool is3D)
     : base(is3D)
 {
     _segments     = segments;
     _enumSegments = segments.EnumSegments;
     _isRecycling  = _enumSegments.IsRecycling;
 }
コード例 #4
0
ファイル: Utils3D.cs プロジェクト: secondii/Yutai
        public static int ThinPolyline3D(IPointCollection ipointCollection_0)
        {
            int num   = -1;
            int index = 0;
            int num2  = -1;
            int num3  = 0;

            while (ipointCollection_0.PointCount != num2)
            {
                num2 = ipointCollection_0.PointCount;
                ISegmentCollection segmentCollection = ipointCollection_0 as ISegmentCollection;
                IEnumSegment       enumSegments      = segmentCollection.EnumSegments;
                enumSegments.Reset();
                ISegment segment;
                enumSegments.Next(out segment, ref num, ref index);
                ISegment segment2;
                enumSegments.Next(out segment2, ref num, ref index);
                while (segment2 != null)
                {
                    int num4 = segment.ReturnTurnDirection(segment2);
                    if (num4 == 1)
                    {
                        ipointCollection_0.RemovePoints(index, 1);
                    }
                    segment = segment2;
                    enumSegments.Next(out segment2, ref num, ref index);
                }
                num3++;
            }
            return(num3);
        }
コード例 #5
0
        public IPolyline ScaleRaai(ref IPolyline Raai)
        {
            ISegmentCollection Segments       = Raai as ISegmentCollection;
            IEnumSegment       enumSegment    = Segments.EnumSegments;
            ISegment           Segment        = null;
            ISegment           LangsteSegment = null;

            int outPartIndex = 0;
            int SegmentIndex = 0;

            enumSegment.Next(out Segment, ref outPartIndex, ref SegmentIndex);
            LangsteSegment = Segment;

            while (Segment != null)
            {
                if (Segment.Length >= LangsteSegment.Length)
                {
                    LangsteSegment = (Segment as IClone).Clone() as ISegment;
                }
                enumSegment.Next(out Segment, ref outPartIndex, ref SegmentIndex);
            }

            IConstructLine line = new Line() as IConstructLine;

            line.ConstructExtended(LangsteSegment as ILine, esriSegmentExtension.esriExtendEmbedded);

            Raai = new Polyline() as IPolyline;
            (Raai as IPointCollection).AddPoint((line as ILine).FromPoint);
            (Raai as IPointCollection).AddPoint((line as ILine).ToPoint);

            return(Raai);
        }
コード例 #6
0
            public SegmentEnumerator([NotNull] IEnumSegment enumSegment)
            {
                Assert.ArgumentNotNull(enumSegment, nameof(enumSegment));

                _enumSegment = enumSegment;
                _isRecycling = enumSegment.IsRecycling;
            }
コード例 #7
0
        public IEnumerable <SegmentProxy> GetSegments()
        {
            IEnumSegment enumSegs = _segments.EnumSegments;

            var enumerable = new SegmentEnumerable(enumSegs);

            return(enumerable);
        }
コード例 #8
0
        public SegmentsEnumerator([NotNull] IEnumSegment enumSegment)
        {
            Assert.ArgumentNotNull(enumSegment, nameof(enumSegment));

            _enumSegment = enumSegment;

            Reset();

            _recycling = _enumSegment.IsRecycling;
        }
コード例 #9
0
        public IEnumerable <SegmentProxy> GetSegments(IBox box)
        {
            IPnt min = box.Min;
            IPnt max = box.Max;

            _qEnv.Value.PutCoords(min.X, min.Y, max.X, max.Y);
            IEnumSegment enumSegs = _segments.IndexedEnumSegments[_qEnv.Value];

            var enumerable = new SegmentEnumerable(enumSegs);

            return(enumerable);
        }
コード例 #10
0
        private static ISegment GetSegment([NotNull] IEnumSegment enumSegments,
                                           int segmentIndex)
        {
            enumSegments.SetAt(0, segmentIndex);

            ISegment segment;
            int      partIndex = 0;
            int      segIndex  = 0;

            enumSegments.Next(out segment, ref partIndex, ref segIndex);
            return(Assert.NotNull(segment, "segment not found for index {0}",
                                  segmentIndex));
        }
コード例 #11
0
        public void CreatePropertyChildNodes(TreeviewBranchViewModel parentNode, object comObj, Type typ)
        {
            IEnumSegment comEnum = comObj as IEnumSegment;

            foreach (ICurve enumValue in comEnum.Enumerate())
            {
                if ((enumValue != null) && (enumValue.GetType().IsCOMObject))
                {
                    ComObjectViewModel child = new ComObjectViewModel(parentNode, enumValue, typeof(ICurve), ".Next()");
                    parentNode.Children.Add(child);
                }
            }
        }
コード例 #12
0
        /// <summary>
        /// Converts an Esri enumerable interface to a DotNet IEnumerable.
        /// </summary>
        /// <param name="esriEnum">An enumerable Esri interface.</param>
        /// <returns>The adapted dotnet enumeration.</returns>
        public static IEnumerable <ICurve> Enumerate(this IEnumSegment esriEnum)
        {
            ISegment segment;
            var      partIndex    = 0;
            var      segmentIndex = 0;

            esriEnum.Reset();
            esriEnum.Next(out segment, ref partIndex, ref segmentIndex);
            while (segment != null)
            {
                yield return(segment);

                esriEnum.Next(out segment, ref partIndex, ref segmentIndex);
            }
        }
コード例 #13
0
        }//获取相交道路的夹角

        private double AngleFromPoint(IGeometry pGeometry)
        {
            ISegmentCollection pSC          = pGeometry as ISegmentCollection;//可能用到的东西:FromPoint、ToPoint、EnumCurve、EnumSegments---IEnumSegment
            IEnumSegment       pEnumSegment = pSC.EnumSegments;

            pEnumSegment.Reset();
            ISegment pSegment;
            int      partIndex    = 0;
            int      segmentIndex = 0;

            pEnumSegment.Next(out pSegment, ref partIndex, ref segmentIndex);
            ILine  pLine  = pSegment as ILine;
            double pAngle = pLine.Angle;

            return(pAngle);
        }//获取夹角的辅助
コード例 #14
0
ファイル: QaMaxSlope.cs プロジェクト: sungaoyong/ProSuite
        private int CheckSegments([NotNull] ISegmentCollection segments,
                                  [NotNull] IRow row)
        {
            IEnumSegment enumSegments = segments.EnumSegments;

            enumSegments.Reset();

            ISegment segment;
            int      partIndex    = -1;
            int      segmentIndex = -1;

            enumSegments.Next(out segment, ref partIndex, ref segmentIndex);
            bool recycling = enumSegments.IsRecycling;

            int errorCount = 0;

            while (segment != null)
            {
                double slopeRadians = GeometryMathUtils.CalculateSlope(segment);

                if (slopeRadians > _limit)
                {
                    string description = string.Format(
                        "Slope angle {0} > {1}", FormatAngle(slopeRadians, "N2"),
                        FormatAngle(_limit, "N2"));

                    IPolyline errorGeometry = GeometryFactory.CreatePolyline(segment);

                    errorCount += ReportError(description, errorGeometry,
                                              Codes[Code.SlopeTooSteep],
                                              TestUtils.GetShapeFieldName(row),
                                              new object[] { MathUtils.ToDegrees(slopeRadians) },
                                              row);
                }

                if (recycling)
                {
                    // release the segment, otherwise "pure virtual function call" occurs
                    // when there are certain circular arcs (IsLine == true ?)
                    Marshal.ReleaseComObject(segment);
                }

                enumSegments.Next(out segment, ref partIndex, ref segmentIndex);
            }

            return(errorCount);
        }
コード例 #15
0
ファイル: QaMinSegAngle.cs プロジェクト: sungaoyong/ProSuite
            public override IEnumerable <AngleInfo> GetAngles()
            {
                ISegment pre = null;

                if (((ICurve)_segments).IsClosed)
                {
                    pre = GetLastNonZeroLengthSegment(_segments);
                }

                IEnumSegment enumSegments = _segments.EnumSegments;
                bool         recycling    = enumSegments.IsRecycling;

                ISegment segment;
                var      partIndex    = 0;
                var      segmentIndex = 0;

                enumSegments.Next(out segment, ref partIndex, ref segmentIndex);

                while (segment != null)
                {
                    // ignore zero-length segments
                    if (!IsZeroLength(segment))
                    {
                        ISegment next = recycling
                                                                        ? GeometryFactory.Clone(segment)
                                                                        : segment;

                        if (pre != null)
                        {
                            yield return(AngleInfo.Create(pre, next, Settings.Is3D));
                        }

                        pre = next;
                    }

                    if (recycling)
                    {
                        // release the segment, otherwise "pure virtual function call" occurs
                        // when there are certain circular arcs (IsLine == true ?)
                        Marshal.ReleaseComObject(segment);
                    }

                    enumSegments.Next(out segment, ref partIndex, ref segmentIndex);
                }
            }
コード例 #16
0
        public static bool IsNonLinearGeometry(ISegmentCollection segColl)
        {
            IEnumSegment enumSeg = segColl.EnumSegments;

            enumSeg.Reset();
            ISegment seg;
            int      outPartIdx = 0;
            int      segIdx     = 0;

            enumSeg.Next(out seg, ref outPartIdx, ref segIdx);

            ESRI.ArcGIS.Geometry.esriGeometryType geometryType;
            while (seg != null)
            {
                geometryType = seg.GeometryType;
                if (geometryType == ESRI.ArcGIS.Geometry.esriGeometryType.esriGeometryBezier3Curve ||
                    geometryType == ESRI.ArcGIS.Geometry.esriGeometryType.esriGeometryCircularArc ||
                    geometryType == ESRI.ArcGIS.Geometry.esriGeometryType.esriGeometryEllipticArc)
                {
                    return(true);
                }
                enumSeg.Next(out seg, ref outPartIdx, ref segIdx);
            }
            return(false);


            //IEnumSegment enumSeg = segColl.EnumSegments;
            //enumSeg.Reset();
            //ISegment seg = enumSeg.Next();

            //do while (seg != null)
            //{
            //    ESRI.ArcGIS.Geometry.esriGeometryType geometryType = seg.GeometryType;
            //    if (geometryType == ESRI.ArcGIS.Geometry.esriGeometryType.esriGeometryBezier3Curve ||
            //        geometryType == ESRI.ArcGIS.Geometry.esriGeometryType.esriGeometryCircularArc ||
            //        geometryType == ESRI.ArcGIS.Geometry.esriGeometryType.esriGeometryEllipticArc)
            //    {
            //        return true;
            //    }
            //seg = enumSeg.Next();
            //}
            //return false;
        }
コード例 #17
0
        public static IPolyline GetSubpart([NotNull] ISegmentCollection segments,
                                           int partIndex,
                                           int startSegmentIndex,
                                           int endSegmentIndex)
        {
            object             missing  = Type.Missing;
            ISegmentCollection polyline = new PolylineClass();

            ((IZAware)polyline).ZAware = ((IZAware)segments).ZAware;

            for (int segmentIndex = startSegmentIndex;
                 segmentIndex <= endSegmentIndex;
                 segmentIndex++)
            {
                ISegment     segment;
                IEnumSegment enumSegs = segments.EnumSegments;
                enumSegs.SetAt(partIndex, segmentIndex);
                enumSegs.Next(out segment, ref partIndex, ref segmentIndex);

                ISegment addSegment;
                if (enumSegs.IsRecycling)
                {
                    addSegment = GeometryFactory.Clone(segment);

                    // release the segment, otherwise "pure virtual function call" occurs
                    // when there are certain circular arcs (IsLine == true ?)
                    Marshal.ReleaseComObject(segment);
                }
                else
                {
                    addSegment = segment;
                }

                polyline.AddSegment(addSegment, ref missing, ref missing);
            }

            return((IPolyline)polyline);
        }
コード例 #18
0
ファイル: QaCurve.cs プロジェクト: sungaoyong/ProSuite
        private int ReportCurveSegments([NotNull] ISegmentCollection segments,
                                        [NotNull] IRow row,
                                        [CanBeNull] ISpatialReference spatialReference)
        {
            var    errorCount = 0;
            object missing    = Type.Missing;

            // IEnumSegments ist massiv schneller als .get_Segment
            IEnumSegment enumSegments = segments.EnumSegments;

            enumSegments.Reset();

            var      partIndex    = 0;
            var      segmentIndex = 0;
            ISegment segment;

            enumSegments.Next(out segment, ref partIndex, ref segmentIndex);

            // this will be null when no open sequence of error segments exist,
            // and non-null while such a sequence exists and has not yet been reported
            IPolyline consecutiveSegmentsPolyline = null;
            int       currentPartIndex            = partIndex;

            var latestSegmentType = esriGeometryType.esriGeometryNull;

            while (segment != null)
            {
                if (!IsAllowedCurveType(segment.GeometryType))
                {
                    if (consecutiveSegmentsPolyline != null && GroupIssuesBySegmentType &&
                        segment.GeometryType != latestSegmentType)
                    {
                        // report the consecutive curves found so far
                        errorCount += ReportError(row, consecutiveSegmentsPolyline);

                        // get ready for next sequence of curves
                        consecutiveSegmentsPolyline = null;
                    }

                    if (consecutiveSegmentsPolyline == null)
                    {
                        consecutiveSegmentsPolyline =
                            GeometryFactory.CreatePolyline(spatialReference);
                    }

                    // important: the segment enumerator is *recycling*, it is mandatory
                    // to create a copy of the segment. Even if it was not recycling it's better to
                    // clone, as AddSegment() just stores a reference to the passed segment (in
                    // the source geometry!)
                    ISegment segmentCopy = GeometryFactory.Clone(segment);

                    ((ISegmentCollection)consecutiveSegmentsPolyline).AddSegment(
                        segmentCopy, ref missing, ref missing);
                }
                else
                {
                    // it's a linear or allowed segment

                    if (consecutiveSegmentsPolyline != null)
                    {
                        // report the consecutive curves found so far
                        errorCount += ReportError(row, consecutiveSegmentsPolyline);

                        // get ready for next sequence of curves
                        consecutiveSegmentsPolyline = null;
                    }
                }

                latestSegmentType = segment.GeometryType;

                // release the segment, otherwise "pure virtual function call" occurs
                // when there are certain circular arcs (IsLine == true ?)
                Marshal.ReleaseComObject(segment);

                enumSegments.Next(out segment, ref partIndex, ref segmentIndex);

                if (segment != null && partIndex != currentPartIndex)
                {
                    // next segment is on another part
                    if (consecutiveSegmentsPolyline != null)
                    {
                        // there is an ongoing sequence of curves, report it
                        errorCount += ReportError(row, consecutiveSegmentsPolyline);

                        // get ready for next sequence of curves
                        consecutiveSegmentsPolyline = null;
                    }

                    currentPartIndex = partIndex;
                }
            }

            if (consecutiveSegmentsPolyline != null)
            {
                // report the last sequence
                errorCount += ReportError(row, consecutiveSegmentsPolyline);
            }

            return(errorCount);
        }
コード例 #19
0
 public SegmentEnumerable([NotNull] IEnumSegment enumSegment)
 {
     _enumSegment = enumSegment;
 }
コード例 #20
0
 public SegmentCollectionSlopeAngleProvider([NotNull] ISegmentCollection segments)
 {
     _segments     = segments;
     _enumSegments = segments.EnumSegments;
     _isRecycling  = _enumSegments.IsRecycling;
 }
コード例 #21
0
        private int ReportInvalidSegments([NotNull] ISegmentCollection segments,
                                          [NotNull] IRow row)
        {
            var errorCount = 0;

            List <ISegment> currentInvalidSequence = null;
            int             currentPartIndex       = -1;

            IEnumSegment enumSegment = segments.EnumSegments;

            int      partIndex    = -1;
            int      segmentIndex = -1;
            ISegment segment;

            enumSegment.Next(out segment, ref partIndex, ref segmentIndex);

            while (segment != null)
            {
                if (currentInvalidSequence != null && partIndex != currentPartIndex)
                {
                    // report sequence from previous part
                    errorCount            += ReportInvalidSequence(currentInvalidSequence, row, _invalidValue);
                    currentInvalidSequence = null;
                    currentPartIndex       = -1;
                }

                if (MeasureUtils.HasInvalidMValue(segment, _queryPoint, _invalidValue))
                {
                    if (currentInvalidSequence == null)
                    {
                        // initialize sequence
                        currentInvalidSequence = new List <ISegment>();
                        currentPartIndex       = partIndex;
                    }

                    currentInvalidSequence.Add(GeometryFactory.Clone(segment));
                }
                else
                {
                    if (currentInvalidSequence != null)
                    {
                        errorCount +=
                            ReportInvalidSequence(currentInvalidSequence, row, _invalidValue);
                        currentInvalidSequence = null;
                        currentPartIndex       = -1;
                    }
                }

                // release the segment, otherwise "pure virtual function call" occurs
                // when there are certain circular arcs (IsLine == true ?)
                Marshal.ReleaseComObject(segment);

                enumSegment.Next(out segment, ref partIndex, ref segmentIndex);
            }

            if (currentInvalidSequence != null)
            {
                // report sequence at end of segment collection
                errorCount += ReportInvalidSequence(currentInvalidSequence, row, _invalidValue);
            }

            return(errorCount);
        }
コード例 #22
0
        private static IEnumerable <ZMonotonicitySequence> GetErrorSequencesFromSinglePart(
            [NotNull] IPolyline singlePartPolyline,
            MonotonicityDirection expectedMonotonicity,
            [NotNull] Func <bool> isFeatureFlipped,
            bool allowConstantValues)
        {
            bool?featureFlipped = null;

            var points       = (IPointCollection4)singlePartPolyline;
            int segmentCount = points.PointCount - 1;

            WKSPointZ[] wksPointZs = new WKSPointZ[points.PointCount];

            GeometryUtils.QueryWKSPointZs(points, wksPointZs);

            ZMonotonicitySequence currentSequence = null;

            double trend = wksPointZs[segmentCount].Z - wksPointZs[0].Z;
            esriMonotinicityEnum monotonicityTrend =
                MeasureUtils.GetMonotonicityType(trend);

            var checkedMonotonicity = GetCheckedMonotonicityDirection(
                expectedMonotonicity,
                monotonicityTrend);

            esriMonotinicityEnum?preMonotonicity = null;
            IEnumSegment         enumSegments    = null;
            bool?recycling = null;

            for (int segmentIndex = 0; segmentIndex < segmentCount; segmentIndex++)
            {
                double dz = wksPointZs[segmentIndex + 1].Z - wksPointZs[segmentIndex].Z;

                esriMonotinicityEnum monotonicity = MeasureUtils.GetMonotonicityType(dz);

                if (monotonicity == esriMonotinicityEnum.esriValueDecreases ||
                    monotonicity == esriMonotinicityEnum.esriValueIncreases)
                {
                    if (!featureFlipped.HasValue)
                    {
                        featureFlipped = isFeatureFlipped();
                    }

                    if (featureFlipped.Value)
                    {
                        monotonicity =
                            monotonicity == esriMonotinicityEnum.esriValueDecreases
                                                                ? esriMonotinicityEnum.esriValueIncreases
                                                                : esriMonotinicityEnum.esriValueDecreases;
                    }
                }

                if (monotonicity != preMonotonicity)
                {
                    if (currentSequence != null)
                    {
                        yield return(currentSequence);
                    }

                    preMonotonicity = monotonicity;
                    currentSequence = null;
                }

                if (currentSequence == null)
                {
                    if (monotonicity == esriMonotinicityEnum.esriValueLevel &&
                        allowConstantValues)
                    {
                        // ok
                    }
                    else if (monotonicity == esriMonotinicityEnum.esriValueIncreases &&
                             checkedMonotonicity == MonotonicityDirection.Increasing)
                    {
                        // ok
                    }
                    else if (monotonicity == esriMonotinicityEnum.esriValueDecreases &&
                             checkedMonotonicity == MonotonicityDirection.Decreasing)
                    {
                        // ok
                    }
                    else if (checkedMonotonicity == MonotonicityDirection.Any)
                    {
                        if (monotonicity == esriMonotinicityEnum.esriValueIncreases)
                        {
                            checkedMonotonicity = MonotonicityDirection.Increasing;
                        }
                        else if (monotonicity == esriMonotinicityEnum.esriValueDecreases)
                        {
                            checkedMonotonicity = MonotonicityDirection.Decreasing;
                        }
                    }
                    else
                    {
                        currentSequence =
                            new ZMonotonicitySequence(monotonicity,
                                                      singlePartPolyline.SpatialReference)
                        {
                            FeatureMonotonicityTrend = monotonicityTrend,
                            FeatureIsFlipped         = featureFlipped
                        };
                    }
                }

                if (currentSequence != null)
                {
                    if (enumSegments == null)
                    {
                        enumSegments = ((ISegmentCollection)singlePartPolyline)
                                       .EnumSegments;
                    }

                    var segment = GetSegment(enumSegments, segmentIndex);
                    if (!recycling.HasValue)
                    {
                        recycling = enumSegments.IsRecycling;
                    }

                    currentSequence.Add(recycling.Value
                                                                    ? GeometryFactory.Clone(segment)
                                                                    : segment);

                    if (recycling.Value)
                    {
                        Marshal.ReleaseComObject(segment);
                    }
                }
            }

            if (currentSequence != null)
            {
                yield return(currentSequence);
            }

            if (enumSegments != null)
            {
                enumSegments.Reset();
            }
        }
コード例 #23
0
        public PartProxy([NotNull] BoxTree <SegmentProxy> boxTree,
                         int partIndex,
                         [NotNull] IPointCollection4 baseGeometry)
        {
            _partIndex       = partIndex;
            SpatialReference = ((IGeometry)baseGeometry).SpatialReference;

            _points = new WKSPointZ[baseGeometry.PointCount];
            GeometryUtils.QueryWKSPointZs(baseGeometry, _points);

            var segmentCollection = baseGeometry as ISegmentCollection;

            if (segmentCollection == null)
            {
                return;
            }

            SegmentCount = segmentCollection.SegmentCount;
            IsClosed     = ((ICurve)segmentCollection).IsClosed;

            segmentCollection.HasNonLinearSegments(ref _hasNonLinearSegs);

            if (_hasNonLinearSegs)
            {
                _nonLinearSegments = new Dictionary <int, AoSegmentProxy>();

                IEnumSegment enumSeg   = segmentCollection.EnumSegments;
                bool         recycling = enumSeg.IsRecycling;

                ISegment segment;
                int      outPartIndex    = 0;
                int      outSegmentIndex = 0;

                enumSeg.Next(out segment, ref outPartIndex, ref outSegmentIndex);

                while (segment != null)
                {
                    var          line = segment as ILine;
                    SegmentProxy segmentProxy;
                    if (line != null)
                    {
                        segmentProxy = new WksSegmentProxy(this, _partIndex, outSegmentIndex);
                    }
                    else
                    {
                        var aoSegmentProxy = new AoSegmentProxy(recycling
                                                                                                ? GeometryFactory.Clone(segment)
                                                                                                : segment,
                                                                _partIndex, outSegmentIndex);

                        _nonLinearSegments.Add(outSegmentIndex, aoSegmentProxy);
                        segmentProxy = aoSegmentProxy;
                    }

                    boxTree.Add(segmentProxy.Extent, segmentProxy);

                    if (recycling)
                    {
                        Marshal.ReleaseComObject(segment);
                    }

                    enumSeg.Next(out segment, ref outPartIndex, ref outSegmentIndex);
                }
            }
            else
            {
                int segmentCount = segmentCollection.SegmentCount;
                for (int segmentIndex = 0; segmentIndex < segmentCount; segmentIndex++)
                {
                    var wksSegmentProxy = new WksSegmentProxy(this, _partIndex, segmentIndex);

                    boxTree.Add(wksSegmentProxy.Extent, wksSegmentProxy);
                }
            }
        }
コード例 #24
0
            protected override IEnumerable <MeanSegmentLength> ReadSegmentLengthCore()
            {
                IEnumSegment enumSegments = _segments.EnumSegments;
                bool         isRecycling  = enumSegments.IsRecycling;

                enumSegments.Reset();
                int      lastPartIndex = -1;
                int      segmentCount  = 0;
                double   fullLength    = 0;
                ISegment segment       = null;
                int      partIndex     = 0;
                int      segmentIndex  = 0;

                do
                {
                    if (isRecycling && segment != null)
                    {
                        Marshal.ReleaseComObject(segment);
                    }

                    enumSegments.Next(out segment, ref partIndex, ref segmentIndex);

                    if (segment != null)
                    {
                        if (_perPart && partIndex != lastPartIndex)
                        {
                            if (segmentCount > 0)
                            {
                                int index = lastPartIndex;
                                yield return
                                    (new MeanSegmentLength(fullLength, segmentCount,
                                                           () => GetGeometry(index)));
                            }

                            segmentCount  = 0;
                            fullLength    = 0;
                            lastPartIndex = partIndex;
                        }

                        double length = segment.Length;
                        if (_is3D)
                        {
                            double z0 = segment.FromPoint.Z;
                            double z1 = segment.ToPoint.Z;
                            double dz = z1 - z0;
                            length = Math.Sqrt(length * length + dz * dz);
                        }

                        fullLength += length;
                        segmentCount++;
                    }
                } while (segment != null);

                if (segmentCount > 0)
                {
                    yield return(new MeanSegmentLength(fullLength,
                                                       segmentCount,
                                                       () => GetGeometry(lastPartIndex)));
                }

                Marshal.ReleaseComObject(enumSegments);
            }
コード例 #25
0
ファイル: ZRangeUtils.cs プロジェクト: sungaoyong/ProSuite
        private static IEnumerable <ZRangeErrorSegments> GetErrorSegments(
            [NotNull] ISegmentCollection segments,
            double minimumZ,
            double maximumZ,
            [CanBeNull] Predicate <double> isAllowed)
        {
            Assert.ArgumentNotNull(segments, nameof(segments));

            IEnumSegment enumSegments = segments.EnumSegments;
            bool         recycling    = enumSegments.IsRecycling;

            enumSegments.Reset();

            var      partIndex    = 0;
            var      segmentIndex = 0;
            ISegment segment;

            enumSegments.Next(out segment, ref partIndex, ref segmentIndex);

            ISpatialReference spatialReference = ((IGeometry)segments).SpatialReference;

            // this will be null when no open sequence of error segments exist,
            // and non-null while such a sequence exists and has not yet been reported
            ZRangeErrorSegments currentErrorSegments = null;

            var firstSegment = true;

            while (segment != null)
            {
                double fromZ;
                double toZ;
                segment.QueryVertexAttributes(esriGeometryAttributes.esriAttributeZ,
                                              out fromZ, out toZ);

                ISegment fromSegment;
                ISegment toSegment;

                double splitPointZ;
                if (fromZ < minimumZ && !(isAllowed != null && isAllowed(fromZ)))
                {
                    if (toZ < minimumZ && !(isAllowed != null && isAllowed(toZ)))
                    {
                        // fromZ below, toZ below

                        // add whole segment (below)
                        if (currentErrorSegments == null)
                        {
                            currentErrorSegments = new ZRangeErrorSegments(
                                ZRangeRelation.BelowZMin, spatialReference, firstSegment);
                        }

                        currentErrorSegments.AddSegment(recycling
                                                                                        ? GeometryFactory.Clone(segment)
                                                                                        : segment,
                                                        fromZ, toZ);
                    }
                    else if (toZ > maximumZ && !(isAllowed != null && isAllowed(toZ)))
                    {
                        // fromZ below, toZ above

                        // interpolate from (below)
                        SplitSegmentAtZValue(segment, fromZ, toZ, minimumZ, isAllowed,
                                             out fromSegment, out toSegment,
                                             out splitPointZ);
                        if (currentErrorSegments == null)
                        {
                            currentErrorSegments = new ZRangeErrorSegments(
                                ZRangeRelation.BelowZMin, spatialReference, firstSegment);
                        }

                        currentErrorSegments.AddSegment(fromSegment, fromZ, splitPointZ);
                        yield return(currentErrorSegments);

                        //interpolate to (above)
                        SplitSegmentAtZValue(segment, fromZ, toZ, maximumZ, isAllowed,
                                             out fromSegment, out toSegment, out splitPointZ);

                        currentErrorSegments = new ZRangeErrorSegments(
                            ZRangeRelation.AboveZMax, spatialReference);
                        currentErrorSegments.AddSegment(toSegment, splitPointZ, toZ);
                    }
                    else                     // to z ok
                    {
                        // fromZ below, toZ OK

                        // interpolate from (below)
                        SplitSegmentAtZValue(segment, fromZ, toZ, minimumZ, isAllowed,
                                             out fromSegment, out toSegment, out splitPointZ);

                        if (currentErrorSegments == null)
                        {
                            currentErrorSegments = new ZRangeErrorSegments(
                                ZRangeRelation.BelowZMin, spatialReference, firstSegment);
                        }

                        currentErrorSegments.AddSegment(fromSegment, fromZ, splitPointZ);

                        yield return(currentErrorSegments);

                        currentErrorSegments = null;
                    }
                }
                else if (fromZ > maximumZ && !(isAllowed != null && isAllowed(fromZ)))
                {
                    if (toZ < minimumZ)
                    {
                        // fromZ above, toZ below

                        // interpolate from (above)
                        SplitSegmentAtZValue(segment, fromZ, toZ, maximumZ, isAllowed,
                                             out fromSegment, out toSegment, out splitPointZ);
                        if (currentErrorSegments == null)
                        {
                            currentErrorSegments = new ZRangeErrorSegments(
                                ZRangeRelation.AboveZMax, spatialReference, firstSegment);
                        }

                        currentErrorSegments.AddSegment(fromSegment, fromZ, splitPointZ);

                        yield return(currentErrorSegments);

                        // interpolate to (below)
                        SplitSegmentAtZValue(segment, fromZ, toZ, minimumZ, isAllowed,
                                             out fromSegment, out toSegment, out splitPointZ);

                        currentErrorSegments = new ZRangeErrorSegments(
                            ZRangeRelation.BelowZMin, spatialReference);
                        currentErrorSegments.AddSegment(toSegment, splitPointZ, toZ);
                    }
                    else if (toZ > maximumZ && !(isAllowed != null && isAllowed(toZ)))
                    {
                        // fromZ above, toZ above

                        // add whole segment
                        if (currentErrorSegments == null)
                        {
                            currentErrorSegments = new ZRangeErrorSegments(
                                ZRangeRelation.AboveZMax, spatialReference, firstSegment);
                        }

                        currentErrorSegments.AddSegment(segment, fromZ, toZ);
                    }
                    else
                    {
                        // fromZ above, toZ OK

                        // interpolate from (above)
                        SplitSegmentAtZValue(segment, fromZ, toZ, maximumZ, isAllowed,
                                             out fromSegment, out toSegment, out splitPointZ);
                        if (currentErrorSegments == null)
                        {
                            currentErrorSegments = new ZRangeErrorSegments(
                                ZRangeRelation.AboveZMax, spatialReference, firstSegment);
                        }

                        currentErrorSegments.AddSegment(fromSegment, fromZ, splitPointZ);

                        yield return(currentErrorSegments);

                        currentErrorSegments = null;
                    }
                }
                else                 //from Z ok
                {
                    if (toZ < minimumZ && !(isAllowed != null && isAllowed(toZ)))
                    {
                        // fromZ OK, toZ below

                        // interpolate to (below)
                        SplitSegmentAtZValue(segment, fromZ, toZ, minimumZ, isAllowed,
                                             out fromSegment, out toSegment, out splitPointZ);
                        if (currentErrorSegments == null)
                        {
                            currentErrorSegments = new ZRangeErrorSegments(
                                ZRangeRelation.BelowZMin, spatialReference);
                        }

                        currentErrorSegments.AddSegment(toSegment, splitPointZ, toZ);
                    }
                    else if (toZ > maximumZ && !(isAllowed != null && isAllowed(toZ)))
                    {
                        // fromZ OK, toZ above

                        // interpolate to (above)
                        SplitSegmentAtZValue(segment, fromZ, toZ, maximumZ, isAllowed,
                                             out fromSegment, out toSegment, out splitPointZ);
                        if (currentErrorSegments == null)
                        {
                            currentErrorSegments = new ZRangeErrorSegments(
                                ZRangeRelation.AboveZMax, spatialReference);
                        }

                        currentErrorSegments.AddSegment(toSegment, splitPointZ, toZ);
                    }
                }

                if (recycling)
                {
                    // release the segment, otherwise "pure virtual function call" occurs
                    // when there are certain circular arcs (IsLine == true ?)
                    Marshal.ReleaseComObject(segment);
                }

                enumSegments.Next(out segment, ref partIndex, ref segmentIndex);
                firstSegment = false;
            }

            if (currentErrorSegments != null)
            {
                currentErrorSegments.EndsOnLastSegment = true;
                yield return(currentErrorSegments);
            }
        }
コード例 #26
0
        public static int CalculateOrientation([NotNull] ISegmentCollection lineSegments,
                                               double resolution,
                                               out double yMax)
        {
            double       xMax;
            IEnumSegment segmentsAtXMax = GetSegmentsAtXMax(lineSegments, resolution,
                                                            out xMax);

            var segmentsEnum = new SegmentsEnumerator(segmentsAtXMax)
            {
                Recycle = false
            };

            var segments = new SegmentsEnumerable(segmentsEnum);
            var box      = new WKSEnvelope();

            foreach (ISegment segment in segments)
            {
                Assert.True(segments.Enumerator.CurrentPartIndex == 0,
                            "Cannot handle multipart lines");
                segment.QueryWKSEnvelope(ref box);

                if (IsZeroLength(segment))
                {
                    continue;
                }

                if (box.XMax + resolution < xMax)
                {
                    continue;
                }

                WKSPoint fromPoint;
                WKSPoint toPoint;

                segment.QueryWKSFromPoint(out fromPoint);
                segment.QueryWKSToPoint(out toPoint);

                if (fromPoint.X + resolution >= xMax)
                {
                    yMax = fromPoint.Y;
                    for (int i = segments.Enumerator.CurrentSegmentIndex - 1;
                         i >= 0;
                         i--)
                    {
                        double   toAngle;
                        ISegment toSeg = lineSegments.Segment[i];
                        if (CalculateToAngle(toSeg, out toAngle))
                        {
                            double fromAngle;
                            CalculateFromAngle(segment, out fromAngle);

                            return(GetOrientation(toAngle, fromAngle));
                        }
                    }

                    return(-2);
                }

                if (toPoint.X + resolution >= xMax)
                {
                    yMax = toPoint.Y;

                    int segmentCount = lineSegments.SegmentCount;
                    for (int i = segments.Enumerator.CurrentSegmentIndex + 1;
                         i < segmentCount;
                         i++)
                    {
                        double   fromAngle;
                        ISegment fromSeg = lineSegments.Segment[i];
                        if (CalculateFromAngle(fromSeg, out fromAngle))
                        {
                            double toAngle;
                            CalculateToAngle(segment, out toAngle);

                            return(GetOrientation(toAngle, fromAngle));
                        }
                    }

                    return(2);
                }

                // linearize not linear segment and
                // get orientation of linearized segment
                var densify = 8;
                int orientation;
                do
                {
                    object    missing = Type.Missing;
                    IPolyline line    = new PolylineClass();
                    ((ISegmentCollection)line).AddSegment(segment, ref missing, ref missing);
                    line.Densify(line.Length / densify, 0);

                    orientation = CalculateOrientation((ISegmentCollection)line, resolution,
                                                       out yMax);

                    densify *= 2;
                }                 // insufficent densification can lead to
                // that start or end point has maxX --> repeat
                while (Math.Abs(orientation) > 1);

                return(orientation);
            }

            yMax = double.NaN;
            return(0);
        }
コード例 #27
0
        private void OnSketchFinished()
        {
            ConfigUtil.type = "gas";
            IFeature           pFeat       = null;
            ISegmentCollection pSegColl    = null;
            IEnumSegment       pESeg       = null;
            ISegment           testSegment = null;
            ISegmentCollection segColTest  = null;
            object             Missing     = null;

            try
            {
                // Send a shift-tab to hide the construction toolbar

                try
                {
                    m_editor.StartOperation();
                }
                catch
                {
                    m_editor.AbortOperation();
                    m_editor.StartOperation();
                }
                bool twoPoint = false;
                (ArcMap.Application.Document as IMxDocument).FocusMap.ClearSelection();
                List <IFeature> pLstFeat   = null;
                string          storeOrder = "";
                if (Control.ModifierKeys == Keys.Control)
                {
                    twoPoint = CreateLineWithEndPoints.CreatePoints(ArcMap.Application, ConfigUtil.GetLinePointAtEndsConfig(), m_edSketch.Geometry as IPolyline, (IFeatureLayer)m_editor.CurrentTemplate.Layer, false, out pLstFeat, out storeOrder);
                }
                else
                {
                    twoPoint = CreateLineWithEndPoints.CreatePoints(ArcMap.Application, ConfigUtil.GetLinePointAtEndsConfig(), m_edSketch.Geometry as IPolyline, (IFeatureLayer)m_editor.CurrentTemplate.Layer, true, out pLstFeat, out storeOrder);
                }
                if (storeOrder == null)
                {
                    storeOrder = "Points";
                }
                if (storeOrder.ToUpper() == "points".ToUpper())
                {
                    foreach (IFeature pFt in pLstFeat)
                    {
                        try
                        {
                            pFt.Store();
                        }
                        catch (Exception ex)
                        {
                            MessageBox.Show(A4LGSharedFunctions.Localizer.GetString("errorOnIFeatureStore"));
                            m_editor.AbortOperation();
                            return;
                        }
                    }
                }
                if (twoPoint)
                {
                    pSegColl = (ISegmentCollection)m_edSketch.Geometry;
                    pESeg    = pSegColl.EnumSegments;
                    pESeg.Reset();


                    int partIndex    = 0;
                    int segmentIndex = 0;

                    pESeg.Next(out testSegment, ref partIndex, ref segmentIndex);

                    while (testSegment != null)
                    {
                        segColTest = new PolylineClass();

                        Missing = Type.Missing;
                        segColTest.AddSegment(testSegment, ref Missing, ref Missing);

                        pFeat = Globals.CreateFeature(segColTest as IGeometry, m_editor.CurrentTemplate, m_editor, ArcMap.Application, false, false, true);
                        try
                        {
                            pFeat.Store();
                        }
                        catch (Exception ex)
                        {
                            MessageBox.Show(A4LGSharedFunctions.Localizer.GetString("errorOnIFeatureStore"));
                            m_editor.AbortOperation();
                            return;
                        }
                        pESeg.Next(out testSegment, ref partIndex, ref segmentIndex);
                    }
                }
                else
                {
                    pFeat = Globals.CreateFeature(m_edSketch.Geometry, m_editor.CurrentTemplate, m_editor, ArcMap.Application, false, false, true);
                    pFeat.Store();
                }

                if (storeOrder.ToUpper() != "points".ToUpper())
                {
                    foreach (IFeature pFt in pLstFeat)
                    {
                        try
                        {
                            pFt.Store();
                        }
                        catch (Exception ex)
                        {
                            MessageBox.Show(A4LGSharedFunctions.Localizer.GetString("errorOnIFeatureStore"));
                            m_editor.AbortOperation();
                            return;
                        }
                    }
                }

                pLstFeat = null;

                m_editor.StopOperation("Create line with points");
            }

            catch (Exception ex)
            {
                MessageBox.Show(A4LGSharedFunctions.Localizer.GetString("ErrorInThe") + A4LGSharedFunctions.Localizer.GetString("CrtLnWithPts") + "\n" + ex.ToString());
                m_editor.AbortOperation();
            }
            finally
            {
                pFeat       = null;
                pSegColl    = null;
                pESeg       = null;
                testSegment = null;
                segColTest  = null;
                Missing     = null;
            }
        }
コード例 #28
0
        private void OnSketchFinished()
        {
            IFeature           pFeat       = null;
            ISegmentCollection pSegColl    = null;
            IEnumSegment       pESeg       = null;
            ISegment           testSegment = null;
            ISegmentCollection segColTest  = null;
            object             Missing     = null;

            try
            {
                // Send a shift-tab to hide the construction toolbar

                try
                {
                    m_editor.StartOperation();
                }
                catch
                {
                    m_editor.AbortOperation();
                    m_editor.StartOperation();
                }
                bool twoPoint = false;
                (ArcMap.Application.Document as IMxDocument).FocusMap.ClearSelection();
                List <IFeature> pLstFeat = null;
                if (Control.ModifierKeys == Keys.Control)
                {
                    twoPoint = CreateLineWithEndPoints.CreatePoints(ArcMap.Application, ConfigUtil.GetLinePointAtEndsConfig(), m_edSketch.Geometry as IPolyline, (IFeatureLayer)m_editor.CurrentTemplate.Layer, false, out pLstFeat);
                }
                else
                {
                    twoPoint = CreateLineWithEndPoints.CreatePoints(ArcMap.Application, ConfigUtil.GetLinePointAtEndsConfig(), m_edSketch.Geometry as IPolyline, (IFeatureLayer)m_editor.CurrentTemplate.Layer, true, out pLstFeat);
                }


                if (twoPoint)
                {
                    pSegColl = (ISegmentCollection)m_edSketch.Geometry;
                    pESeg    = pSegColl.EnumSegments;
                    pESeg.Reset();


                    int partIndex    = 0;
                    int segmentIndex = 0;

                    pESeg.Next(out testSegment, ref partIndex, ref segmentIndex);

                    while (testSegment != null)
                    {
                        segColTest = new PolylineClass();

                        Missing = Type.Missing;
                        segColTest.AddSegment(testSegment, ref Missing, ref Missing);

                        pFeat = Globals.CreateFeature(segColTest as IGeometry, m_editor.CurrentTemplate, m_editor, ArcMap.Application, false, false, true);
                        pFeat.Store();
                        pESeg.Next(out testSegment, ref partIndex, ref segmentIndex);
                    }
                }
                else
                {
                    pFeat = Globals.CreateFeature(m_edSketch.Geometry, m_editor.CurrentTemplate, m_editor, ArcMap.Application, false, false, true);
                    pFeat.Store();
                }

                foreach (IFeature pFt in pLstFeat)
                {
                    pFt.Store();
                }
                pLstFeat = null;

                m_editor.StopOperation(A4LGSharedFunctions.Localizer.GetString("CrtLnWithPts"));
                (ArcMap.Application.Document as IMxDocument).ActiveView.PartialRefresh(esriViewDrawPhase.esriViewAll, null, null);
            }
            catch { }
            finally
            {
                pFeat       = null;
                pSegColl    = null;
                pESeg       = null;
                testSegment = null;
                segColTest  = null;
                Missing     = null;
            }
        }
コード例 #29
0
        public static IEnumerable <MMonotonicitySequence> GetMonotonicitySequences(
            [NotNull] ISegmentCollection segments,
            [NotNull] IEnumerable <esriMonotinicityEnum> monotonicityTypes)
        {
            MMonotonicitySequence currentSequence = null;
            var types = new HashSet <esriMonotinicityEnum>(monotonicityTypes);

            if (types.Count == 0)
            {
                yield break;
            }

            IEnumSegment enumSegments = segments.EnumSegments;

            enumSegments.Reset();

            ISegment segment;
            var      partIndex    = 0;
            var      segmentIndex = 0;

            enumSegments.Next(out segment, ref partIndex, ref segmentIndex);
            bool recycling = enumSegments.IsRecycling;

            while (segment != null)
            {
                esriMonotinicityEnum currentMonotonicity = GetMonotonicityType(segment);

                if (types.Contains(currentMonotonicity))
                {
                    if (currentSequence == null)
                    {
                        currentSequence = new MMonotonicitySequence(currentMonotonicity,
                                                                    segment.SpatialReference);
                    }

                    if (currentSequence.MonotonicityType != currentMonotonicity)
                    {
                        yield return(currentSequence);

                        currentSequence = new MMonotonicitySequence(currentMonotonicity,
                                                                    segment.SpatialReference);
                    }

                    currentSequence.Add(recycling
                                                                    ? GeometryFactory.Clone(segment)
                                                                    : segment);
                }
                else
                {
                    if (currentSequence != null)
                    {
                        yield return(currentSequence);

                        currentSequence = null;
                    }
                }

                if (recycling)
                {
                    Marshal.ReleaseComObject(segment);
                }

                enumSegments.Next(out segment, ref partIndex, ref segmentIndex);
            }

            if (currentSequence != null)
            {
                yield return(currentSequence);
            }
        }