public void loadBusData()
        {
            string path = @"E:\Projects\BusMap\BusRouterConverter\output\";

            string routerString      = File.ReadAllText(path + "routers.json");
            string stationString     = File.ReadAllText(path + "stations.json");
            string stationPathString = File.ReadAllText(path + "stationPath.json");

            List <Router>      list1 = JsonConvert.DeserializeObject <List <Router> >(routerString);
            List <Station>     list2 = JsonConvert.DeserializeObject <List <Station> >(stationString);
            List <StationPath> list3 = JsonConvert.DeserializeObject <List <StationPath> >(stationPathString);

            for (int i = 0; i < list1.Count; i++)
            {
                Router router = list1[i];
                _listRouter.Add(router.RouterId, router);
            }
            for (int i = 0; i < list2.Count; i++)
            {
                Station station = list2[i];
                _listStation.Add(station.StationId, station);
            }
            for (int i = 0; i < list3.Count; i++)
            {
                StationPath stationPath = list3[i];
                if (!_listPath.ContainsKey(stationPath.PathId))
                {
                    _listPath.Add(stationPath.PathId, stationPath);
                }
            }
        }
Exemple #2
0
        public bool addPath(int stationA, int stationB)
        {
            if (!_busData.Stations.ContainsKey(stationA) || !_busData.Stations.ContainsKey(stationB))
            {
                return(false);
            }
            Vertex vertA = checkAndAddVertex(stationA);
            Vertex vertB = checkAndAddVertex(stationB);

            string      pathId = BUtils.generatePathId(stationA, stationB);
            Edge        edge   = checkAndAddEdge(pathId);
            StationPath path   = _busData.getStationPath(pathId);

            edge.Target = vertB;
            edge.Weight = path.Distance;
            addEdgeToVertex(edge, vertA);

            return(true);
        }
Exemple #3
0
        private void updateStationPath(string stationPathId)
        {
            try
            {
                if (!_listPath.ContainsKey(stationPathId))
                {
                    return;
                }
                StationPath path = _listPath[stationPathId];
                Station     startStation, endStation;
                if (!_listStation.ContainsKey(path.StartStation))
                {
                    throw new Exception("Invalid station: " + path.StartStation);
                }
                startStation = _listStation[path.StartStation];
                if (!_listStation.ContainsKey(path.EndStation))
                {
                    throw new Exception("Invalid station: " + path.EndStation);
                }
                endStation = _listStation[path.EndStation];

                PointLatLng start     = new PointLatLng(startStation.LatLong.Latitude, startStation.LatLong.Longitude);
                PointLatLng end       = new PointLatLng(endStation.LatLong.Latitude, endStation.LatLong.Longitude);
                MapRoute    mapRouter = GMap.NET.MapProviders.GoogleMapProvider.Instance.GetRoute(start, end, false, false, 50);
                path.Path.Clear();
                long distance = (long)(mapRouter.Distance * 1000); // as meter
                for (int j = 0; j < mapRouter.Points.Count; j++)
                {
                    PointLatLng point   = mapRouter.Points[j];
                    LatLong     latlong = new LatLong();
                    latlong.Latitude  = point.Lat;
                    latlong.Longitude = point.Lng;
                    path.Path.Add(latlong);
                }
                path.Distance = distance;
            }
            catch (Exception e)
            {
                Console.Error.WriteLine(e.Message);
            }
        }
Exemple #4
0
        private void drawStationPath(List <int> stationIds, Color color, GMapOverlay overlay)
        {
            List <PointLatLng> list = new List <PointLatLng>();
            int preStation          = 0;

            for (int i = 0; i < stationIds.Count; i++)
            {
                int station = stationIds[i];
                if (preStation == 0)
                {
                    preStation = station;
                }
                else
                {
                    string key = BUtils.generatePathId(preStation, station);
                    if (!StationPaths.ContainsKey(key))
                    {
                        preStation = station;
                        continue;
                    }
                    StationPath    path   = StationPaths[key];
                    List <LatLong> points = path.Path;
                    for (int j = 0; j < points.Count; j++)
                    {
                        LatLong     point = points[j];
                        PointLatLng pont1 = new PointLatLng(point.Latitude, point.Longitude);
                        list.Add(pont1);
                    }
                    preStation = station;
                }
            }

            GMapRoute routers = new GMapRoute(list, "polygon");

            routers.Stroke       = new Pen(color);
            routers.Stroke.Width = 5;
            overlay.Routes.Add(routers);
        }
