Gpx.GpxTrackPoint SetGpxPoint(Models.GpxPoint pt, DateTime?inicio) { /* * Sacar elevacion * https://secure.geonames.org/srtm3JSON?lat=43.528641&lng=-6.523797&username=galwayireland * {"srtm3":107,"lng":-6.523797,"lat":43.528641} */ var pto = new Gpx.GpxTrackPoint(); pto.Elevation = pt.Ele ?? 1; if (pt.Lat < 25) { pto.Latitude = (Double)(pt.Lon ?? 0); pto.Longitude = (Double)(pt.Lat ?? 0); } else { pto.Latitude = (Double)(pt.Lat ?? 0); pto.Longitude = (Double)(pt.Lon ?? 0); } if (inicio.HasValue && pt.Time.HasValue) { DateTime dt = DateTime.Now; TimeSpan ts = pt.Time.Value - inicio.Value; pto.Time = dt + ts; } else { pto.Time = DateTime.Now; } return(pto); }
private void WriteTrackPoint(GpxTrackPoint trackPoint) { Writer_.WriteStartElement("trkpt"); WritePoint(trackPoint); if (trackPoint.HasExtensions) { Writer_.WriteStartElement("extensions"); Writer_.WriteStartElement("TrackPointExtension", GpxNamespaces.GARMIN_TRACKPOINT_EXTENSIONS_V2_NAMESPACE); if (trackPoint.Temperature != null) { Writer_.WriteElementString("atemp", GpxNamespaces.GARMIN_TRACKPOINT_EXTENSIONS_V2_NAMESPACE, trackPoint.Temperature.Value.ToString()); } if (trackPoint.WaterTemperature != null) { Writer_.WriteElementString("wtemp", GpxNamespaces.GARMIN_TRACKPOINT_EXTENSIONS_V2_NAMESPACE, trackPoint.WaterTemperature.Value.ToString()); } if (trackPoint.Depth != null) { Writer_.WriteElementString("depth", GpxNamespaces.GARMIN_TRACKPOINT_EXTENSIONS_V2_NAMESPACE, trackPoint.Depth.Value.ToString()); } if (trackPoint.HeartRate != null) { Writer_.WriteElementString("hr", GpxNamespaces.GARMIN_TRACKPOINT_EXTENSIONS_V2_NAMESPACE, trackPoint.HeartRate.Value.ToString()); } if (trackPoint.Cadence != null) { Writer_.WriteElementString("cad", GpxNamespaces.GARMIN_TRACKPOINT_EXTENSIONS_V2_NAMESPACE, trackPoint.Cadence.Value.ToString()); } if (trackPoint.Speed != null) { Writer_.WriteElementString("speed", GpxNamespaces.GARMIN_TRACKPOINT_EXTENSIONS_V2_NAMESPACE, trackPoint.Speed.Value.ToString()); } if (trackPoint.Course != null) { Writer_.WriteElementString("course", GpxNamespaces.GARMIN_TRACKPOINT_EXTENSIONS_V2_NAMESPACE, trackPoint.Course.Value.ToString()); } if (trackPoint.Bearing != null) { Writer_.WriteElementString("bearing", GpxNamespaces.GARMIN_TRACKPOINT_EXTENSIONS_V2_NAMESPACE, trackPoint.Bearing.Value.ToString()); } Writer_.WriteEndElement(); Writer_.WriteEndElement(); } Writer_.WriteEndElement(); }
private void ReadTrackPointExtensions(GpxTrackPoint trackPoint) { if (Reader_.IsEmptyElement) { return; } string elementName = Reader_.Name; while (Reader_.Read()) { switch (Reader_.NodeType) { case XmlNodeType.Element: if (Reader_.NamespaceURI == GpxNamespaces.GARMIN_EXTENSIONS_NAMESPACE || Reader_.NamespaceURI == GpxNamespaces.GARMIN_TRACKPOINT_EXTENSIONS_V1_NAMESPACE || Reader_.NamespaceURI == GpxNamespaces.GARMIN_TRACKPOINT_EXTENSIONS_V2_NAMESPACE) { switch (Reader_.LocalName) { case "TrackPointExtension": ReadGarminTrackPointExtensions(trackPoint); break; default: SkipElement(); break; } break; } SkipElement(); break; case XmlNodeType.EndElement: if (Reader_.Name != elementName) { throw new FormatException(Reader_.Name); } return; } } throw new FormatException(elementName); }
private GpxTrackPoint ReadGpxTrackPoint() { string elementName = Reader_.Name; bool isEmptyElement = Reader_.IsEmptyElement; GpxTrackPoint trackPoint = new GpxTrackPoint(); GetPointLocation(trackPoint); if (isEmptyElement) { return(trackPoint); } while (Reader_.Read()) { switch (Reader_.NodeType) { case XmlNodeType.Element: switch (Reader_.Name) { case "extensions": ReadTrackPointExtensions(trackPoint); break; default: if (!ProcessPointField(trackPoint)) { SkipElement(); } break; } break; case XmlNodeType.EndElement: if (Reader_.Name != elementName) { throw new FormatException(Reader_.Name); } return(trackPoint); } } throw new FormatException(elementName); }
internal void Add(GpxTrackPoint point) { this.points.Add(point); }
private void ReadGarminTrackPointExtensions(GpxTrackPoint trackPoint) { if (Reader_.IsEmptyElement) { return; } string elementName = Reader_.Name; while (Reader_.Read()) { switch (Reader_.NodeType) { case XmlNodeType.Element: switch (Reader_.LocalName) { case "Temperature": case "atemp": trackPoint.Temperature = ReadContentAsDouble(); break; case "wtemp": trackPoint.WaterTemperature = ReadContentAsDouble(); break; case "Depth": case "depth": trackPoint.Depth = ReadContentAsDouble(); break; case "hr": trackPoint.HeartRate = ReadContentAsInt(); break; case "cad": trackPoint.Cadence = ReadContentAsInt(); break; case "speed": trackPoint.Speed = ReadContentAsDouble(); break; case "course": trackPoint.Course = ReadContentAsDouble(); break; case "bearing": trackPoint.Bearing = ReadContentAsDouble(); break; default: SkipElement(); break; } break; case XmlNodeType.EndElement: if (Reader_.Name != elementName) { throw new FormatException(Reader_.Name); } return; } } throw new FormatException(elementName); }