예제 #1
0
        /// <summary>
        /// Tries to split a branch at the given chainage. It will not create empty branches ( split at chainage 0 or chainage is length branch)
        /// All branch features are updated
        /// Chainage is interpreted as chainage in geometry, even if IsLengthCustom is true for branch
        /// </summary>
        /// <param name="branch"></param>
        /// <param name="geometryOffset">Local (or geometry-based) chainage</param>
        public static SplitResult SplitBranchAtNode(IBranch branch, double geometryOffset)
        {
            bool startedEdit = false;
            BranchSplitAction branchSplitAction = null;

            //start editaction if not editing

            if (geometryOffset == 0.0)
            {
                return(null); //no split required
            }
            if (geometryOffset == branch.Geometry.Length)
            {
                return(null); //no split required
            }
            if (!branch.Network.IsEditing)
            {
                startedEdit       = true;
                branchSplitAction = new BranchSplitAction();
                branch.Network.BeginEdit(branchSplitAction);
            }

            var lengthIndexedLine = new LengthIndexedLine(branch.Geometry);
            var splitLocation     = lengthIndexedLine.ExtractPoint(geometryOffset);

            var node = (INode)Activator.CreateInstance(branch.Source.GetType());

            node.Name     = GetUniqueName("Node{0:D3}", branch.Network.Nodes, "Node");
            node.Geometry =
                new Point(new Coordinate(splitLocation.X, splitLocation.Y,
                                         Double.IsNaN(splitLocation.Z) ? 0.0 : splitLocation.Z));

            var         newBranch = SplitBranchAtNode(branch.Network, branch, node);
            SplitResult result    = null;

            if (null != newBranch)
            {
                branch.Network.Nodes.Add(node);
                result = new SplitResult
                {
                    NewNode   = node,
                    NewBranch = newBranch
                };
            }

            if (startedEdit)
            {
                branchSplitAction.SplittedBranch = branch;
                if (result != null)
                {
                    branchSplitAction.NewBranch = result.NewBranch;
                }
                branch.Network.EndEdit();
            }

            return(result);
        }
예제 #2
0
        private void HandleBranchSplit(BranchSplitAction currentEditAction)
        {
            var coverageHasLocationsForSplitBranch =
                Locations.Values.Any(l => l.Branch == currentEditAction.SplittedBranch);

            //nothing to DO..leave it at default
            if (coverageHasLocationsForSplitBranch)
            {
                UpdateValuesForBranchSplit(currentEditAction);
            }

            //reinitialize
            segmentsInitialized = false;
            initialized         = false;
            StoreBranchLengths();
        }
예제 #3
0
        /// <summary>
        /// This method can be override for custom logic in moving values / locations
        /// </summary>
        /// <param name="currentEditAction"></param>
        protected virtual void UpdateValuesForBranchSplit(BranchSplitAction currentEditAction)
        {
            double splitAtOffset = currentEditAction.SplittedBranch.Length;
            var    splitLocation = new NetworkLocation(currentEditAction.SplittedBranch, splitAtOffset);
            var    value         = Evaluate(splitLocation);

            IEnumerable <INetworkLocation> networkLocationsToMove =
                Locations.Values.Where(
                    nl => nl.Branch == currentEditAction.SplittedBranch && nl.Offset >= splitAtOffset)
                .ToList();

            foreach (var location in networkLocationsToMove)
            {
                location.Branch = currentEditAction.NewBranch;
                location.Offset = location.Offset - splitAtOffset;
            }

            //add a point at the end of the orignal branch
            var startLocation = new NetworkLocation(currentEditAction.NewBranch, 0);

            this[splitLocation] = value;
            this[startLocation] = value;
        }