Exemple #5
0
        private void drawStationPath(List <int> stationIds)
        {
            List <PointLatLng> list = new List <PointLatLng>();
            int preStation          = 0;

            for (int i = 0; i < stationIds.Count; i++)
            {
                int station = stationIds[i];
                if (preStation == 0)
                {
                    preStation = station;
                }
                else
                {
                    string key = preStation + "_" + station;
                    if (!_listPath.ContainsKey(key))
                    {
                        preStation = station;
                        continue;
                    }
                    StationPath    path   = _listPath[key];
                    List <LatLong> points = path.Path;
                    for (int j = 0; j < points.Count; j++)
                    {
                        LatLong     point = points[j];
                        PointLatLng pont1 = new PointLatLng(point.Latitude, point.Longitude);
                        list.Add(pont1);
                    }
                    preStation = station;
                }
            }

            GMapRoute routers = new GMapRoute(list, "polygon");

            routerOverlay.Routes.Add(routers);
        }
        public static void loadFormFiles(String[] filenames, Dictionary <int, Router> listRouter, Dictionary <int, Station> listStation,
                                         Dictionary <string, StationPath> listPath)
        {
            for (int i = 0; i < filenames.Length; i++)
            {
                string path = filenames[i];
                string json = File.ReadAllText(path);

                //
                char[]   keys     = { '\\', '-', '.' };
                string[] parts    = path.Split(keys);
                int      routerid = Int32.Parse(parts[parts.Length - 3]);
                int      turn     = Int32.Parse(parts[parts.Length - 2]);

                Router router = null;

                if (!listRouter.ContainsKey(routerid))
                {
                    router          = new Router();
                    router.RouterId = routerid;
                    listRouter.Add(routerid, router);
                }
                else
                {
                    router = listRouter[routerid];
                    List <int> list = null;
                    if (turn == 1)
                    {
                        list = router.Stations1;
                    }
                    else
                    {
                        list = router.Stations2;
                    }
                    if (list.Count != 0)
                    {
                        DialogResult result = MessageBox.Show("Router: " + routerid + "_" + turn + " is exist. Please delete it then try again", "Warning", MessageBoxButtons.OK);
                        continue;
                    }
                }

                Dictionary <string, object> obj = deserializeObject(json);
                JArray  array      = (JArray)obj["TABLE"];
                JToken  rows       = (JToken)array[0];
                JArray  array2     = (JArray)rows["ROW"];
                Station preStation = null;
                foreach (JToken stationdata in array2)
                {
                    JArray arraydata   = (JArray)stationdata["COL"];
                    string address     = parseJsonData(arraydata[12]).ToString();
                    double Lat         = Double.Parse(parseJsonData(arraydata[9]).ToString());
                    double Lng         = Double.Parse(parseJsonData(arraydata[8]).ToString());
                    int    stationId   = Int32.Parse(parseJsonData(arraydata[1]).ToString());
                    string stationName = parseJsonData(arraydata[7]).ToString();
                    string stationCode = parseJsonData(arraydata[13]).ToString();
                    int    routerId    = Int32.Parse(parseJsonData(arraydata[0]).ToString());
                    string routerName  = parseJsonData(arraydata[10]).ToString();
                    string routerDes   = parseJsonData(arraydata[11]).ToString();

                    router.Description = routerDes;
                    router.Name        = routerName;
                    Station station = null;

                    if (listStation.ContainsKey(stationId))
                    {
                        station = listStation[stationId];
                        station.Routers.Add(routerid);
                    }
                    else
                    {
                        station             = new Station();
                        station.Address     = address;
                        station.LatLong     = new LatLong(Lat, Lng);
                        station.StationId   = stationId;
                        station.StationName = stationName;
                        station.StationCode = stationCode;

                        if (!station.Routers.Contains(routerid))
                        {
                            station.Routers.Add(routerid);
                        }

                        listStation.Add(stationId, station);
                    }

                    if (turn == 1)
                    {
                        if (!router.Stations1.Contains(stationId))
                        {
                            router.Stations1.Add(stationId);
                        }
                    }
                    else
                    {
                        if (!router.Stations2.Contains(stationId))
                        {
                            router.Stations2.Add(stationId);
                        }
                    }

                    if (preStation == null)
                    {
                        preStation = station;
                    }
                    else
                    {
                        StationPath stationPath = new StationPath();
                        stationPath.PathId = preStation.StationId + "_" + station.StationId;
                        //
                        PointLatLng start     = new PointLatLng(preStation.LatLong.Latitude, preStation.LatLong.Longitude);
                        PointLatLng end       = new PointLatLng(station.LatLong.Latitude, station.LatLong.Longitude);
                        MapRoute    mapRouter = GMap.NET.MapProviders.GoogleMapProvider.Instance.GetRoute(start, end, true, false, 50);
                        long        distance  = (long)(mapRouter.Distance * 1000); // as meter
                        for (int j = 0; j < mapRouter.Points.Count; j++)
                        {
                            PointLatLng point   = mapRouter.Points[j];
                            LatLong     latlong = new LatLong();
                            latlong.Latitude  = point.Lat;
                            latlong.Longitude = point.Lng;
                            stationPath.Path.Add(latlong);
                        }
                        stationPath.StartStation = preStation.StationId;
                        stationPath.EndStation   = station.StationId;
                        stationPath.Distance     = distance;
                        if (!listPath.ContainsKey(stationPath.PathId))
                        {
                            listPath.Add(stationPath.PathId, stationPath);
                        }
                        preStation = station;
                    }
                }
            }
        }
        public void AddPathData(string label, StationPath path)
        {
            Stopwatch stopWatch = new Stopwatch();
            TimeSpan  ts;

            double passingYard = 0;
            int    cntRows     = tablePaths.RowCount;

            if (path == null)
            {
                return;
            }

            Label CinBoth = new Label()
            {
                Text = "--", Anchor = AnchorStyles.Left, AutoSize = true
            };

            if (path.MainPath)
            {
                CinBoth.Text = "M - " + label;
            }
            else
            {
                CinBoth.Text = label;
            }

            int   nbrGlobalItem = path.ComponentItem.Count - 1;
            Label CoutBoth      = new Label()
            {
                Text = "--", Anchor = AnchorStyles.Left, AutoSize = true
            };
            GlobalItem lastItem = (GlobalItem)(path.ComponentItem[nbrGlobalItem]);

            if (lastItem.GetType() == typeof(AEBufferItem) && lastItem.associateNode.TrEndNode)
            {
                CoutBoth.Text = ((AEBufferItem)lastItem).NameBuffer;
            }
            else if (lastItem.GetType() == typeof(TrackSegment) && lastItem.associateNode.TrJunctionNode == null)
            {
                CoutBoth.Text = ((TrackSegment)(lastItem)).HasConnector.label;
                if ((path.ComponentItem[0]).GetType() == typeof(TrackSegment))
                {
                    passingYard = Math.Round(path.PassingYard, 1);
                }
            }
            else
            {
                CoutBoth.Text = "###";
            }
            //TextBox t1 = new TextBox();

            //l1.Text = "field : ";
            stopWatch.Start();
            tablePaths.RowCount++;
            this.tablePaths.RowStyles.Add(new RowStyle(SizeType.AutoSize)); // 30 is the rows space
            this.tablePaths.Controls.Add(CinBoth, 0, cntRows);              // add label in column0
            this.tablePaths.Controls.Add(CoutBoth, 1, cntRows);             // add textbox in column1
            double yard           = Math.Round(path.Platform, 1);
            Label  platformLength = new Label()
            {
                Text = yard.ToString(), Anchor = AnchorStyles.Left, AutoSize = true
            };

            this.tablePaths.Controls.Add(platformLength, 2, cntRows);
            yard = Math.Round(path.Siding, 1);
            Label sidingLength = new Label()
            {
                Text = yard.ToString(), Anchor = AnchorStyles.Left, AutoSize = true
            };

            this.tablePaths.Controls.Add(sidingLength, 3, cntRows);

            Label nbrPlatform = new Label()
            {
                Text = path.NbrPlatform.ToString(), Anchor = AnchorStyles.Left, AutoSize = true
            };

            this.tablePaths.Controls.Add(nbrPlatform, 4, cntRows);
            Label nbrSiding = new Label()
            {
                Text = path.NbrSiding.ToString(), Anchor = AnchorStyles.Left, AutoSize = true
            };

            this.tablePaths.Controls.Add(nbrSiding, 5, cntRows);
            Label passingYardLength = new Label()
            {
                Text = passingYard.ToString(), Anchor = AnchorStyles.Left, AutoSize = true
            };

            this.tablePaths.Controls.Add(passingYardLength, 6, cntRows);
            CinBoth = new Label()
            {
                Text = "--", Anchor = AnchorStyles.Left, AutoSize = true
            };
            cntRows++;
            ts = stopWatch.Elapsed;
        }