public override void Stop(SnapResult snapResult)
        {
            var networkLocation = (INetworkLocation)SourceFeature;

            if (null == networkLocation)
            {
                return;
            }

            var branch = snapResult.SnappedFeature as IBranch;

            if (null == branch)
            {
                return;
            }

            var network = Network ?? branch.Network; // network must e known

            if (network == null)
            {
                return;
            }

            if (networkLocation.Branch != branch)
            {
                networkLocation.Branch = branch;
            }
            // todo move update distance to AddBranchFeatureToNearestBranch?
            var distanceInGeometryLength    = GeometryHelper.Distance((ILineString)networkLocation.Branch.Geometry, TargetFeature.Geometry.Coordinates[0]);
            var distanceInCalculationLength = NetworkHelper.CalculationChainage(branch, distanceInGeometryLength);

            networkLocation.Chainage = BranchFeature.SnapChainage(networkLocation.Branch.Length, distanceInCalculationLength);
        }
Beispiel #2
0
        public void Stop(SnapResult snapResult, bool stayOnSameBranch)
        {
            if (!(SourceFeature is IBranchFeature))
            {
                return;
            }
            if (null != snapResult && null == snapResult.SnappedFeature as IBranch)
            {
                return;
            }

            var branchFeature = (IBranchFeature)SourceFeature;

            if (moving)
            {
                branchFeature.SetBeingMoved(true);
            }

            var tolerance = Layer == null ? Tolerance : MapHelper.ImageToWorld(Layer.Map, 1);

            var      branch  = branchFeature.Branch;
            INetwork network = Network ?? branch.Network; // network must be known

            if (!stayOnSameBranch && branch != null)
            {
                branch.BranchFeatures.Remove(branchFeature);
                branchFeature.Branch = null;
            }

            base.Stop(); // set new geometry

            if (!stayOnSameBranch)
            {
                NetworkHelper.AddBranchFeatureToNearestBranch(network.Branches, branchFeature, tolerance);
            }

            if (moving)
            {
                branchFeature.SetBeingMoved(false);
                moving = false;
            }

            // todo move update distance to AddBranchFeatureToNearestBranch?
            double distance = GeometryHelper.Distance((ILineString)branchFeature.Branch.Geometry, branchFeature.Geometry.Coordinates[0]);

            if (branchFeature.Branch.IsLengthCustom)
            {
                distance *= branchFeature.Branch.Length / branchFeature.Branch.Geometry.Length;
            }
            branchFeature.Chainage = BranchFeature.SnapChainage(branchFeature.Branch.Length, distance);
            if (branchFeature.Geometry.GetType() == typeof(LineString))
            {
                UpdateLineGeometry(branchFeature);
            }
        }
Beispiel #3
0
        private void UpdateBranchFeatureGeometry(IGeometry target, ILineString newLineString, double newFraction, IBranch branch, IBranchFeature branchFeature)
        {
            var newOffset = !branch.IsLengthCustom
                                ? BranchFeature.SnapChainage(newLineString.Length, newLineString.Length * newFraction)
                                : BranchFeature.SnapChainage(newLineString.Length, branchFeature.Chainage * newLineString.Length / branch.Length);

            if (!branch.IsLengthCustom)
            {
                branchFeature.Chainage = newOffset;
            }

            branchFeature.Geometry = GeometryHelper.SetCoordinate(target, 0, GeometryHelper.LineStringCoordinate(newLineString, newOffset));
        }
        public void SnapChainageTest()
        {
            const double epsilon = 1.0e-7;

            Assert.AreEqual(epsilon, BranchFeature.Epsilon, 1.0e-8);

            const double length = 100.0;

            // Values near 0.0
            const double smallCorrectableNegativeOffset    = -1.0e-8;
            const double smallNotCorrectableNegativeOffset = -1.0e-6;

            Assert.AreEqual(0.0, BranchFeature.SnapChainage(length, smallCorrectableNegativeOffset));
            Assert.AreEqual(0.0, BranchFeature.SnapChainage(length, smallNotCorrectableNegativeOffset));

            const double smallCorrectablePositiveOffset    = 1.0e-8;
            const double smallNotCorrectablePositiveOffset = 1.0e-6;

            Assert.AreEqual(0.0, BranchFeature.SnapChainage(length, smallCorrectablePositiveOffset));
            Assert.AreNotEqual(0.0, BranchFeature.SnapChainage(length, smallNotCorrectablePositiveOffset));

            // Values near 100.0
            const double correctableOffsetSmallerThanLength    = 100.0 - 1.0e-8;
            const double notCorrectableOffsetSmallerThanLength = 100.0 - 1.0e-6;

            Assert.AreEqual(100.0, BranchFeature.SnapChainage(length, correctableOffsetSmallerThanLength));
            Assert.AreNotEqual(100.0, BranchFeature.SnapChainage(length, notCorrectableOffsetSmallerThanLength));

            const double correctableOffsetLargerThanLength    = 100.0 + 1.0e-8;
            const double notCorrectableOffsetLargerThanLength = 100.0 + 1.0e-6;

            Assert.AreEqual(100.0, BranchFeature.SnapChainage(length, correctableOffsetLargerThanLength));
            Assert.AreEqual(100.0, BranchFeature.SnapChainage(length, notCorrectableOffsetLargerThanLength));

            // other case, should return input offset
            const double offsetValue1 = 50.0 + 1.0e-8;
            const double offsetValue2 = 50.0 + 1.0e-6;

            Assert.AreEqual(offsetValue1, BranchFeature.SnapChainage(length, offsetValue1));
            Assert.AreEqual(offsetValue2, BranchFeature.SnapChainage(length, offsetValue2));
        }