/// <summary> /// gets routes from gpsd log file /// </summary> /// <param name="gpsdLogFile"></param> /// <param name="start">start time(UTC) of route, null to read from very start</param> /// <param name="end">end time(UTC) of route, null to read to the very end</param> /// <param name="maxPositionDilutionOfPrecision">max value of PositionDilutionOfPrecision, null to get all</param> /// <returns></returns> public static IEnumerable <List <GpsLog> > GetRoutesFromMobileLog(string gpsdLogFile, DateTime?start, DateTime?end, double?maxPositionDilutionOfPrecision) { #if SQLite using (SQLiteConnection cn = new SQLiteConnection()) { #if !MONO cn.ConnectionString = string.Format("Data Source=\"{0}\";FailIfMissing=True;", gpsdLogFile); #else cn.ConnectionString = string.Format("Version=3,URI=file://{0},FailIfMissing=True", gpsdLogFile); #endif cn.Open(); { using (DbCommand cmd = cn.CreateCommand()) { cmd.CommandText = "SELECT * FROM GPS "; int initLenght = cmd.CommandText.Length; if (start.HasValue) { cmd.CommandText += "WHERE TimeUTC >= @t1 "; SQLiteParameter lookupValue = new SQLiteParameter("@t1", start); cmd.Parameters.Add(lookupValue); } if (end.HasValue) { if (cmd.CommandText.Length <= initLenght) { cmd.CommandText += "WHERE "; } else { cmd.CommandText += "AND "; } cmd.CommandText += "TimeUTC <= @t2 "; SQLiteParameter lookupValue = new SQLiteParameter("@t2", end); cmd.Parameters.Add(lookupValue); } if (maxPositionDilutionOfPrecision.HasValue) { if (cmd.CommandText.Length <= initLenght) { cmd.CommandText += "WHERE "; } else { cmd.CommandText += "AND "; } cmd.CommandText += "PositionDilutionOfPrecision <= @p3 "; SQLiteParameter lookupValue = new SQLiteParameter("@p3", maxPositionDilutionOfPrecision); cmd.Parameters.Add(lookupValue); } using (DbDataReader rd = cmd.ExecuteReader()) { List <GpsLog> points = new List <GpsLog>(); while (rd.Read()) { GpsLog log = new GpsLog(); { log.TimeUTC = (DateTime)rd["TimeUTC"]; log.SessionCounter = (long)rd["SessionCounter"]; log.Delta = rd["Delta"] as double?; log.Speed = rd["Speed"] as double?; log.SeaLevelAltitude = rd["SeaLevelAltitude"] as double?; log.EllipsoidAltitude = rd["EllipsoidAltitude"] as double?; log.SatellitesInView = rd["SatellitesInView"] as System.Byte?; log.SatelliteCount = rd["SatelliteCount"] as System.Byte?; log.Position = new PointLatLng((double)rd["Lat"], (double)rd["Lng"]); log.PositionDilutionOfPrecision = rd["PositionDilutionOfPrecision"] as double?; log.HorizontalDilutionOfPrecision = rd["HorizontalDilutionOfPrecision"] as double?; log.VerticalDilutionOfPrecision = rd["VerticalDilutionOfPrecision"] as double?; log.FixQuality = (FixQuality)((byte)rd["FixQuality"]); log.FixType = (FixType)((byte)rd["FixType"]); log.FixSelection = (FixSelection)((byte)rd["FixSelection"]); } if (log.SessionCounter == 0 && points.Count > 0) { List <GpsLog> ret = new List <GpsLog>(points); points.Clear(); { yield return(ret); } } points.Add(log); } if (points.Count > 0) { List <GpsLog> ret = new List <GpsLog>(points); points.Clear(); { yield return(ret); } } points.Clear(); points = null; rd.Close(); } } } cn.Close(); } #else return(null); #endif }
/// <summary> /// gets routes from gpsd log file /// </summary> /// <param name="gpsdLogFile"></param> /// <param name="start">start time(UTC) of route, null to read from very start</param> /// <param name="end">end time(UTC) of route, null to read to the very end</param> /// <param name="maxPositionDilutionOfPrecision">max value of PositionDilutionOfPrecision, null to get all</param> /// <returns></returns> public static IEnumerable<List<GpsLog>> GetRoutesFromMobileLog(string gpsdLogFile, DateTime? start, DateTime? end, double? maxPositionDilutionOfPrecision) { #if SQLite using(SQLiteConnection cn = new SQLiteConnection()) { #if !MONO cn.ConnectionString = string.Format("Data Source=\"{0}\";FailIfMissing=True;", gpsdLogFile); #else cn.ConnectionString = string.Format("Version=3,URI=file://{0},FailIfMissing=True", gpsdLogFile); #endif cn.Open(); { using(DbCommand cmd = cn.CreateCommand()) { cmd.CommandText = "SELECT * FROM GPS "; int initLenght = cmd.CommandText.Length; if(start.HasValue) { cmd.CommandText += "WHERE TimeUTC >= @t1 "; SQLiteParameter lookupValue = new SQLiteParameter("@t1", start); cmd.Parameters.Add(lookupValue); } if(end.HasValue) { if(cmd.CommandText.Length <= initLenght) { cmd.CommandText += "WHERE "; } else { cmd.CommandText += "AND "; } cmd.CommandText += "TimeUTC <= @t2 "; SQLiteParameter lookupValue = new SQLiteParameter("@t2", end); cmd.Parameters.Add(lookupValue); } if(maxPositionDilutionOfPrecision.HasValue) { if(cmd.CommandText.Length <= initLenght) { cmd.CommandText += "WHERE "; } else { cmd.CommandText += "AND "; } cmd.CommandText += "PositionDilutionOfPrecision <= @p3 "; SQLiteParameter lookupValue = new SQLiteParameter("@p3", maxPositionDilutionOfPrecision); cmd.Parameters.Add(lookupValue); } using(DbDataReader rd = cmd.ExecuteReader()) { List<GpsLog> points = new List<GpsLog>(); while(rd.Read()) { GpsLog log = new GpsLog(); { log.TimeUTC = (DateTime)rd["TimeUTC"]; log.SessionCounter = (long)rd["SessionCounter"]; log.Delta = rd["Delta"] as double?; log.Speed = rd["Speed"] as double?; log.SeaLevelAltitude = rd["SeaLevelAltitude"] as double?; log.EllipsoidAltitude = rd["EllipsoidAltitude"] as double?; log.SatellitesInView = rd["SatellitesInView"] as System.Byte?; log.SatelliteCount = rd["SatelliteCount"] as System.Byte?; log.Position = new PointLatLng((double)rd["Lat"], (double)rd["Lng"]); log.PositionDilutionOfPrecision = rd["PositionDilutionOfPrecision"] as double?; log.HorizontalDilutionOfPrecision = rd["HorizontalDilutionOfPrecision"] as double?; log.VerticalDilutionOfPrecision = rd["VerticalDilutionOfPrecision"] as double?; log.FixQuality = (FixQuality)((byte)rd["FixQuality"]); log.FixType = (FixType)((byte)rd["FixType"]); log.FixSelection = (FixSelection)((byte)rd["FixSelection"]); } if(log.SessionCounter == 0 && points.Count > 0) { List<GpsLog> ret = new List<GpsLog>(points); points.Clear(); { yield return ret; } } points.Add(log); } if(points.Count > 0) { List<GpsLog> ret = new List<GpsLog>(points); points.Clear(); { yield return ret; } } points.Clear(); points = null; rd.Close(); } } } cn.Close(); } #else return null; #endif }