public static Gpx11.gpxType Open(string path) { XmlReaderSettings settings = new XmlReaderSettings(); settings.CheckCharacters = true; settings.CloseInput = true; settings.Schemas.Add(null, GpxSchemaPath); settings.ValidationType = ValidationType.Schema; settings.ValidationFlags |= XmlSchemaValidationFlags.ReportValidationWarnings; settings.ValidationEventHandler += new ValidationEventHandler(settings_ValidationEventHandler); Gpx11.gpxType gpx = null; using (XmlReader xmlReader = XmlReader.Create(path)) { //if (xmlReader != null) //{ // while (xmlReader.Read()) // { // //empty loop - if Read fails it will raise an error via the // //ValidationEventHandler wired to the XmlReaderSettings object // } // //explicitly call Close on the XmlReader to reduce strain on the GC // xmlReader.Close(); //} XmlSerializer serializer = new XmlSerializer(typeof(Gpx11.gpxType)); gpx = (Gpx11.gpxType)serializer.Deserialize(xmlReader); } return(gpx); }
public HttpResponseMessage GetProfileGpxFile([FromUri] Guid profileId) { var views = ApplicationManager.BuildViews(); var profile = views.Profiles.GetById(profileId); var waypoints = profile.Track.Points.Select(CreateWaypoint).ToArray(); var trkseg = new gpx11.trksegType(); trkseg.trkpt = waypoints; var trk = new gpx11.trkType(); trk.name = profile.Name; trk.trkseg = new[] { trkseg }; var gpx = new gpx11.gpxType(); gpx.creator = "Altidude.net"; gpx.version = "0.1"; gpx.trk = new gpx11.trkType[] { trk }; return(new HttpResponseMessage(HttpStatusCode.OK) { Content = new ObjectContent <gpx11.gpxType>(gpx, new System.Net.Http.Formatting.XmlMediaTypeFormatter { UseXmlSerializer = true }) }); }
public static void SaveTo(Gpx11.gpxType gpx, Stream stream) { using (var xmlWriter = XmlWriter.Create(stream)) { XmlSerializer serializer = new XmlSerializer(typeof(Gpx11.gpxType)); serializer.Serialize(stream, gpx); } }
public HttpResponseMessage GetProfilePositionFile() { var views = ApplicationManager.BuildViews(); var profiles = views.Profiles.GetAll(); var waypoints = new List <gpx11.wptType>(); var number = 1; foreach (var profile in profiles) { waypoints.Add(new gpx11.wptType() { lat = (decimal)profile.Track.FirstPoint.Latitude, lon = (decimal)profile.Track.FirstPoint.Longitude, name = "#" + number + " - " + profile.Name }); number++; } var gpx = new gpx11.gpxType(); gpx.creator = "Altidude.net"; gpx.version = "0.1"; gpx.wpt = waypoints.ToArray(); return(new HttpResponseMessage(HttpStatusCode.OK) { Content = new ObjectContent <gpx11.gpxType>(gpx, new System.Net.Http.Formatting.XmlMediaTypeFormatter { UseXmlSerializer = true }) }); }
public static Track CreateTrack(gpx11.gpxType gpx) { var trackPoints = new List <TrackPoint>(); var transformer = new GaussKreugerTranformation(Ellipsoid.WGS84); if (gpx.trk.Length > 0) { var trk = gpx.trk[0]; double distance = 0.0; Coordinate lastCoordinate = null; foreach (var trkseg in trk.trkseg) { foreach (var trkpt in trkseg.trkpt) { var coodinate = transformer.ToCoordinate((double)trkpt.lat, (double)trkpt.lon); if (lastCoordinate != null) { distance += lastCoordinate.DistanceTo(coodinate); } lastCoordinate = coodinate; var trackpoint = new TrackPoint((double)trkpt.lat, (double)trkpt.lon, (double)trkpt.ele, distance, trkpt.time); trackPoints.Add(trackpoint); } } } var climbs = new ClimbFinder().Find(trackPoints.ToArray()); return(new Track(Guid.NewGuid(), trackPoints.ToArray(), climbs)); }
public static Gpx11.gpxType Open(Stream stream, bool validate) { Gpx11.gpxType gpx = null; using (XmlReader xmlReader = CreateXmlReader(stream, validate)) { //if (xmlReader != null) //{ // while (xmlReader.Read()) // { // //empty loop - if Read fails it will raise an error via the // //ValidationEventHandler wired to the XmlReaderSettings object // } // //explicitly call Close on the XmlReader to reduce strain on the GC // xmlReader.Close(); //} XmlSerializer serializer = new XmlSerializer(typeof(Gpx11.gpxType)); gpx = (Gpx11.gpxType)serializer.Deserialize(xmlReader); } return(gpx); }