예제 #1
0
        public void CanReplaceSegmentsWithNonZAwareReplacement()
        {
            ISpatialReference lv95 =
                SpatialReferenceUtils.CreateSpatialReference(WellKnownHorizontalCS.LV95,
                                                             WellKnownVerticalCS.LHN95);

            IPolyline originalPolyline = GeometryFactory.CreatePolyline(
                GeometryFactory.CreatePath(
                    GeometryFactory.CreatePoint(2600000, 1200000, 400, double.NaN, lv95),
                    GeometryFactory.CreatePoint(2600010, 1200000, 410, double.NaN, lv95),
                    GeometryFactory.CreatePoint(2600020, 1200000, 410, double.NaN, lv95),
                    GeometryFactory.CreatePoint(2600030, 1200000, 420, double.NaN, lv95)));

            IPath replacement = GeometryFactory.CreatePath(
                GeometryFactory.CreatePoint(2600010, 1200000, 0, double.NaN, lv95),
                GeometryFactory.CreatePoint(2600015, 1200010, 500, double.NaN, lv95),
                GeometryFactory.CreatePoint(2600020, 1200000, 900, double.NaN, lv95));

            // NOTE: The Z value of the first point of the replacement is used, however, the envelope of the resulting pathToReshape is not updated!
            //       Hence it is crucial to insert the exact replacement end points into the geometry to reshape!

            IPolyline polyline = GeometryFactory.Clone(originalPolyline);

            var pathToReshape =
                (ISegmentCollection)((IGeometryCollection)polyline).Geometry[0];

            GeometryUtils.MakeNonZAware(replacement);

            SegmentReplacementUtils.ReplaceSegments((IPath)pathToReshape, replacement,
                                                    replacement.FromPoint, replacement.ToPoint);

            Assert.AreEqual(410, ((IPointCollection)pathToReshape).Point[1].Z);
            Assert.AreEqual(400, polyline.Envelope.ZMin,
                            "Envelope is not inconsistent any more after segment replacment!");

            // Now connect within a segment:
            IPoint firstPoint = replacement.FromPoint;

            firstPoint.X = 2600007;
            ((IPointCollection)replacement).UpdatePoint(0, firstPoint);

            polyline      = GeometryFactory.Clone(originalPolyline);
            pathToReshape = (ISegmentCollection)((IGeometryCollection)polyline).Geometry[0];

            GeometryUtils.MakeNonZAware(replacement);
            SegmentReplacementUtils.ReplaceSegments((IPath)pathToReshape, replacement,
                                                    replacement.FromPoint, replacement.ToPoint);

            Assert.AreEqual(407, ((IPointCollection)pathToReshape).Point[1].Z);
            Assert.AreEqual(400, polyline.Envelope.ZMin,
                            "Envelope is not inconsistent any more after segment replacment!");
        }
예제 #2
0
        public void LearningTest_ReplaceSegmentsWithNonIdenticalConnectPointsZs()
        {
            ISpatialReference lv95 =
                SpatialReferenceUtils.CreateSpatialReference(WellKnownHorizontalCS.LV95,
                                                             WellKnownVerticalCS.LHN95);

            IPolyline originalPolyline = GeometryFactory.CreatePolyline(
                GeometryFactory.CreatePath(
                    GeometryFactory.CreatePoint(2600000, 1200000, 400, double.NaN, lv95),
                    GeometryFactory.CreatePoint(2600010, 1200000, 405, double.NaN, lv95),
                    GeometryFactory.CreatePoint(2600020, 1200000, 410, double.NaN, lv95),
                    GeometryFactory.CreatePoint(2600030, 1200000, 420, double.NaN, lv95)));

            IPath replacement = GeometryFactory.CreatePath(
                GeometryFactory.CreatePoint(2600010, 1200000, 0, double.NaN, lv95),
                GeometryFactory.CreatePoint(2600015, 1200010, 500, double.NaN, lv95),
                GeometryFactory.CreatePoint(2600020, 1200000, 900, double.NaN, lv95));

            // NOTE: The Z value of the first point of the replacement is used, however, the envelope of the resulting pathToReshape is not updated!
            //       Hence it is crucial to insert the exact replacement end points into the geometry to reshape!

            IPolyline polyline = GeometryFactory.Clone(originalPolyline);

            var pathToReshape =
                (ISegmentCollection)((IGeometryCollection)polyline).Geometry[0];

            pathToReshape.ReplaceSegmentCollection(1, 2, (ISegmentCollection)replacement);

            // This makes no difference:
            //pathToReshape.SegmentsChanged();

            Assert.AreEqual(0, ((IPointCollection)pathToReshape).Point[1].Z);
            Assert.AreEqual(400, polyline.Envelope.ZMin,
                            "Envelope is not inconsistent any more after ArcObjects segment replacment!");

            // Make sure this does not happen in SegmentReplacementUtils
            polyline      = GeometryFactory.Clone(originalPolyline);
            pathToReshape = (ISegmentCollection)((IGeometryCollection)polyline).Geometry[0];
            SegmentReplacementUtils.ReplaceSegments((IPath)pathToReshape, replacement,
                                                    replacement.FromPoint, replacement.ToPoint);

            Assert.AreEqual(0, ((IPointCollection)pathToReshape).Point[1].Z);
            Assert.AreEqual(0, polyline.Envelope.ZMin,
                            "Envelope is inconsistent after SegmentReplacementUtils.ReplaceSegments!");
        }