Ejemplo n.º 1
0
        private static int CreateCube(string travelPath, string cubePath)
        {
            List <string> AllTravels = new List <string>();
            StreamReader  sr         = new StreamReader(travelPath, Encoding.Default);
            // 内存读取行程数据集,获得起始经纬度最大、最小值
            string line = sr.ReadLine();
            double minX = double.MaxValue, maxX = double.MinValue;
            double minY = double.MaxValue, maxY = double.MinValue;

            Console.WriteLine("Start Reading!");
            while ((line = sr.ReadLine()) != null)
            {
                AllTravels.Add(line);
                string[] travel = line.Split(',');
                double   startX = Convert.ToDouble(travel[5]), startY = Convert.ToDouble(travel[6]);
                if (startX < minX)
                {
                    minX = startX;
                }
                if (startX > maxX)
                {
                    maxX = startX;
                }
                if (startY < minY)
                {
                    minY = startY;
                }
                if (startY > maxY)
                {
                    maxY = startY;
                }
            }
            Console.WriteLine("Reading finished! Creating Cube now!");
            // 读取行程数据集,生成Cube
            int  lineNum = 0; int err = 0;
            Cube cube = new Cube(minX, maxX, minY, maxY);

            for (int i = 0; i < AllTravels.Count; i++)
            {
                string[] oneRecord = AllTravels[i].Split(',');
                string   CarID = oneRecord[1];
                DateTime StartTime = DateTime.Parse(oneRecord[2]);
                DateTime EndTime = DateTime.Parse(oneRecord[3]);
                double   StartX = Convert.ToDouble(oneRecord[5]), StartY = Convert.ToDouble(oneRecord[6]), EndX = Convert.ToDouble(oneRecord[7]), EndY = Convert.ToDouble(oneRecord[8]);
                double   TravelLength = Convert.ToDouble(oneRecord[9]);

                OneTravel oneTravel = new OneTravel(lineNum, CarID, StartTime, EndTime, StartX, StartY, EndX, EndY, TravelLength);

                err = cube.AddTravel(oneTravel);

                lineNum++;
            }
            //Console.WriteLine("Creating cube finished,WRITING now!");
            Console.WriteLine("ERROR Num: {0}", err);
            cube.WriteCubeToCSV(cubePath);

            return(err);
            //Console.WriteLine("WRITING FINISHED!");
        }
Ejemplo n.º 2
0
        public int AddTravel(OneTravel travel)
        {
            double    x = travel.StartX, y = travel.StartY;
            double    intervalX  = Math.Floor((x - MinStartX) / rangeX) * rangeX + MinStartX;
            double    intervalY  = Math.Floor((y - MinStartY) / rangeY) * rangeY + MinStartY;
            GISVertex key        = new GISVertex(intervalX, intervalY);
            int       errorCount = 0;

            // 什么情况下会出现明明存在key却说不存在
            if (VertexWithLineIndex.ContainsKey(key))
            {
                VertexWithLineIndex[key].Add(travel.LineNum);
            }
            else
            {
                errorCount++;
            }

            return(errorCount);

            ; //double key = Math.Floor((x - MinStartX) / rangeX) * rangeX + MinStartX; //计算出x对应的区间最小值
              //XwithLineIndex[key].Add(travel.LineNum);
        }
Ejemplo n.º 3
0
 public void AddTravel(OneTravel oneTravel)
 {
     travels.Add(oneTravel);
 }