Esempio n. 1
0
        /// <summary>
        /// 生成子路径
        /// </summary>
        /// <param name="g">寻径的floyd图</param>
        /// <param name="DKlist">路径上的dkcode列表,至少2个</param>
        /// <param name="milelist">路径上的里程列表,至少2个</param>
        /// <param name="stepm">细分里程间隔</param>
        private void CreateSubPathFromNodeList(MGraph g, List <string> DKlist, List <double> milelist, double stepm)
        {
            if (DKlist == null || DKlist.Count < 2)
            {
                return;
            }
            mFromDK      = DKlist.First();
            mToDK        = DKlist.Last();
            mFromMileage = milelist.First();
            mToMileage   = milelist.Last();
            mStepM       = stepm;
            mLength      = 0;
            List <PathNode> ls = new List <PathNode>();
            // 路径节点,0,2,4,6下标为链路编号,1,3,5,7等标注正序还是逆序,0-正序,1-逆序
            List <int>   idls = null;
            CRailwayLine tmpLine;

            //存放所有路径上的链路编号
            int[] rlls = new int[DKlist.Count];

            for (int i = 0; i < DKlist.Count; i++)
            {
                tmpLine = CRailwayLineList.getRailwayLineByDKCode(DKlist[i], milelist[i]);
                if (tmpLine == null)
                {
                    return;
                }
                rlls[i] = tmpLine.mIndex;
            }


            // 路径节点,0,2,4,6下标为路径编号,1,3,5,7等标注正序还是逆序,0-正序,1-逆序
            idls = ShortestPathFloyd.getNavPath(rlls, g);
            if (idls == null)
            {
                Console.WriteLine(DKlist[0] + "等路径不存在");
                return;
            }
            if (DKlist.Count == 2 && rlls[0] == rlls[1])  // 起点和终点在同一个链路中
            {
                CRailwayLine rl = CRailwayLineList.getRailwayLineByIndex(idls[0]);
                mLength = Math.Abs(milelist[0] - milelist.Last());
                //if (idls[1] == 0)
                ls.Add(new PathNode(rl, milelist[0], milelist.Last(), false));
                //else
                //    ls.Add(new PathNode(rl, milelist.Last(), milelist[0], true));
            }
            else if (idls.Count > 2)
            {
                mLength     = 0;
                mNodeLength = new double[idls.Count / 2];
                // path中的第一条链
                CRailwayLine rl = CRailwayLineList.getRailwayLineByIndex(idls[0]);
                if (idls[1] == 0)
                {
                    ls.Add(new PathNode(rl, milelist[0], rl.mEnd, false));
                    mLength += Math.Abs(milelist[0] - rl.mEnd);
                }
                else
                {
                    ls.Add(new PathNode(rl, milelist[0], rl.mStart, true));
                    mLength += Math.Abs(milelist[0] - rl.mStart);
                }
                mNodeLength[0] = mLength;
                if (idls.Count > 2)
                {
                    // path的中间链
                    for (int i = 1; i < idls.Count / 2 - 1; i++)
                    {
                        rl = CRailwayLineList.getRailwayLineByIndex(idls[2 * i]);
                        if (idls[2 * i + 1] == 0)
                        {
                            ls.Add(new PathNode(rl, rl.mStart, rl.mEnd, false));
                        }
                        else
                        {
                            ls.Add(new PathNode(rl, rl.mEnd, rl.mStart, true));
                        }
                        mLength       += Math.Abs(rl.mLength);
                        mNodeLength[i] = mLength;
                    }

                    // path的最后一条链
                    rl = CRailwayLineList.getRailwayLineByIndex(idls[idls.Count - 2]);
                    if (idls.Last() == 0)
                    {
                        ls.Add(new PathNode(rl, rl.mStart, milelist.Last(), false));
                        mLength += Math.Abs(rl.mStart - milelist.Last());
                    }
                    else
                    {
                        ls.Add(new PathNode(rl, rl.mEnd, milelist.Last(), true));
                        mLength += Math.Abs(rl.mEnd - milelist.Last());
                    }
                    mNodeLength[mNodeLength.Length - 1] = mLength;
                }
            }

            mPathNodeList = ls;

            hasPath = mPathNodeList.Count > 0 && mLength > 1;

            if (hasPath)
            {
                createSubLine();
            }
        }
