Esempio n. 1
0
        private static MonotonicityDirection GetCheckedMonotonicityDirection(
            MonotonicityDirection expectedMonotonicity,
            esriMonotinicityEnum monotonicityTrend)
        {
            if (expectedMonotonicity != MonotonicityDirection.Any)
            {
                return(expectedMonotonicity);
            }

            switch (monotonicityTrend)
            {
            case esriMonotinicityEnum.esriValueDecreases:
                return(MonotonicityDirection.Decreasing);

            case esriMonotinicityEnum.esriValueIncreases:
                return(MonotonicityDirection.Increasing);

            case esriMonotinicityEnum.esriValueLevel:
            case esriMonotinicityEnum.esriValuesEmpty:
                return(MonotonicityDirection.Any);

            default:
                throw new ArgumentOutOfRangeException(
                          nameof(monotonicityTrend), monotonicityTrend,
                          null);
            }
        }
        public MonotonicitySequence(esriMonotinicityEnum monotonicityType,
                                    [CanBeNull] ISpatialReference spatialReference)
        {
            MonotonicityType = monotonicityType;

            _spatialReference = spatialReference;
        }
        private static IEnumerable <esriMonotinicityEnum> GetInvalidMonotonicityTypes(
            [NotNull] IPolyline polyline)
        {
            esriMonotinicityEnum trend = MeasureUtils.GetMonotonicityTrend(polyline);

            switch (trend)
            {
            case esriMonotinicityEnum.esriValueIncreases:
                yield return(esriMonotinicityEnum.esriValueDecreases);

                break;

            case esriMonotinicityEnum.esriValueDecreases:
                yield return(esriMonotinicityEnum.esriValueIncreases);

                break;

            case esriMonotinicityEnum.esriValueLevel:
                yield return(esriMonotinicityEnum.esriValueIncreases);

                yield return(esriMonotinicityEnum.esriValueDecreases);

                break;

            case esriMonotinicityEnum.esriValuesEmpty:
                break;

            default:
                throw new ArgumentOutOfRangeException();
            }
        }
Esempio n. 4
0
 private static double GetTotalLengthForMonotonicity(
     [NotNull] IEnumerable <MMonotonicitySequence> sequences,
     esriMonotinicityEnum monotinicity)
 {
     return(sequences.Where(sequence => sequence.MonotonicityType == monotinicity)
            .Sum(sequence => sequence.Length));
 }
Esempio n. 5
0
        private static ICollection <esriMonotinicityEnum> GetActualErrorMonotonicities(
            [NotNull] IPolyline singlePartPolyline,
            MonotonicityDirection expectedMonotonicity,
            [NotNull] Func <bool> isFeatureFlipped,
            bool allowConstantValues,
            out bool?featureFlipped,
            out esriMonotinicityEnum?monotonicityTrend)
        {
            var mSegmentation           = (IMSegmentation3)singlePartPolyline;
            int actualMonotonicityTypes = mSegmentation.MMonotonicity;

            monotonicityTrend = null;
            featureFlipped    = null;

            var result = new HashSet <esriMonotinicityEnum>();

            if (!allowConstantValues)
            {
                if (ContainsMonotonicityType(actualMonotonicityTypes,
                                             esriMonotinicityEnum.esriValueLevel))

                {
                    result.Add(esriMonotinicityEnum.esriValueLevel);
                }
            }

            if (expectedMonotonicity == MonotonicityDirection.Any)
            {
                if (ContainsAllMonotonicityTypes(actualMonotonicityTypes,
                                                 esriMonotinicityEnum.esriValueIncreases,
                                                 esriMonotinicityEnum.esriValueDecreases))
                {
                    monotonicityTrend = GetMonotonicityTrend(singlePartPolyline);

                    result.Add(
                        monotonicityTrend == esriMonotinicityEnum.esriValueDecreases
                                                        ? esriMonotinicityEnum.esriValueIncreases
                                                        : esriMonotinicityEnum.esriValueDecreases);
                }

                return(result);
            }

            esriMonotinicityEnum violatingMonotonicityType =
                GetViolatingMonotonicityType(expectedMonotonicity, isFeatureFlipped,
                                             out featureFlipped);

            if (ContainsMonotonicityType(actualMonotonicityTypes,
                                         violatingMonotonicityType))
            {
                result.Add(violatingMonotonicityType);
            }

            return(result);
        }
Esempio n. 6
0
        public void CanGetMonotonicityTrendDecreasing1()
        {
            var polyline = (IPolyline)CurveConstruction.StartLine(CreatePoint(0, 0, -0.00001))
                           .LineTo(CreatePoint(4, 0, -0.1))
                           .Curve;

            polyline.SpatialReference = CreateSpatialReference(_mTolerance, _xyTolerance);
            GeometryUtils.MakeMAware(polyline);

            esriMonotinicityEnum result =
                MeasureUtils.GetMonotonicityTrend(polyline);

            Assert.AreEqual(esriMonotinicityEnum.esriValueDecreases, result);
        }
Esempio n. 7
0
        public void CanGetMonotonicityTrendEmpty()
        {
            var polyline =
                (IPolyline)CurveConstruction.StartLine(CreatePoint(0, 0, double.NaN))
                .LineTo(CreatePoint(50, 0, double.NaN))
                .LineTo(CreatePoint(150, 0, double.NaN))
                .Curve;

            polyline.SpatialReference = CreateSpatialReference(_mTolerance, _xyTolerance);
            GeometryUtils.MakeMAware(polyline);

            esriMonotinicityEnum result =
                MeasureUtils.GetMonotonicityTrend(polyline);

            Assert.AreEqual(esriMonotinicityEnum.esriValuesEmpty, result);
        }
Esempio n. 8
0
        public void CanGetMonotonicityTrendLevelSymmetric()
        {
            var polyline = (IPolyline)CurveConstruction.StartLine(CreatePoint(0, 0, 0))
                           .LineTo(CreatePoint(1, 0, 1))
                           .LineTo(CreatePoint(2, 0, 2))
                           .LineTo(CreatePoint(3, 0, 1))
                           .LineTo(CreatePoint(4, 0, 0))
                           .Curve;

            polyline.SpatialReference = CreateSpatialReference(_mTolerance, _xyTolerance);
            GeometryUtils.MakeMAware(polyline);

            esriMonotinicityEnum result =
                MeasureUtils.GetMonotonicityTrend(polyline);

            Assert.AreEqual(esriMonotinicityEnum.esriValueLevel, result);
        }
Esempio n. 9
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();
            }
        }
Esempio n. 10
0
 public MMonotonicitySequence(esriMonotinicityEnum monotonicityType,
                              [CanBeNull] ISpatialReference spatialReference)
     : base(monotonicityType, spatialReference)
 {
 }
Esempio n. 11
0
 private static bool ContainsMonotonicityType(int monotonicityTypes,
                                              esriMonotinicityEnum monotonicity)
 {
     return((monotonicityTypes & (int)monotonicity) == (int)monotonicity);
 }
Esempio n. 12
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);
            }
        }