示例#1
0
        /// <summary>
        /// 进行最短路径分析。
        /// Optimal path analysis
        /// </summary>
        /// <returns></returns>
        public bool Analyst()
        {
            try
            {
                m_count = 0;
                TransportationAnalystParameter parameter = new TransportationAnalystParameter();

                // 设置障碍点及障碍边
                // Set barrier nodes and edges
                int[] barrierEdges = new int[m_barrierEdges.Count];
                for (int i = 0; i < barrierEdges.Length; i++)
                {
                    barrierEdges[i] = m_barrierEdges[i];
                }
                parameter.BarrierEdges = barrierEdges;

                int[] barrierNodes = new int[m_barrierNodes.Count];
                for (int i = 0; i < barrierNodes.Length; i++)
                {
                    barrierNodes[i] = m_barrierNodes[i];
                }
                parameter.BarrierNodes = barrierNodes;
                parameter.WeightName   = "length";

                // 设置最佳路径分析的返回对象
                // Set the return object of the optimal path analysis
                parameter.Points             = m_Points;
                parameter.IsNodesReturn      = true;
                parameter.IsEdgesReturn      = true;
                parameter.IsPathGuidesReturn = true;
                parameter.IsRoutesReturn     = true;

                // 进行分析并显示结果
                // Analyze
                m_result = m_analyst.FindPath(parameter, false);
                if (m_result == null)
                {
                    if (SuperMap.Data.Environment.CurrentCulture != "zh-CN")
                    {
                        MessageBox.Show("Failed");
                    }
                    else
                    {
                        MessageBox.Show("分析失败");
                    }
                    return(false);
                }
                ShowResult();
                FillDataGridView(0);
                m_selectMode = SelectMode.None;
                return(true);
            }
            catch (Exception e)
            {
                Trace.WriteLine(e.Message);
                return(false);
            }
        }
        /// <summary>
        /// 进行网络分析分析
        /// </summary>
        public void BeginNetworkAnalyst()
        {
            try
            {
                mAnalystResult = mAnalyst.FindTSPPath(mAnalystParameter, false);
                if (mAnalystResult != null)
                {
                    int[][] EdgeId = new int[mAnalystResult.Edges.Length][];
                    //拿到交错数组中第一行元素ID
                    int[] IDedge = new int[mAnalystResult.Edges[0].Length];
                    for (int i = 0; i < IDedge.Length; i++)
                    {
                        IDedge[i] = mAnalystResult.Edges[0][i];
                    }
                    //拿到弧段ID后查询路名
                    string[]  RodeName  = new string[IDedge.Length];
                    Recordset recordset = null;
                    for (int i = 0; i < IDedge.Length; i++)
                    {
                        recordset         = mRodeNetWork.Query("SmID =" + IDedge[i], CursorType.Static);
                        RodeName[i]       = recordset.GetFieldValue("RodeName").ToString().Trim();
                        mRodeTotalLength += Convert.ToInt32(recordset.GetFieldValue("SmLength"));
                    }
                    //编辑路名显示形式
                    string mStartRode = "起点→";
                    string mNewRode   = null;
                    for (int i = 0; i < RodeName.Length; i++)
                    {
                        if (i == 0)
                        {
                            mNewRode = mStartRode.Insert(mStartRode.Length, RodeName[i] + "→");
                        }
                        else
                        {
                            mNewRode = mNewRode.Insert(mNewRode.Length, RodeName[i] + "→");
                        }
                    }
                    mTextBoxRodeName = mNewRode + "终点";
                }
                GeoLine line = mAnalystResult.Routes[0].ConvertToLine();
                if (mLine3D == null)
                {
                    mLine3D = new GeoLine3D();
                }

                for (Int32 i = 0; i < line.PartCount; i++)
                {
                    mLine3D.AddPart(line[i].ToPoint3Ds());
                }
                mLine3D[0].Insert(0, new Point3D(mStartPoint.X, mStartPoint.Y, 0));
                mLine3D[0].Add(new Point3D(mEndPoint.X, mEndPoint.Y, 0));
                DisplayFlyRoute();
            }
            catch (Exception ex)
            {
                Trace.WriteLine(ex.Message);
            }
        }
示例#3
0
        /// <summary>
        /// 开始分析。
        /// Analyze
        /// </summary>
        public void StartAnalyst()
        {
            try
            {
                int index = m_trackingLayer.IndexOf("route");
                if (index != -1)
                {
                    m_trackingLayer.Remove(index);
                }
                m_mapControl.Map.Refresh();

                TransportationAnalystParameter parameter = new TransportationAnalystParameter();
                // 设置设施点
                // Set facilities
                int[] facilityNodes = new int[m_nodesList.Count];
                for (int i = 0; i < facilityNodes.Length; i++)
                {
                    facilityNodes[i] = m_nodesList[i];
                }
                parameter.Nodes              = facilityNodes;
                parameter.WeightName         = "length";
                parameter.IsEdgesReturn      = true;
                parameter.IsNodesReturn      = true;
                parameter.IsRoutesReturn     = true;
                parameter.IsPathGuidesReturn = true;

                // 设置障碍点及障碍边
                // Set barrier nodes and edges
                int[] barrierEdges = new int[m_barrierEdges.Count];
                for (int i = 0; i < barrierEdges.Length; i++)
                {
                    barrierEdges[i] = m_barrierEdges[i];
                }
                parameter.BarrierEdges = barrierEdges;

                int[] barrierNodes = new int[m_barrierNodes.Count];
                for (int i = 0; i < barrierNodes.Length; i++)
                {
                    barrierNodes[i] = m_barrierNodes[i];
                }
                parameter.BarrierNodes = barrierNodes;

                // 进行分析,这里设置查找设施点的数量为1
                // The facility number here is 1
                m_analystResult = m_analyst.FindClosestFacility(parameter,
                                                                m_eventNode, 1, true, 0);
                if (m_analystResult == null)
                {
                    if (SuperMap.Data.Environment.CurrentCulture != "zh-CN")
                    {
                        MessageBox.Show("Failed");
                    }
                    else
                    {
                        MessageBox.Show("分析失败");
                    }
                    return;
                }
                else
                {
                    ShowResult();
                    FillResultTable(0);
                }
            }
            catch (Exception ex)
            {
                Trace.WriteLine(ex.Message);
            }
        }