예제 #1
0
        public void CanReshapeAlongMinimalTolerance()
        {
            GetOverlappingPolygons(out GdbFeature sourceFeature, out GdbFeature targetFeature);

            // Insert an extra point:
            IPoint targetAlmostIntersectPoint = GeometryFactory.CreatePoint(
                2601000.001, 1200500.0, sourceFeature.Shape.SpatialReference);

            bool pointInserted = ReshapeUtils.EnsurePointsExistInTarget(
                targetFeature.Shape,
                new[] { targetAlmostIntersectPoint }, 0.001);

            Assert.IsTrue(pointInserted);
            Assert.AreEqual(6, GeometryUtils.GetPointCount(targetFeature.Shape));

            CalculateReshapeLinesRequest calculationRequest =
                CreateCalculateReshapeLinesRequest(sourceFeature, targetFeature);

            CalculateReshapeLinesResponse calculateResponse =
                ChangeAlongServiceUtils.CalculateReshapeLines(calculationRequest, null);

            Assert.AreEqual((int)ReshapeAlongCurveUsability.CanReshape,
                            calculateResponse.ReshapeLinesUsability);
            AssertReshapeLineCount(calculateResponse.ReshapeLines, 2, 2);

            int insideLineIndex =
                GetInsideReshapeLineIndex(calculateResponse.ReshapeLines, sourceFeature.Shape);

            IPolyline insideLine =
                (IPolyline)ProtobufGeometryUtils.FromShapeMsg(
                    calculateResponse.ReshapeLines[insideLineIndex].Path);

            Assert.NotNull(insideLine);
            Assert.AreNotEqual(1000.0, (insideLine).Length);

            // NOTE: If IntersectionUtils.UseCustomIntersect = true the from point is exactly on the inserted point
            //       Otherwise it's somewhere between - so we cannot do the exact comparison
            Assert.AreNotEqual(insideLine.FromPoint.X, 2601000.0);
            Assert.AreNotEqual(insideLine.ToPoint.X, 2601000.0);

            //
            // Reshape the default side:
            ApplyReshapeLinesRequest applyRequest = new ApplyReshapeLinesRequest();

            applyRequest.ReshapeLines.Add(calculateResponse.ReshapeLines[insideLineIndex]);
            applyRequest.CalculationRequest       = calculationRequest;
            applyRequest.InsertVerticesInTarget   = false;
            applyRequest.UseNonDefaultReshapeSide = false;

            ApplyReshapeLinesResponse applyResponse =
                ChangeAlongServiceUtils.ApplyReshapeLines(applyRequest, null);

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

            GdbObjectMsg updatedFeatureMsg = applyResponse.ResultFeatures[0].Update;
            IGeometry    updatedGeometry   = ProtobufGeometryUtils.FromShapeMsg(updatedFeatureMsg.Shape);

            Assert.IsNotNull(updatedGeometry);
            Assert.Greater(((IArea)updatedGeometry).Area, 1000.0 * 1000.0 * 3 / 4);

            // Check the new reshape line:
            AssertReshapeLineCount(applyResponse.NewReshapeLines, 1, 1);

            Assert.AreEqual((int)ReshapeAlongCurveUsability.CanReshape,
                            applyResponse.ReshapeLinesUsability);

            //
            //
            // The same using the minimum tolerance:
            //
            calculationRequest.Tolerance = 0;

            calculateResponse =
                ChangeAlongServiceUtils.CalculateReshapeLines(calculationRequest, null);

            Assert.AreEqual((int)ReshapeAlongCurveUsability.CanReshape,
                            calculateResponse.ReshapeLinesUsability);
            AssertReshapeLineCount(calculateResponse.ReshapeLines, 2, 2);

            insideLineIndex =
                GetInsideReshapeLineIndex(calculateResponse.ReshapeLines, sourceFeature.Shape);

            insideLine =
                (IPolyline)ProtobufGeometryUtils.FromShapeMsg(
                    calculateResponse.ReshapeLines[insideLineIndex].Path);

            Assert.NotNull(insideLine);
            Assert.AreEqual(1000.0, insideLine.Length, 0.000000001);

            // NOTE: If IntersectionUtils.UseCustomIntersect = true the from point is exactly on the inserted point
            //       Otherwise it's somewhere between - so we cannot do the exact comparison
            Assert.AreEqual(2601000.0, insideLine.FromPoint.X);
            Assert.AreEqual(1200500.0, insideLine.FromPoint.Y);

            //
            // Apply with minimum tolerance:
            applyRequest = new ApplyReshapeLinesRequest();

            applyRequest.ReshapeLines.Add(calculateResponse.ReshapeLines[insideLineIndex]);
            applyRequest.CalculationRequest       = calculationRequest;
            applyRequest.InsertVerticesInTarget   = false;
            applyRequest.UseNonDefaultReshapeSide = false;

            applyResponse =
                ChangeAlongServiceUtils.ApplyReshapeLines(applyRequest, null);

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

            updatedFeatureMsg = applyResponse.ResultFeatures[0].Update;

            updatedGeometry = ProtobufGeometryUtils.FromShapeMsg(updatedFeatureMsg.Shape);

            Assert.IsNotNull(updatedGeometry);
            Assert.AreEqual(1000 * 1000 * 3 / 4, ((IArea)updatedGeometry).Area);

            // Check the new remaining reshape line (outside)
            AssertReshapeLineCount(applyResponse.NewReshapeLines, 1, 1);
            Assert.AreEqual((int)ReshapeAlongCurveUsability.CanReshape,
                            applyResponse.ReshapeLinesUsability);

            IPolyline outsideLine = (IPolyline)ProtobufGeometryUtils.FromShapeMsg(
                applyResponse.NewReshapeLines[0].Path);

            Assert.NotNull(outsideLine);
            Assert.AreEqual(3000.0, outsideLine.Length, 0.000000001);

            // NOTE: If IntersectionUtils.UseCustomIntersect = true the from point is exactly on the inserted point
            //       Otherwise it's somewhere between - so we cannot do the exact comparison
            Assert.AreEqual(2601000.0, outsideLine.ToPoint.X);
            Assert.AreEqual(1200500.0, outsideLine.ToPoint.Y);
        }