示例#1
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);
        }
        async public Task <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;
            NetworkWeighInput  weight =
                input.Contains(NetworkTracerInputType.Weight) ?
                input.Collect(NetworkTracerInputType.Weight)[0] as NetworkWeighInput :
                null;

            Dijkstra dijkstra = new Dijkstra(cancelTraker);

            dijkstra.reportProgress += this.ReportProgress;
            dijkstra.MaxDistance     = _properties.Distance;
            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);

            NetworkTracerOutputCollection output = new NetworkTracerOutputCollection();

            #region Knoten/Kanten <= Distance
            Dijkstra.Nodes dijkstraNodes = dijkstra.DijkstraNodesWithMaxDistance(_properties.Distance);
            if (dijkstraNodes == null)
            {
                return(null);
            }

            List <int> edgeIds = new List <int>();
            foreach (Dijkstra.Node dijkstraNode in dijkstraNodes)
            {
                if (dijkstraNode.EId < 0)
                {
                    continue;
                }

                int index = edgeIds.BinarySearch(dijkstraNode.EId);
                if (index < 0)
                {
                    edgeIds.Insert(~index, dijkstraNode.EId);
                }

                if (Math.Abs(dijkstraNode.Dist - _properties.Distance) < double.Epsilon)
                {
                    // ToDo: Flag einfügen!!
                }
            }

            output.Add(new NetworkEdgeCollectionOutput(edgeIds));
            #endregion

            #region Knoten/Kanten > Distance
            Dijkstra.Nodes cnodes = dijkstra.DijkstraNodesDistanceGreaterThan(_properties.Distance);
            foreach (Dijkstra.Node cnode in cnodes)
            {
                Dijkstra.Node node = dijkstra.DijkstraNodes.ById(cnode.Pre);
                if (node == null)
                {
                    continue;
                }

                IGraphEdge graphEdge = gt.QueryEdge(cnode.EId);
                if (graphEdge == null)
                {
                    continue;
                }

                RowIDFilter filter = new RowIDFilter(String.Empty);
                filter.IDs.Add(graphEdge.Eid);
                IFeatureCursor cursor = await network.GetEdgeFeatures(filter);

                if (cursor == null)
                {
                    continue;
                }

                IFeature feature = await cursor.NextFeature();

                if (feature == null)
                {
                    continue;
                }

                IPath path = null;
                if (cnode.Id != graphEdge.N2 && cnode.Id == graphEdge.N1)
                {
                    ((Polyline)feature.Shape)[0].ChangeDirection();
                }

                double trimDist = _properties.Distance - node.Dist;
                string label    = _properties.Distance.ToString();
                if (weight != null)
                {
                    double w = gt.QueryEdgeWeight(weight.Weight.Guid, cnode.EId);
                    switch (weight.WeightApplying)
                    {
                    case WeightApplying.Weight:
                        trimDist *= w;
                        break;

                    case WeightApplying.ActualCosts:
                        trimDist = ((IPolyline)feature.Shape)[0].Length * trimDist * w;      // ??? Prüfen
                        break;
                    }
                    label += "\n(" + Math.Round(node.GeoDist + trimDist, 2).ToString() + ")";
                }
                path = ((IPolyline)feature.Shape)[0].Trim(trimDist);
                Polyline polyline = new Polyline();
                polyline.AddPath(path);

                output.Add(new NetworkEdgePolylineOutput(cnode.EId, polyline));

                output.Add(new NetworkFlagOutput(
                               polyline[0][polyline[0].PointCount - 1],
                               label));
            }
            #endregion

            return(output);
        }