Esempio n. 1
0
        async public Task <IFeatureCursor> NetworkPathEdges(Dijkstra.NetworkPath networkPath)
        {
            if (_nfc == null)
            {
                return(null);
            }

            RowIDFilter filter = new RowIDFilter(String.Empty);

            foreach (Dijkstra.NetworkPathEdge edge in networkPath)
            {
                filter.IDs.Add(edge.EId);
            }

            return(await _nfc.GetEdgeFeatures(filter));
        }
Esempio n. 2
0
        public NetworkTracerOutputCollection Trace(INetworkFeatureClass network, NetworkTracerInputCollection input, gView.Framework.system.ICancelTracker cancelTraker)
        {
            if (network == null || !CanTrace(input))
            {
                return(null);
            }

            GraphTable         gt     = new GraphTable(network.GraphTableAdapter());
            NetworkSourceInput source = input.Collect(NetworkTracerInputType.SourceNode)[0] as NetworkSourceInput;
            NetworkSinkInput   sink   = input.Collect(NetworkTracerInputType.SinkNode)[0] as NetworkSinkInput;
            NetworkWeighInput  weight =
                input.Contains(NetworkTracerInputType.Weight) ?
                input.Collect(NetworkTracerInputType.Weight)[0] as NetworkWeighInput :
                null;

            Dijkstra dijkstra = new Dijkstra(cancelTraker);

            dijkstra.reportProgress += this.ReportProgress;
            if (weight != null)
            {
                dijkstra.GraphWeight    = weight.Weight;
                dijkstra.WeightApplying = weight.WeightApplying;
            }
            dijkstra.ApplySwitchState = input.Contains(NetworkTracerInputType.IgnoreSwitches) == false &&
                                        network.HasDisabledSwitches;
            Dijkstra.ApplyInputIds(dijkstra, input);

            dijkstra.Calculate(gt, source.NodeId, sink.NodeId);
            Dijkstra.NetworkPath networkPath = dijkstra.DijkstraPath(sink.NodeId);
            if (networkPath == null)
            {
                return(null);
            }

            NetworkTracerOutputCollection output = new NetworkTracerOutputCollection();

            NetworkPathOutput pathOutput = new NetworkPathOutput();

            foreach (Dijkstra.NetworkPathEdge pathEdge in networkPath)
            {
                pathOutput.Add(new NetworkEdgeOutput(pathEdge.EId));
            }

            output.Add(pathOutput);

            if (input.Collect(NetworkTracerInputType.AppendNodeFlags).Count > 0)
            {
                Dijkstra.Nodes pathNodes = dijkstra.DijkstraPathNodes(sink.NodeId);
                Helper.AppendNodeFlags(network, gt, Helper.NodeIds(pathNodes), output);
            }
            //if (pathNodes != null)
            //{
            //    foreach (Dijkstra.Node node in pathNodes)
            //    {
            //        string label = node.Dist.ToString();
            //        if (weight != null)
            //        {
            //            label += "\n(" + (Math.Round(node.GeoDist, 2)).ToString() + ")";
            //        }
            //        output.Add(new NetworkNodeFlagOuput(node.Id));
            //    }
            //}

            return(output);
        }
