public void GetData_2Segment3PointsInXml_3Points() { setUpFileManagerWithText ( @"<gpx><trk> <trkseg> <trkpt lat = ""40.1"" lon = ""30.23""> <ele>4600.5</ele><time>2011-07-20T06:19:57Z</time> </trkpt> <trkpt lat = ""40.1"" lon = ""30.23""> <ele>4600.5</ele><time>2011-07-20T06:19:57Z</time> </trkpt> </trkseg> <trkseg> <trkpt lat = ""40.1"" lon = ""30.23""> <ele>4600.5</ele><time>2011-07-20T06:19:57Z</time> </trkpt> </trkseg> </trk></gpx>" ); var res = new GpxFileReader("filePath").GetData(); Assert.AreEqual(3, res.Count()); }
public void GetData_OnePointInXml_OneCorrectPoint() { setUpFileManagerWithText ( @"<gpx><trk> <trkseg> <trkpt lat = ""40.1"" lon = ""30.23""> <ele>4600.5</ele><time>2011-07-20T06:19:57Z</time> </trkpt> </trkseg> </trk></gpx>" ); var res = new GpxFileReader("filePath").GetData(); Assert.AreEqual(1, res.Count()); Assert.AreEqual(res.First(), new GeoData() { Latitude = 40.1, Longitude = 30.23, Altitude = 4600.5, CreatingDate = new DateTime(2011, 07, 20, 6, 19, 57)} ); }
public int ChangeGeoDataForFiles(IEnumerable<string> pathToImageFiles, string pathToTrack, int timezone, Action actionDuringIteration, out string errors) { errors = ""; if (pathToImageFiles.Count() == 0) return 0; IEnumerable<GeoData> track; try { using (var gpxeReader = new GpxFileReader(pathToTrack)) { track = gpxeReader.GetData(); } } catch (Exception e) { errors = String.Format(Resources.ErrorREadTrackFileUI, pathToTrack); m_Log.Error(String.Format(Resources.ErrorReadTrackFileLog, pathToTrack), e); return 0; } int countChangedFiles = 0; BlockingCollection<string> errosInProcces = new BlockingCollection<string>(); SynchronizationContext ctx = SynchronizationContext.Current; Parallel.ForEach(pathToImageFiles, file => { string error; var res = changeExifInformationInFile(file, createDirectoryForOutput(file), out error, (EXIFFileWorker photoExifInfo, out string er) => { er = ""; GeoData? geoData = new GeoDataWorker().GetGeoForPointByTime(photoExifInfo.GetDateTimeTaken().AddHours(-timezone), track); if (geoData == null) { er = String.Format(EXIFPhotoEditor.Properties.Resources.CantFindCoordsForPhotoUI, file); m_Log.ErrorFormat(EXIFPhotoEditor.Properties.Resources.CanTFindCoordsForPhotoLog, file); return false; } photoExifInfo.ChangeGeoData(geoData.Value.Latitude,geoData.Value.Longitude, geoData.Value.Altitude); return true; }); if (res) countChangedFiles++; else errosInProcces.Add(error); actionDuringIteration(); }); errors = errosInProcces.Aggregate("", (acum, str) => acum + str + "\r\n"); return countChangedFiles; }