private static IEnumerable <Linestring> GetLineStrings([NotNull] IGeometry shape)
        {
            if (shape.GeometryType == esriGeometryType.esriGeometryMultiPatch)
            {
                var segments = QaGeometryUtils.GetSegments((IMultiPatch)shape);

                yield return(GetLineString(segments));
            }
            else if (shape.GeometryType == esriGeometryType.esriGeometryPolygon ||
                     shape.GeometryType == esriGeometryType.esriGeometryPolyline)
            {
                foreach (var path in GetLinearizedPaths(shape))
                {
                    yield return(GeometryConversionUtils.GetLinestring(path));
                }
            }
            else
            {
                throw new ArgumentException(
                          $@"Unexpected geometry type: {shape.GeometryType}",
                          nameof(shape));
            }
        }
Exemple #2
0
        public void CanCutAlongUsingZSources()
        {
            GetOverlappingPolygons(out GdbFeature sourceFeature, out GdbFeature targetFeature);

            GeometryUtils.MakeZAware(sourceFeature.Shape);
            GeometryUtils.MakeZAware(targetFeature.Shape);

            var   normal     = new Vector(new[] { 0.5, 0.5, 2 });
            Pnt3D planePoint = new Pnt3D(2600000, 1200000, 600);

            Plane3D sourcePlane = new Plane3D(normal, planePoint);

            ChangeAlongZUtils.AssignZ((IPointCollection)sourceFeature.Shape, sourcePlane);

            GeometryUtils.ApplyConstantZ(targetFeature.Shape, 500);

            CalculateCutLinesRequest calculationRequest =
                CreateCalculateCutLinesRequest(sourceFeature, targetFeature);

            CalculateCutLinesResponse calculateResponse =
                ChangeAlongServiceUtils.CalculateCutLines(calculationRequest, null);

            Assert.AreEqual(ReshapeAlongCurveUsability.CanReshape,
                            (ReshapeAlongCurveUsability)calculateResponse.ReshapeLinesUsability);

            AssertReshapeLineCount(calculateResponse.CutLines, 1, 1);

            IPolyline reshapeLine =
                (IPolyline)ProtobufGeometryUtils.FromShapeMsg(calculateResponse.CutLines[0].Path);

            Assert.NotNull(reshapeLine);
            Assert.AreEqual(1000, (reshapeLine).Length);

            Linestring cutLinestring =
                GeometryConversionUtils.GetLinestring(GeometryUtils.GetPaths(reshapeLine).Single());

            Pnt3D midPoint = (Pnt3D)cutLinestring.GetPointAlong(0.5, true);

            List <Pnt3D> points = GeometryConversionUtils.GetPntList(reshapeLine);

            Assert.IsTrue(points.All(p => MathUtils.AreEqual(p.Z, 500.0)));

            //
            // Cutting - TargetZ
            //
            var applyRequest = new ApplyCutLinesRequest();

            applyRequest.CutLines.Add(calculateResponse.CutLines[0]);
            applyRequest.CalculationRequest     = calculationRequest;
            applyRequest.InsertVerticesInTarget = false;
            applyRequest.ChangedVerticesZSource = (int)ChangeAlongZSource.Target;

            ApplyCutLinesResponse applyResponse =
                ChangeAlongServiceUtils.ApplyCutLines(applyRequest, null);

            Assert.AreEqual(2, applyResponse.ResultFeatures.Count);

            List <IGeometry> cutGeometries =
                applyResponse.ResultFeatures.Select(GetShape).ToList();

            Assert.AreEqual(1000 * 1000, cutGeometries.Sum(g => ((IArea)g).Area));

            List <MultiPolycurve> multiPolycurves =
                cutGeometries
                .Select(g => GeometryConversionUtils.CreateMultiPolycurve((IPolycurve)g))
                .ToList();

            foreach (MultiPolycurve multiPolycurve in multiPolycurves)
            {
                Line3D segment = multiPolycurve.FindSegments(midPoint, 0.001).First().Value;
                Assert.AreEqual(500, segment.StartPoint.Z);
                Assert.AreEqual(500, segment.EndPoint.Z);
            }

            //
            // Cutting - Interpolate
            //
            applyRequest = new ApplyCutLinesRequest();

            applyRequest.CutLines.Add(calculateResponse.CutLines[0]);
            applyRequest.CalculationRequest     = calculationRequest;
            applyRequest.InsertVerticesInTarget = false;
            applyRequest.ChangedVerticesZSource = (int)ChangeAlongZSource.InterpolatedSource;

            applyResponse = ChangeAlongServiceUtils.ApplyCutLines(applyRequest, null);

            Assert.AreEqual(2, applyResponse.ResultFeatures.Count);

            cutGeometries = applyResponse.ResultFeatures.Select(GetShape).ToList();

            Assert.AreEqual(1000 * 1000, cutGeometries.Sum(g => ((IArea)g).Area));

            multiPolycurves =
                cutGeometries
                .Select(g => GeometryConversionUtils.CreateMultiPolycurve((IPolycurve)g))
                .ToList();

            foreach (MultiPolycurve multiPolycurve in multiPolycurves)
            {
                List <Line3D> segments
                    = multiPolycurve.FindSegments(midPoint, 0.001)
                      .Select(kvp => kvp.Value).ToList();

                Assert.AreEqual(2, segments.Count);

                // Check if they are properly ordered and same length
                Assert.AreEqual(segments[0].EndPoint, segments[1].StartPoint);
                Assert.AreEqual(segments[0].Length2D, segments[1].Length2D);

                // Check if they are interpolated
                double average = (segments[0].StartPoint.Z + segments[1].EndPoint.Z) / 2;

                Assert.AreEqual(average, segments[0].EndPoint.Z);
            }

            //
            // Cutting - Plane
            //
            applyRequest = new ApplyCutLinesRequest();

            applyRequest.CutLines.Add(calculateResponse.CutLines[0]);
            applyRequest.CalculationRequest     = calculationRequest;
            applyRequest.InsertVerticesInTarget = false;
            applyRequest.ChangedVerticesZSource = (int)ChangeAlongZSource.SourcePlane;

            applyResponse = ChangeAlongServiceUtils.ApplyCutLines(applyRequest, null);

            Assert.AreEqual(2, applyResponse.ResultFeatures.Count);

            cutGeometries = applyResponse.ResultFeatures.Select(GetShape).ToList();

            Assert.AreEqual(1000 * 1000, cutGeometries.Sum(g => ((IArea)g).Area));

            multiPolycurves =
                cutGeometries
                .Select(g => GeometryConversionUtils.CreateMultiPolycurve((IPolycurve)g))
                .ToList();

            foreach (MultiPolycurve multiPolycurve in multiPolycurves)
            {
                bool?coplanar = ChangeAlongZUtils.AreCoplanar(
                    multiPolycurve.GetPoints().ToList(), sourcePlane,
                    0.01, out double _, out string _);

                Assert.IsTrue(coplanar);
            }
        }