Esempio n. 2
0
        public static MGraph gMileageConnection; // 用于计算里程

        /// <summary>
        /// 由数据库或远程服务器读入三维中线的数据,这儿无效,在工具中使用,
        /// </summary>
        /// <param name="fileName"></param>
        //public static void CreateLinelistFromExcel(string dbPath)
        //{
        //    double[] m, x, y, z;
        //    double fromMeter, toMeter;
        //    //double fromX, toX, fromY, toY;
        //    int chainIndex;
        //    int chainType;
        //    string dkcode, dkcode2;
        //    //bool isRight = false;
        //    //bool isDouble = true;
        //    int count;

        //    DataTable dt1, dt2, dt3;

        //    //本地sqlite数据库读取里程数据
        //    //#if DEBUG
        //    //            Helper.LogHelper.WriteLog("SQlite Database" + dbPath);
        //    //#endif

        //    dt1 = ExcelWrapper.LoadDataTableFromExcel(dbPath, @"select chainIndex, fromMeter, toMeter,DKCode,DKCode2,chainType from [ChainInfo$] order by chainIndex");
        //    dt2 = ExcelWrapper.LoadDataTableFromExcel(dbPath, @"select fromChain, toChain from [ExtraConnection$] ");
        //    List<OneConnection> connectionList = new List<OneConnection>();
        //    foreach (DataRow dr in dt2.Rows)
        //    {
        //        OneConnection aCon = new OneConnection();
        //        aCon.fromIndex = Convert.ToInt32(dr["fromChain"]);
        //        aCon.toIndex = Convert.ToInt32(dr["toChain"]);
        //        //aCon.isRealConnect = Convert.ToInt32(dr["isConnect"])==0 ? true:false;
        //        //aCon.mileageOffset = Convert.ToDouble(dr["mileageOffset"]);
        //        connectionList.Add(aCon);
        //    }
        //    //int index = 0;

        //    foreach (DataRow dr in dt1.Rows)
        //    {
        //        chainIndex = Convert.ToInt32(dr["chainIndex"]);
        //        fromMeter = Convert.ToDouble(dr["fromMeter"]);
        //        toMeter = Convert.ToDouble(dr["toMeter"]);
        //        dkcode = (string)dr["DKCode"];
        //        dkcode2 = dr["DKCode2"].ToString();
        //        chainType = Convert.ToInt32(dr["chainType"]);
        //        //  isReverse = Convert.ToBoolean(dr["IsReverse"]);
        //        string strOrder = (fromMeter < toMeter) ? "" : " desc ";
        //        string tableName = "sheet" + chainIndex;
        //        dt3 = ExcelWrapper.LoadDataTableFromExcel(dbPath, @"select Mileage, Longitude,Latitude,Altitude from [" + tableName + "$] order by mileage " + strOrder);
        //        count = dt3.Rows.Count;
        //        if (count < 2) continue;

        //        m = new double[count];
        //        x = new double[count];
        //        y = new double[count];
        //        z = new double[count];
        //        //xMars = new double[count];
        //        //yMars = new double[count];
        //        int j = 0;
        //        foreach (DataRow dr2 in dt3.Rows)
        //        {

        //            m[j] = Math.Abs(Convert.ToDouble(dr2["Mileage"]) - fromMeter);
        //            x[j] = Convert.ToDouble(dr2["Longitude"]);
        //            y[j] = Convert.ToDouble(dr2["Latitude"]);
        //            z[j] = Convert.ToDouble(dr2["Altitude"]);
        //            j++;
        //            //xMars[j] = Convert.ToDouble(dr2["LongitudeMars"]);
        //            //yMars[j] = Convert.ToDouble(dr2["LatitudeMars"]);
        //        }
        //        mLineList.Add(new CRailwayLine(chainIndex, dkcode, dkcode2, fromMeter, toMeter, chainType, count, m, x, y, z));
        //    }


        //    gRealConnection = new MGraph();
        //    gMileageConnection = new MGraph();

        //    ShortestPathFloyd.initPathGraph(mLineList, gRealConnection, null);
        //    ShortestPathFloyd.initPathGraph(mLineList, gMileageConnection, connectionList);
        //}

        /// <summary>
        /// 由数据库或远程服务器读入三维中线的数据
        /// </summary>
        /// <param name="fileName"></param>
        public static void CreateLinelistFromSqlite(string dbPath)
        {
            double[] m, x, y, z;
            double   fromMeter, toMeter;
            //double fromX, toX, fromY, toY;
            int    chainIndex;
            int    chainType;
            string dkcode, dkcode2;
            //bool isRight = false;
            //bool isDouble = true;
            int count;

            DataTable dt1, dt2, dt3;

            //本地sqlite数据库读取里程数据
            //#if DEBUG
            //            Helper.LogHelper.WriteLog("SQlite Database" + dbPath);
            //#endif

            dt1 = DatabaseWrapper.ExecuteDataTable(dbPath, @"select chainIndex, fromMeter, toMeter,DKCode,DKCode2,chainType from ChainInfo order by chainIndex; ");
            dt2 = DatabaseWrapper.ExecuteDataTable(dbPath, @"select fromChain, toChain from ExtraConnection; ");

            //dt1 = ExcelWrapper.LoadDataTableFromExcel(dbPath, @"select chainIndex, fromMeter, toMeter,DKCode,DKCode2,chainType from [ChainInfo$] order by chainIndex");
            //dt2 = ExcelWrapper.LoadDataTableFromExcel(dbPath, @"select fromChain, toChain from [ExtraConnection$] ");
            List <OneConnection> connectionList = new List <OneConnection>();

            foreach (DataRow dr in dt2.Rows)
            {
                OneConnection aCon = new OneConnection();
                aCon.fromIndex = Convert.ToInt32(dr["fromChain"]);
                aCon.toIndex   = Convert.ToInt32(dr["toChain"]);
                //aCon.isRealConnect = Convert.ToInt32(dr["isConnect"])==0 ? true:false;
                //aCon.mileageOffset = Convert.ToDouble(dr["mileageOffset"]);
                connectionList.Add(aCon);
            }
            //int index = 0;

            foreach (DataRow dr in dt1.Rows)
            {
                chainIndex = Convert.ToInt32(dr["chainIndex"]);
                fromMeter  = Convert.ToDouble(dr["fromMeter"]);
                toMeter    = Convert.ToDouble(dr["toMeter"]);
                dkcode     = (string)dr["DKCode"];
                if (dr["DKCode2"] == null)
                {
                    dkcode2 = "";
                }
                else
                {
                    dkcode2 = dr["DKCode2"].ToString();
                }
                chainType = Convert.ToInt32(dr["chainType"]);
                //  isReverse = Convert.ToBoolean(dr["IsReverse"]);
                string strOrder = (fromMeter < toMeter) ? "" : " desc ";
                //string tableName = "sheet" + chainIndex;
                dt3   = DatabaseWrapper.ExecuteDataTable(dbPath, @"select Mileage, Longitude,Latitude,Altitude from MileageInfo where MileagePrefix=" + chainIndex + "  order by mileage " + strOrder);
                count = dt3.Rows.Count;
                if (count < 2)
                {
                    continue;
                }

                m = new double[count];
                x = new double[count];
                y = new double[count];
                z = new double[count];
                //xMars = new double[count];
                //yMars = new double[count];
                int j = 0;
                foreach (DataRow dr2 in dt3.Rows)
                {
                    m[j] = Math.Abs(Convert.ToDouble(dr2["Mileage"]) - fromMeter);
                    x[j] = Convert.ToDouble(dr2["Longitude"]);
                    y[j] = Convert.ToDouble(dr2["Latitude"]);
                    z[j] = Convert.ToDouble(dr2["Altitude"]);
                    j++;
                    //xMars[j] = Convert.ToDouble(dr2["LongitudeMars"]);
                    //yMars[j] = Convert.ToDouble(dr2["LatitudeMars"]);
                }
                mLineList.Add(new CRailwayLine(chainIndex, dkcode, dkcode2, fromMeter, toMeter, chainType, count, m, x, y, z));
            }

            gRealConnection    = new MGraph();
            gMileageConnection = new MGraph();

            ShortestPathFloyd.initPathGraph(mLineList, gRealConnection, null);
            ShortestPathFloyd.initPathGraph(mLineList, gMileageConnection, connectionList);
        }