Beispiel #1
0
        public void CanCutMultipatchWithInnerRingThroughInnerRing()
        {
            ISpatialReference lv95 = SpatialReferenceUtils.CreateSpatialReference(
                WellKnownHorizontalCS.LV95);

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

            IPolygon innerRingPoly = GeometryFactory.CreatePolygon(
                GeometryFactory.CreateEnvelope(2600000, 1200000, 500, 10, 10, lv95));
            var innerRing = (IRing)((IGeometryCollection)innerRingPoly).Geometry[0];

            innerRing.ReverseOrientation();

            IMultiPatch multiPatch = GeometryFactory.CreateMultiPatch(originalPoly);

            GeometryFactory.AddRingToMultiPatch(innerRing, multiPatch,
                                                esriMultiPatchRingType
                                                .esriMultiPatchInnerRing);

            // cut line cuts through the inner ring
            IPolyline cutLine = GeometryFactory.CreateLine(
                GeometryFactory.CreatePoint(2600000 - 100, 1200000),
                GeometryFactory.CreatePoint(2600000 + 100, 1200000));

            cutLine.SpatialReference = lv95;

            IFeature mockFeature = TestUtils.CreateMockFeature(multiPatch);

            var cutter = new FeatureCutter(new[] { mockFeature });

            cutter.ZSourceProvider =
                new DatasetSpecificSettingProvider <ChangeAlongZSource>(
                    string.Empty, ChangeAlongZSource.SourcePlane);

            cutter.Cut(cutLine);

            IList <IGeometry> results = cutter.ResultGeometriesByFeature[mockFeature];

            Assert.AreEqual(2, results.Count);

            double areaSum   = 0;
            var    partCount = 0;

            foreach (IGeometry result in cutter.ResultGeometriesByFeature[mockFeature])
            {
                Assert.IsFalse(GeometryUtils.HasUndefinedZValues(result));

                areaSum +=
                    GeometryUtils.GetParts((IGeometryCollection)result)
                    .Sum(part => ((IArea)part).Area);

                partCount += GeometryUtils.GetParts((IGeometryCollection)result).Count();
            }

            Assert.AreEqual(2, partCount);

            Assert.AreEqual(((IArea)originalPoly).Area + ((IArea)innerRing).Area,
                            areaSum, 0.0001);
        }
Beispiel #2
0
        public void CanCutPolygonWithCorrectZ_Top4666()
        {
            // Tests the work-around for TOP-4666
            // TODO: Report ArcObjects bug to Esri Inc.
            IFeature polygonFeature = TestUtils.CreateMockFeature("PolygonTop4666.xml");

            var cutLine =
                (IPolyline)
                TestUtils.ReadGeometryFromXml(
                    TestUtils.GetGeometryTestDataPath("CutLineTop4666.xml"));

            GeometryUtils.EnsureSpatialReference(
                cutLine, polygonFeature.Shape.SpatialReference);

            var cutter = new FeatureCutter(new[] { polygonFeature });

            Stopwatch watch = Stopwatch.StartNew();

            cutter.Cut(cutLine);

            watch.Stop();

            Console.WriteLine("Cut large feature: {0}ms", watch.ElapsedMilliseconds);

            Assert.AreEqual(5, cutter.ResultGeometriesByFeature[polygonFeature].Count);

            foreach (IGeometry geometry in cutter.ResultGeometriesByFeature[
                         polygonFeature])
            {
                var polygon = (IPolygon)geometry;

                Assert.False(GeometryUtils.HasUndefinedZValues(polygon));

                GeometryUtils.Simplify(polygon);

                Assert.False(GeometryUtils.HasUndefinedZValues(polygon));

                foreach (IPoint point in GeometryUtils.GetPoints(
                             (IPointCollection)polygon))
                {
                    Assert.AreNotEqual(0, point.Z);
                }

                IPolyline resultAsPolyline = GeometryFactory.CreatePolyline(polygon);

                IPolyline zDifference =
                    ReshapeUtils.GetZOnlyDifference(resultAsPolyline, cutLine);

                // ArcObjects uses the cutLine's Z also at the intersection points.
                // Do the same in CustomIntersect?
                Assert.IsNull(zDifference);
            }
        }
        public static ApplyCutLinesResponse ApplyCutLines(
            [NotNull] ApplyCutLinesRequest request,
            [CanBeNull] ITrackCancel trackCancel)
        {
            IList <CutSubcurve> cutCurves = request.CutLines.Select(FromReshapeLineMsg).ToList();

            FeatureCutter cutter = CreateFeatureCutter(request, out IList <IFeature> targetFeatures);

            cutter.Cut(cutCurves);

            List <IFeature> storedFeatures = new List <IFeature>();

            var response = new ApplyCutLinesResponse();

            if (cutter.ResultGeometriesByFeature.Count > 0)
            {
                cutter.StoreResultFeatures(storedFeatures);

                cutter.LogSuccessfulCut();

                ICollection <KeyValuePair <IFeature, IList <IFeature> > > insertsByOriginal =
                    cutter.InsertedFeaturesByOriginal;

                IList <ResultObjectMsg> ResultObjectMsgs =
                    GetResultFeatureMessages(insertsByOriginal, storedFeatures);

                response.ResultFeatures.AddRange(ResultObjectMsgs);

                // Calculate the new cut lines:
                List <IFeature> newSourceFeatures = new List <IFeature>(cutter.SourceFeatures);

                newSourceFeatures.AddRange(
                    insertsByOriginal.SelectMany(kvp => kvp.Value));

                var newSubcurves =
                    CalculateCutLines(newSourceFeatures, targetFeatures,
                                      request.CalculationRequest, trackCancel,
                                      out ReshapeAlongCurveUsability usability);

                response.CutLinesUsability = (int)usability;

                response.NewCutLines.AddRange(newSubcurves.Select(ToReshapeLineMsg));

                return(response);
            }

            _msg.WarnFormat("The selection was not cut. Please select the lines to cut along");

            return(response);
        }
Beispiel #4
0
        public void CanCutMultipatch()
        {
            ISpatialReference lv95 = SpatialReferenceUtils.CreateSpatialReference(
                WellKnownHorizontalCS.LV95);

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

            IMultiPatch multiPatch = GeometryFactory.CreateMultiPatch(originalPoly);

            IPolyline cutLine = GeometryFactory.CreateLine(
                GeometryFactory.CreatePoint(2600000 - 100, 1200000),
                GeometryFactory.CreatePoint(2600000 + 100, 1200000));

            cutLine.SpatialReference = lv95;

            IFeature mockFeature = TestUtils.CreateMockFeature(multiPatch);

            var cutter = new FeatureCutter(new[] { mockFeature });

            cutter.ZSourceProvider =
                new DatasetSpecificSettingProvider <ChangeAlongZSource>(
                    string.Empty, ChangeAlongZSource.SourcePlane);

            cutter.Cut(cutLine);

            IList <IGeometry> results = cutter.ResultGeometriesByFeature[mockFeature];

            Assert.AreEqual(2, results.Count);

            double areaSum = 0;

            foreach (IGeometry result in cutter.ResultGeometriesByFeature[mockFeature])
            {
                Assert.IsFalse(GeometryUtils.HasUndefinedZValues(result));

                areaSum +=
                    GeometryUtils.GetParts((IGeometryCollection)result)
                    .Sum(part => ((IArea)part).Area);
            }

            Assert.IsTrue(MathUtils.AreEqual(((IArea)originalPoly).Area, areaSum));
        }