コード例 #1
0
        private static IPolyline VerifyZOnlyDifferences(IPolyline sourcePolyline,
                                                        IPolyline targetPolyline,
                                                        int expectedResultLength,
                                                        double zTolerance = 0)
        {
            IPolyline geomOpResult = IntersectionUtils.GetZOnlyDifferenceLines(
                sourcePolyline, targetPolyline, zTolerance);

            Assert.IsNotNull(geomOpResult);
            Assert.AreEqual(expectedResultLength, Math.Round(geomOpResult.Length, 3));

            IPolyline legacyResult =
                ReshapeUtils.GetZOnlyDifferenceLegacy(sourcePolyline,
                                                      targetPolyline, zTolerance);

            Assert.IsNotNull(legacyResult);

            Assert.AreEqual(expectedResultLength, Math.Round(legacyResult.Length, 3));

            GeometryUtils.AreEqual(geomOpResult, legacyResult);

            return(geomOpResult);
        }
コード例 #2
0
        public void CanCutPolygonWithZSourcePlane()
        {
            ISpatialReference lv95 = SpatialReferenceUtils.CreateSpatialReference(
                WellKnownHorizontalCS.LV95);

            IPolygon originalPoly = GeometryFactory.CreatePolygon(
                GeometryFactory.CreateEnvelope(2600000, 1200000, 500, 100, 100, lv95));

            IPolygon innerRingPoly = GeometryFactory.CreatePolygon(
                GeometryFactory.CreateEnvelope(2600000, 1200000, 500, 10, 10, lv95));

            Plane3D plane = Plane3D.FitPlane(new List <Pnt3D>
            {
                new Pnt3D(2600000, 1200000, 500),
                new Pnt3D(2600100, 1200100, 580),
                new Pnt3D(2600000, 1200100, 550)
            });

            ((IGeometryCollection)originalPoly).AddGeometryCollection(
                (IGeometryCollection)innerRingPoly);

            GeometryUtils.Simplify(originalPoly);

            ChangeAlongZUtils.AssignZ((IPointCollection)originalPoly, plane);

            // The non-z-aware cut line cuts north of the inner ring -> the inner ring should be assigned to the southern result
            IPolyline cutLine = GeometryFactory.CreateLine(
                GeometryFactory.CreatePoint(2600000 - 100, 1200020),
                GeometryFactory.CreatePoint(2600000 - 40, 1200020),
                GeometryFactory.CreatePoint(2600000 - 40, 1200040),
                GeometryFactory.CreatePoint(2600000 + 40, 1200040),
                GeometryFactory.CreatePoint(2600000 + 40, 1200020),
                GeometryFactory.CreatePoint(2600000 + 100, 1200020));

            cutLine.SpatialReference = lv95;

            bool customIntersectOrig = IntersectionUtils.UseCustomIntersect;

            try
            {
                IntersectionUtils.UseCustomIntersect = false;

                const ChangeAlongZSource zSource = ChangeAlongZSource.SourcePlane;
                var resultsAo =
                    CutGeometryUtils.TryCut(originalPoly, cutLine, zSource);

                IntersectionUtils.UseCustomIntersect = true;
                var resultsGeom =
                    CutGeometryUtils.TryCut(originalPoly, cutLine, zSource);

                Assert.NotNull(resultsAo);
                Assert.NotNull(resultsGeom);

                EnsureCutResult(resultsAo, originalPoly, plane, 3);
                EnsureCutResult(resultsGeom, originalPoly, plane, 3);

                // NOTE: The results have different start/end points, therefore GeometryUtils.AreEqual is false
                Assert.True(GeometryUtils.AreEqualInXY(resultsAo[0], resultsGeom[0]));
                Assert.True(GeometryUtils.AreEqualInXY(resultsAo[1], resultsGeom[1]));

                Assert.AreEqual(0,
                                IntersectionUtils.GetZOnlyDifferenceLines(
                                    (IPolycurve)resultsAo[0],
                                    (IPolycurve)resultsGeom[0], 0.001)
                                .Length);

                Assert.AreEqual(0,
                                IntersectionUtils.GetZOnlyDifferenceLines(
                                    (IPolycurve)resultsAo[1],
                                    (IPolycurve)resultsGeom[1], 0.001)
                                .Length);
            }
            finally
            {
                IntersectionUtils.UseCustomIntersect = customIntersectOrig;
            }
        }