/// <summary> /// Create the graph from a GPX file /// </summary> /// <param name="gpx">gpx file</param> public Graph(string gpx) : this() { // Read in the GPX file try { GPXType map = GPXType.FromFile(gpx); Tracks = map.Tracks; } catch (InvalidOperationException) { //Version 2.0 using (GpxReader reader = new GpxReader(new FileStream(gpx, FileMode.Open))) { while (reader.Read()) { switch (reader.ObjectType) { case GpxObjectType.Metadata: break; case GpxObjectType.WayPoint: Waypoints.Add(new WayPoint(reader.WayPoint)); break; case GpxObjectType.Route: break; case GpxObjectType.Track: Tracks.Add(new Track(reader.Track)); break; } } } } // We finally know how many vertices we have so we can construct the matrix CreateEdges(Tracks); }
public List<GpxWayPoint> GetPoints() { var result = new List<GpxWayPoint>(); var fileName = CurrentFileName(); var tempFileName = "points.gpx.temp"; IsolatedStorageFile isStore = IsolatedStorageFile.GetUserStoreForApplication(); if (isStore.FileExists(tempFileName)) { isStore.DeleteFile(tempFileName); } if (isStore.FileExists(fileName)) { isStore.CopyFile(fileName, tempFileName); } else { return result; } using (IsolatedStorageFileStream input = new IsolatedStorageFileStream(tempFileName, System.IO.FileMode.Open, FileAccess.Read, isStore)) { using (GpxReader reader = new GpxReader(input)) { while (reader.Read()) { switch (reader.ObjectType) { case GpxObjectType.WayPoint: result.Add(reader.WayPoint); break; } } } } return result; }
public int SaveFile(GeoPosition<GeoCoordinate> Position = null) { if (Position == null) { GeoCoordinateWatcher watcher = new GeoCoordinateWatcher(GeoPositionAccuracy.Default); watcher.Start(); Position = watcher.Position; } var fileName = CurrentFileName(); var tempFileName = "record.gpx.temp"; var count = 0; bool firstRun = true; IsolatedStorageFile isStore = IsolatedStorageFile.GetUserStoreForApplication(); if (isStore.FileExists(tempFileName)) { isStore.DeleteFile(tempFileName); } if (isStore.FileExists(fileName)) { firstRun = false; isStore.MoveFile(fileName, tempFileName); } using (IsolatedStorageFileStream input = new IsolatedStorageFileStream(tempFileName, System.IO.FileMode.OpenOrCreate, FileAccess.Read, isStore)) using (IsolatedStorageFileStream output = new IsolatedStorageFileStream(fileName, System.IO.FileMode.OpenOrCreate, FileAccess.Write, isStore)) using (GpxWriter writer = new GpxWriter(output)) { GpxWayPoint last = null; if (!firstRun) { using (GpxReader reader = new GpxReader(input)) { while (reader.Read()) { switch (reader.ObjectType) { case GpxObjectType.WayPoint: count++; writer.WriteWayPoint(reader.WayPoint); last = reader.WayPoint; break; } } } } IsolatedStorageSettings.ApplicationSettings["LastLocation"] = last; IsolatedStorageSettings.ApplicationSettings.Save(); if (double.IsNaN(Position.Location.Latitude) || double.IsNaN(Position.Location.Longitude)) { return count; } if (last == null || last.Time.ToString() != Position.Timestamp.UtcDateTime.ToString()) { writer.WriteWayPoint(new GpxWayPoint { Latitude = Position.Location.Latitude, Longitude = Position.Location.Longitude, Elevation = Position.Location.Altitude, Time = Position.Timestamp.UtcDateTime, }); count++; } } return count; }