public void TestReadingFile() { var reader = new GoogleTimelineKmlReader(); var positions = reader.Read(@"Gps\GoogleTimeline.kml"); Assertions.AreEqual(new List <Position>() { new Position(new DateTimeOffset(2016, 12, 18, 00, 46, 26, TimeSpan.Zero), 45.705188, -12.2042061), new Position(new DateTimeOffset(2016, 12, 18, 00, 47, 39, TimeSpan.Zero), 45.7053364, -12.20418839999999) }, positions.ToList()); }
private static void Main(string[] args) { if (args.Length == 0) { Console.WriteLine("First parameter is the project file path. An example project file should look like this:"); Console.WriteLine(); Console.WriteLine(JsonConvert.SerializeObject(new Settings(), Formatting.Indented)); return; } if (!File.Exists(args[0])) { Console.WriteLine("Project file {0} does not exist", args[0]); return; } Settings settings = JsonConvert.DeserializeObject <Settings>(File.ReadAllText(args[0]), new JsonSerializerSettings { Culture = CultureInfo.InvariantCulture, DateParseHandling = DateParseHandling.DateTimeOffset, DateFormatHandling = DateFormatHandling.IsoDateFormat, }); CreateDirectoryIfNotExists(settings.WorkingDirectory); CreateDirectoryIfNotExists(settings.OutputDirectory); var folder = settings.PicturesInputDirectory; if (!Directory.Exists(folder)) { using (var se = new StreamWriter(System.Console.OpenStandardError())) { se.WriteLine("Provided directory doesn't exist, Pictures directory: {0}", folder); return; } } var allPoints = CacheOrExecute(Path.Combine(settings.WorkingDirectory, "cached-positions.json"), () => ImageUtility.FindLatLongsWithTime(folder)); allPoints = allPoints.Where(p => p.DilutionOfPrecision <10 && p.DilutionOfPrecision> 0.01).ToList(); if (!string.IsNullOrEmpty(settings.GpsInputDirectory)) { Console.WriteLine("Adding points from Endomondo"); var gpsPoints = CacheOrExecute(Path.Combine(settings.WorkingDirectory, "endomondo-positions.json"), () => FindAllPointsFromGpx(settings.GpsInputDirectory)); allPoints = EnumerableUtils.Merge(allPoints, gpsPoints, (x, y) => x.Time < y.Time).ToList(); } if (!string.IsNullOrEmpty(settings.GoogleTimelineKmlFile)) { Console.WriteLine("Adding Google Timeline points"); var googleTimelinePoints = new GoogleTimelineKmlReader().Read(settings.GoogleTimelineKmlFile); allPoints = EnumerableUtils.Merge(allPoints, googleTimelinePoints, (x, y) => x.Time < y.Time).ToList(); } if (!string.IsNullOrEmpty(settings.GoogleTimelineJsonFile)) { Console.WriteLine("Adding Google Timeline points from JSON"); var googleTimelinePoints = new GoogleTimelineJsonReader(settings.GoogleTimelineMinimumAccuracyMeters).Read(settings.GoogleTimelineJsonFile); allPoints = EnumerableUtils.Merge(allPoints, googleTimelinePoints, (x, y) => x.Time < y.Time).ToList(); } allPoints = allPoints.Where(p => (settings.StartTime == null || p.Time > settings.StartTime) && (settings.EndTime == null || p.Time < settings.EndTime)).ToList(); WritePointsAsGpx(settings.OutputDirectory, allPoints); CreateMapFromPoints(allPoints, settings); }