Ejemplo n.º 1
0
        public static void LoadMap()
        {
            //Open file from path
            StreamReader file = new StreamReader(Global.Batch.INFATI.Path + "\\map.csv");

            //Discard data header
            file.ReadLine();

            //Read remaining file, split every row into its columns
            string entry;
            List<List<string>> rows = new List<List<string>>();

            while ((entry = file.ReadLine()) != null) {
                List<string> elements = entry.Split(new char[] { ';' }, StringSplitOptions.RemoveEmptyEntries).ToList();

                //Add to list of entries
                rows.Add(elements);
            }

            file.Close();

            //Assemble the entries into SegmentInformation
            List<Fact> facts = new List<Fact>();
            DBController dbc = new DBController();

            foreach (List<string> row in rows) {
                //(Int64 SegmentId, Int64 OSMId, string RoadName, Int16 RoadType, Int16 Oneway, Int16 Bridge, Int16 Tunnel, Int16 MaxSpeed, bool Direction, PostgisLineString RoadLine)
                //segmentkey0;segmentid1;name2;category3;startpoint4;endpoint5;direction6;speedlimit_forward7;speedlimit_backward8;meters9;geom10
                if (row.Count != 11) {
                    Int64 segmentIdC12 = Int64.Parse(row[0]);
                    Int64 osmIdC12 = Int64.Parse(row[1]);
                    string RoadNameC12 = row[2] + ";" + row[3];

                    Int16 RoadTypeC12 = (Int16)(Global.Enums.RoadType)Enum.Parse(typeof(Global.Enums.RoadType), row[4]);
                    Int16 OneWayC12 = (Int16)(Global.Enums.Direction)Enum.Parse(typeof(Global.Enums.Direction), row[7]);

                    SegmentInformation segmentC12 = new SegmentInformation(segmentIdC12, osmIdC12, RoadNameC12, RoadTypeC12, OneWayC12, 0, 0, 0, false, null);

                    Int16 speedlimitForwardC12 = Int16.Parse(row[8]);
                    Int16 speedlimitBackwardC12 = Int16.Parse(row[9]);
                    string lineStringC12 = row[11];

                    dbc.AddSegment(segmentC12, speedlimitForwardC12, speedlimitBackwardC12, lineStringC12);
                    //REFACTOR POTENTIAL BECAUSE approx 165 cases has length 12... the code is just copy-pasted in again and adjusted the index-keys
                    continue;
                }

                Int64 segmentId = Int64.Parse(row[0]);
                Int64 osmId = Int64.Parse(row[1]);
                string RoadName = row[2];

                Int16 RoadType = (Int16)(Global.Enums.RoadType)Enum.Parse(typeof(Global.Enums.RoadType), row[3]);
                Int16 OneWay = (Int16)(Global.Enums.Direction)Enum.Parse(typeof(Global.Enums.Direction), row[6]);

                SegmentInformation segment = new SegmentInformation(segmentId, osmId, RoadName, RoadType, OneWay, 0, 0, 0, false, null);

                Int16 speedlimitForward = Int16.Parse(row[7]);
                Int16 speedlimitBackward = Int16.Parse(row[8]);
                string lineString = row[10];

                dbc.AddSegment(segment, speedlimitForward, speedlimitBackward, lineString);
            }

            dbc.Close();
        }