/// <summary>
 /// Конструктор
 /// </summary>
 /// <param name="start">Начальная координата</param>
 /// <param name="finish">Конечная координата</param>
 public TrackVectorItem(TrackItem start, TrackItem finish)
 {
     this.start = start;
     this.finish = finish;
     dist = DataAnalyzer.GetDist(start.Latitude, start.Longitude, finish.Latitude, finish.Longitude);
     heading = DataAnalyzer.GetBearing(start.Latitude, start.Longitude, finish.Latitude, finish.Longitude);
     duration = finish.Date - start.Date;
     speed = dist / duration.TotalSeconds;
 }
 /// <summary>
 /// Конструктор
 /// </summary>
 /// <param name="trackItem">Необработанный трек</param>
 /// <param name="procLat">Обработанная широта</param>
 /// <param name="procLon">Обработанная долгота</param>
 public ProccessedTrackItem(TrackItem trackItem, double procLat, double procLon)
 {
     origLat = trackItem.Latitude;
     origLon = trackItem.Longitude;
     date = trackItem.Date;
     this.procLat = procLat;
     this.procLon = procLon;
     dist = DataAnalyzer.GetDist(origLat, origLon, procLat, procLon);
 }
        /// <summary>
        /// Обработка набора данных в трек
        /// </summary>
        /// <param name="dataSet">набор данных</param>
        /// <returns>Трек</returns>
        private static Track ParseDataSet(DataSet dataSet, bool hasHeader)
        {
            DataTable dataTable = dataSet.Tables[0];
            DataRow[] rows = dataTable.Select();
            Track res = new Track();
            String latCol = null;
            String lonCol = null;
            String dateCol = null;
            String timeCol = null;
            if (hasHeader)
            {
                latCol = "Latitude";
                lonCol = "Longitude";
                int i = 0;
                while (i < dataTable.Columns.Count && !dataTable.Columns[i].ColumnName.ToLower().Contains("date"))
                    i++;
                if (i < dataTable.Columns.Count)
                    dateCol = dataTable.Columns[i].ColumnName;
                else
                    throw new Exception("Неверный формат файла");
                i = 0;
                while (i < dataTable.Columns.Count && !dataTable.Columns[i].ColumnName.ToLower().Contains("time"))
                    i++;
                if (i < dataTable.Columns.Count)
                    timeCol = dataTable.Columns[i].ColumnName;
                else
                    throw new Exception("Неверный формат файла");
            }
            else
            {
                for (int i = 0; i < dataTable.Columns.Count; i++)
                {
                    String cellVal = dataTable.Rows[0][i].ToString();
                    double testTouble;
                    DateTime testDt;
                    if (double.TryParse(cellVal.Replace(".", ","), out testTouble))
                    {
                        if (latCol == null)
                            latCol = dataTable.Columns[i].ColumnName;
                        else if (lonCol == null)
                            lonCol = dataTable.Columns[i].ColumnName;
                    }
                    else if (DateTime.TryParse(cellVal, out testDt))
                    {
                        if (dateCol == null)
                            dateCol = dataTable.Columns[i].ColumnName;
                        else if (timeCol == null)
                            timeCol = dataTable.Columns[i].ColumnName;
                    }

                }
            }
            foreach (DataRow row in rows)
            {
                double lat = row[latCol] is double ? (double)row[latCol] : double.Parse((row[latCol] as String).Replace('.', ','));
                double lon = row[lonCol] is double ? (double)row[lonCol] : double.Parse((row[lonCol] as String).Replace('.', ','));
                DateTime date = DateTime.Now;
                if (row[dateCol] is DateTime)
                {
                    date = (DateTime)row[dateCol];
                    DateTime time = (DateTime)row[timeCol];
                    date = date.AddHours(time.Hour);
                    date = date.AddMinutes(time.Minute);
                    date = date.AddSeconds(time.Second);
                }
                else
                {
                    date = DateTime.ParseExact(row[dateCol].ToString(), "MM.dd.yyyy", null);
                    DateTime time = DateTime.Parse(row[timeCol].ToString());
                    date = date.AddHours(time.Hour);
                    date = date.AddMinutes(time.Minute);
                    date = date.AddSeconds(time.Second);
                }
                TrackItem tempTrackItem = new TrackItem(lat, lon, date);
                res.AddTrackItem(tempTrackItem);
            }
            return res;
        }
Exemple #4
0
 /// <summary>
 /// Добавить координату
 /// </summary>
 /// <param name="trackItem">Координата</param>
 public void AddTrackItem(TrackItem trackItem)
 {
     trackItems.Add(trackItem);
 }
 /// <summary>
 /// обработать таблицу с обработанным треком
 /// </summary>
 /// <param name="dataTable">Таблица</param>
 /// <returns>Обработанный трек</returns>
 private ProccessedTrack ParseProccessedDataTable(DataTable dataTable)
 {
     bool isVector = dataTable.Columns.Count > 7;
     ProccessedTrack pTrack = new ProccessedTrack(dataTable.TableName.Replace('_', ' ').Replace("$", ""), isVector);
     DataRow[] dataRows = dataTable.Select();
     if (isVector)
     {
         foreach (DataRow row in dataRows)
         {
             double stlat = (double)row[1];
             double stlon = (double)row[2];
             DateTime stdate = (DateTime)row[3];
             double enlat = (double)row[4];
             double enlon = (double)row[5];
             DateTime endate = (DateTime)row[6];
             TimeSpan lapse = endate - stdate;
             double oSpeed = (double)row[8];
             double pSpeed = (double)row[9];
             double oDist = (double)row[10];
             double pDist = (double)row[11];
             double oHead = (double)row[12];
             double pHead = (double)row[13];
             TrackItem stItem = new TrackItem(stlat, stlon, stdate);
             TrackItem enItem = new TrackItem(enlat, enlon, endate);
             TrackVectorItem vItem = new TrackVectorItem(stItem, enItem);
             ProccessedTrackVectorItem pVector = new ProccessedTrackVectorItem(vItem, pSpeed, pDist, pHead);
             pTrack.AddProccedTrackVectorItem(pVector);
         }
     }
     else
     {
         foreach (DataRow row in dataRows)
         {
             double lat = (double)row[1];
             double lon = (double)row[2];
             DateTime date = (DateTime)row[3];
             double plat = (double)row[4];
             double plon = (double)row[5];
             double dist = (double)row[6];
             TrackItem item = new TrackItem(lat, lon, date);
             ProccessedTrackItem pItem = new ProccessedTrackItem(item, plat, plon);
             pTrack.AddProccessedTrackItem(pItem);
         }
     }
     return pTrack;
 }
 /// <summary>
 /// Обработать таблицу с треком
 /// </summary>
 /// <param name="dataTable">Таблица</param>
 /// <returns>Трек</returns>
 private Track ParseDataTable(DataTable dataTable)
 {
     DataRow[] dataRows = dataTable.Select();
     Track track = new Track();
     foreach (DataRow row in dataRows)
     {
         double lat = (double)row[1];
         double lon = (double)row[2];
         DateTime date = (DateTime)row[3];
         TrackItem temp = new TrackItem(lat, lon, date);
         track.AddTrackItem(temp);
     }
     track.CalculateVectors();
     return track;
 }