//Check if urban criteria are matched
        //********************************************************************************************

        /*Parameters:
         *      - dt_urban:         DataTable with the urban dataset
         *      - column_speed:     string with the name of the speed column
         *      - column_time:      string with the name of the time column
         */
        //********************************************************************************************
        private bool CheckUrban(DataTable dt_urban, string column_speed, string column_time)
        {
            double avgSpeed          = 0;
            double duration_interval = 0;

            duration_hold = 0;
            double duration_ratio = 0;
            int    countTime      = 1;

            //Calculate the average speed in the interval and the duration of the trip in minutes
            avgSpeed          = (double)dt_urban.Compute("SUM([" + column_speed + "])", "") / dt_urban.Rows.Count;
            duration_interval = (double)(dt_urban.Rows.Count - 1) / 60;

            //Copy only entries with a speed value lower than 1 km/h to DataTable
            //and sort DataTable by time
            dt_urban = dt_urban.Select("[" + column_speed + "]" + " < 1").CopyToDataTable();
            Berechnungen.SortData(ref dt_urban, column_time);

            //Check if single hold time was longer as 300 seconds
            for (int i = 1; i < dt_urban.Rows.Count; i++)
            {
                if (Convert.ToDouble(dt_urban.Rows[i][column_time]) - Convert.ToDouble(dt_urban.Rows[i - 1][column_time]) == 1000)
                {
                    countTime++;
                }
                else
                {
                    countTime = 1;
                }
            }

            //Calculate value of longest hold time
            //and the ratio of the longest hold time to the duration of trip
            duration_hold  = (double)(dt_urban.Rows.Count - 1) / 60;
            duration_ratio = duration_hold * 100 / duration_interval;

            //if urban criteria matched return true
            if (avgSpeed >= 15 && avgSpeed <= 40 && duration_ratio >= 6 && duration_ratio <= 30 && countTime <= 120)
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }
示例#2
0
        private void AddRoute(string column_latitude, string column_longitude, string column_speed, string column_time)
        {
            GMapOverlay        routes         = new GMapOverlay("routes");
            List <PointLatLng> points         = new List <PointLatLng>();
            List <PointLatLng> pointsUrban    = new List <PointLatLng>();
            List <PointLatLng> pointsRural    = new List <PointLatLng>();
            List <PointLatLng> pointsMotorway = new List <PointLatLng>();

            DataTable urban    = new DataTable();
            DataTable rural    = new DataTable();
            DataTable motorway = new DataTable();
            DataTable dt       = new DataTable();

            Berechnungen.SepIntervals(dataset, column_speed);
            Berechnungen.GetIntervals(ref urban, ref rural, ref motorway);

            Berechnungen.SortData(ref urban, column_time);
            Berechnungen.SortData(ref rural, column_time);
            Berechnungen.SortData(ref motorway, column_time);

            for (int i = 0; i < urban.Rows.Count; i++)
            {
                points.Add(new PointLatLng(Convert.ToDouble(urban.Rows[i][column_latitude]), Convert.ToDouble(urban.Rows[i][column_longitude])));

                if (i >= 1 && (Convert.ToDouble(urban.Rows[i][column_time]) - (Convert.ToDouble(urban.Rows[(i - 1)][column_time])) > 1000))
                {
                    dt = rural.Select("[" + column_time + "] = " + (Convert.ToInt32(urban.Rows[i - 1][column_time]) + 1000)).CopyToDataTable();

                    points.RemoveAt(points.Count - 1);
                    points.Add(new PointLatLng(Convert.ToDouble(dt.Rows[0][column_latitude]), Convert.ToDouble(dt.Rows[0][column_longitude])));

                    GMapRoute route = new GMapRoute(points, "Urban");
                    route.Stroke = new Pen(Color.IndianRed, 4);
                    routes.Routes.Add(route);

                    points.Clear();
                    points.Add(new PointLatLng(Convert.ToDouble(urban.Rows[i][column_latitude]), Convert.ToDouble(urban.Rows[i][column_longitude])));
                }
            }

            GMapRoute routeA = new GMapRoute(points, "Urban");

            routeA.Stroke = new Pen(Color.IndianRed, 4);
            routes.Routes.Add(routeA);

            points.Clear();

            for (int i = 0; i < rural.Rows.Count; i++)
            {
                points.Add(new PointLatLng(Convert.ToDouble(rural.Rows[i][column_latitude]), Convert.ToDouble(rural.Rows[i][column_longitude])));

                if (i >= 1 && (Convert.ToDouble(rural.Rows[i][column_time]) - (Convert.ToDouble(rural.Rows[(i - 1)][column_time])) > 1000))
                {
                    if (Convert.ToDouble(rural.Rows[i - 1]["ai"]) < 0)
                    {
                        dt = urban.Select("[" + column_time + "] = " + (Convert.ToInt32(rural.Rows[i - 1][column_time]) + 1000)).CopyToDataTable();
                    }
                    else
                    {
                        dt = motorway.Select("[" + column_time + "] = " + (Convert.ToInt32(rural.Rows[i - 1][column_time]) + 1000)).CopyToDataTable();
                    }

                    points.RemoveAt(points.Count - 1);
                    points.Add(new PointLatLng(Convert.ToDouble(dt.Rows[0][column_latitude]), Convert.ToDouble(dt.Rows[0][column_longitude])));

                    GMapRoute route = new GMapRoute(points, "Rural");
                    route.Stroke = new Pen(Color.MediumSeaGreen, 4);
                    routes.Routes.Add(route);

                    points.Clear();
                    points.Add(new PointLatLng(Convert.ToDouble(rural.Rows[i][column_latitude]), Convert.ToDouble(rural.Rows[i][column_longitude])));
                }
            }
            dt = urban.Select("[" + column_time + "] = " + (Convert.ToInt32(rural.Rows[rural.Rows.Count - 1][column_time]) + 1000)).CopyToDataTable();
            points.Add(new PointLatLng(Convert.ToDouble(dt.Rows[0][column_latitude]), Convert.ToDouble(dt.Rows[0][column_longitude])));

            GMapRoute routeB = new GMapRoute(points, "Rural");

            routeB.Stroke = new Pen(Color.MediumSeaGreen, 4);
            routes.Routes.Add(routeB);

            points.Clear();

            for (int i = 0; i < motorway.Rows.Count; i++)
            {
                points.Add(new PointLatLng(Convert.ToDouble(motorway.Rows[i][column_latitude]), Convert.ToDouble(motorway.Rows[i][column_longitude])));

                if (i >= 1 && (Convert.ToDouble(motorway.Rows[i][column_time]) - (Convert.ToDouble(motorway.Rows[(i - 1)][column_time])) > 1000))
                {
                    dt = rural.Select("[" + column_time + "] = " + (Convert.ToInt32(motorway.Rows[i - 1][column_time]) + 1000)).CopyToDataTable();

                    points.RemoveAt(points.Count - 1);
                    points.Add(new PointLatLng(Convert.ToDouble(dt.Rows[0][column_latitude]), Convert.ToDouble(dt.Rows[0][column_longitude])));

                    GMapRoute route = new GMapRoute(points, "motorway");
                    route.Stroke = new Pen(Color.LightSkyBlue, 4);
                    routes.Routes.Add(route);

                    points.Clear();
                    points.Add(new PointLatLng(Convert.ToDouble(motorway.Rows[i][column_latitude]), Convert.ToDouble(motorway.Rows[i][column_longitude])));
                }
            }
            dt = rural.Select("[" + column_time + "] = " + (Convert.ToInt32(motorway.Rows[motorway.Rows.Count - 1][column_time]) + 1000)).CopyToDataTable();
            points.Add(new PointLatLng(Convert.ToDouble(dt.Rows[0][column_latitude]), Convert.ToDouble(dt.Rows[0][column_longitude])));

            GMapRoute routeC = new GMapRoute(points, "Motorway");

            routeC.Stroke = new Pen(Color.LightSkyBlue, 4);
            routes.Routes.Add(routeC);
            gMap.Overlays.Add(routes);

            //GMapOverlay markers = new GMapOverlay("markers");
            //GMapMarker marker = new GMarkerGoogle(
            //    new PointLatLng(Convert.ToDouble(motorway.Rows[motorway.Rows.Count - 1][column_latitude]), Convert.ToDouble(motorway.Rows[motorway.Rows.Count - 1][column_longitude])),
            //    GMarkerGoogleType.blue_pushpin);
            //markers.Markers.Add(marker);
            //gMap.Overlays.Add(markers);

            //points.Clear();
            //for (int i = 0; i < dataset.Rows.Count; i++)
            //{
            //    points.Add(new PointLatLng(Convert.ToDouble(dataset.Rows[i][column_latitude]), Convert.ToDouble(dataset.Rows[i][column_longitude])));
            //}

            //GMapRoute routee = new GMapRoute(points, "Color Coded Trip");
            //routee.Stroke = new Pen(Color.Blue, 1);
            //routes.Routes.Add(routee);
            //gMap.Overlays.Add(routes);

            //MainForm.Controls["txtMeasurement"].Text = "//Gemessene Distanz anhand GPS Datenauswertung:\n" + routee.Distance.ToString();
        }