Esempio n. 3
0
        async public Task <NetworkTracerOutputCollection> Trace(INetworkFeatureClass network, NetworkTracerInputCollection input, ICancelTracker cancelTraker)
        {
            if (network == null || !CanTrace(input))
            {
                return(null);
            }

            GraphTable             gt         = new GraphTable(network.GraphTableAdapter());
            NetworkSourceInput     sourceNode = null;
            NetworkSourceEdgeInput sourceEdge = null;

            if (input.Collect(NetworkTracerInputType.SourceNode).Count == 1)
            {
                sourceNode = input.Collect(NetworkTracerInputType.SourceNode)[0] as NetworkSourceInput;
            }
            else if (input.Collect(NetworkTracerInputType.SoruceEdge).Count == 1)
            {
                sourceEdge = input.Collect(NetworkTracerInputType.SoruceEdge)[0] as NetworkSourceEdgeInput;
            }
            else
            {
                return(null);
            }

            input.Collect(NetworkTracerInputType.BarrierNodes);

            NetworkTracerOutputCollection outputCollection = new NetworkTracerOutputCollection();
            List <int>        edgeIds    = new List <int>();
            NetworkPathOutput pathOutput = new NetworkPathOutput();

            List <int> neighborNodeFcIds         = new List <int>();
            Dictionary <int, string> neighborFcs = new Dictionary <int, string>();

            foreach (var networkClass in await network.NetworkClasses())
            {
                if (networkClass.GeometryType != geometryType.Point)
                {
                    continue;
                }

                int fcid = await network.NetworkClassId(networkClass.Name);

                neighborNodeFcIds.Add(fcid);
                neighborFcs.Add(fcid, networkClass.Name);
            }

            Dijkstra dijkstra = new Dijkstra(cancelTraker);

            dijkstra.reportProgress  += this.ReportProgress;
            dijkstra.ApplySwitchState = input.Contains(NetworkTracerInputType.IgnoreSwitches) == false &&
                                        network.HasDisabledSwitches;
            dijkstra.TargetNodeFcIds = neighborNodeFcIds;
            dijkstra.TargetNodeType  = TargetNodeType;
            Dijkstra.ApplyInputIds(dijkstra, input);

            Dijkstra.Nodes dijkstraEndNodes = null;
            if (sourceNode != null)
            {
                dijkstra.Calculate(gt, sourceNode.NodeId);

                dijkstraEndNodes = dijkstra.DijkstraEndNodes;
            }
            else if (sourceEdge != null)
            {
                IGraphEdge graphEdge = gt.QueryEdge(sourceEdge.EdgeId);
                if (graphEdge == null)
                {
                    return(null);
                }

                bool n1_2_n2 = gt.QueryN1ToN2(graphEdge.N1, graphEdge.N2) != null;
                bool n2_2_n1 = gt.QueryN1ToN2(graphEdge.N2, graphEdge.N1) != null;
                if (n1_2_n2 == false &&
                    n2_2_n1 == false)
                {
                    return(null);
                }

                bool n1switchState = dijkstra.ApplySwitchState ? gt.SwitchState(graphEdge.N1) : true;
                bool n2switchState = dijkstra.ApplySwitchState ? gt.SwitchState(graphEdge.N2) : true;

                bool n1isNeighbor = neighborNodeFcIds.Contains(gt.GetNodeFcid(graphEdge.N1));
                bool n2isNeighbor = neighborNodeFcIds.Contains(gt.GetNodeFcid(graphEdge.N2));

                if (n1isNeighbor && n2isNeighbor)
                {
                    dijkstraEndNodes = new Dijkstra.Nodes();
                    dijkstraEndNodes.Add(new Dijkstra.Node(graphEdge.N1));
                    dijkstraEndNodes.Add(new Dijkstra.Node(graphEdge.N2));
                    dijkstraEndNodes[0].EId = graphEdge.Eid;

                    edgeIds.Add(graphEdge.Eid);
                    pathOutput.Add(new NetworkEdgeOutput(graphEdge.Eid));
                }
                else
                {
                    if (!n1isNeighbor && n1switchState == true)
                    {
                        dijkstra.Calculate(gt, graphEdge.N1);
                        dijkstraEndNodes = dijkstra.DijkstraEndNodes;

                        if (!n1_2_n2 && n2isNeighbor)
                        {
                            Dijkstra.Node n1Node = new Dijkstra.Node(graphEdge.N2);
                            n1Node.EId = graphEdge.Eid;
                            dijkstraEndNodes.Add(n1Node);

                            edgeIds.Add(graphEdge.Eid);
                            pathOutput.Add(new NetworkEdgeOutput(graphEdge.Eid));
                        }
                    }
                    else if (!n2isNeighbor && n2switchState == true)
                    {
                        dijkstra.Calculate(gt, graphEdge.N2);
                        dijkstraEndNodes = dijkstra.DijkstraEndNodes;

                        if (!n2_2_n1 && n1isNeighbor)
                        {
                            Dijkstra.Node n1Node = new Dijkstra.Node(graphEdge.N1);
                            n1Node.EId = graphEdge.Eid;
                            dijkstraEndNodes.Add(n1Node);

                            edgeIds.Add(graphEdge.Eid);
                            pathOutput.Add(new NetworkEdgeOutput(graphEdge.Eid));
                        }
                    }
                }
            }

            #region Create Output
            if (dijkstraEndNodes == null)
            {
                return(null);
            }

            ProgressReport report = (ReportProgress != null ? new ProgressReport() : null);

            #region Collect End Nodes
            if (report != null)
            {
                report.Message    = "Collect End Nodes...";
                report.featurePos = 0;
                report.featureMax = dijkstraEndNodes.Count;
                ReportProgress(report);
            }

            int counter = 0;
            foreach (Dijkstra.Node endNode in dijkstraEndNodes)
            {
                int fcId = gt.GetNodeFcid(endNode.Id);
                if (neighborNodeFcIds.Contains(fcId) && gt.GetNodeType(endNode.Id) == this.TargetNodeType)
                {
                    IFeature nodeFeature = await network.GetNodeFeature(endNode.Id);

                    if (nodeFeature != null && nodeFeature.Shape is IPoint)
                    {
                        string fcName = neighborFcs.ContainsKey(fcId) ?
                                        neighborFcs[fcId] : String.Empty;

                        //outputCollection.Add(new NetworkNodeFlagOuput(endNode.Id, nodeFeature.Shape as IPoint));

                        outputCollection.Add(new NetworkFlagOutput(nodeFeature.Shape as IPoint,
                                                                   new NetworkFlagOutput.NodeFeatureData(endNode.Id, fcId, Convert.ToInt32(nodeFeature["OID"]), fcName)));
                    }
                }
                counter++;
                if (report != null && counter % 1000 == 0)
                {
                    report.featurePos = counter;
                    ReportProgress(report);
                }
            }
            #endregion

            #region Collect EdgedIds
            if (report != null)
            {
                report.Message    = "Collect Edges...";
                report.featurePos = 0;
                report.featureMax = dijkstra.DijkstraNodes.Count;
                ReportProgress(report);
            }

            counter = 0;
            foreach (Dijkstra.Node dijkstraEndNode in dijkstraEndNodes)
            {
                Dijkstra.NetworkPath networkPath = dijkstra.DijkstraPath(dijkstraEndNode.Id);
                if (networkPath == null)
                {
                    continue;
                }

                foreach (Dijkstra.NetworkPathEdge pathEdge in networkPath)
                {
                    int index = edgeIds.BinarySearch(pathEdge.EId);
                    if (index >= 0)
                    {
                        continue;
                    }
                    edgeIds.Insert(~index, pathEdge.EId);

                    pathOutput.Add(new NetworkEdgeOutput(pathEdge.EId));
                    counter++;
                    if (report != null && counter % 1000 == 0)
                    {
                        report.featurePos = counter;
                        ReportProgress(report);
                    }
                }
            }
            if (pathOutput.Count > 0)
            {
                outputCollection.Add(pathOutput);
            }
            #endregion
            #endregion

            return(outputCollection);
        }