internal List <wptType> ConvertTrackToRoute(trkType track) { var waypoints = new List <wptType>(); foreach (var segment in track.trkseg) { waypoints.AddRange(segment.trkpt); } return(waypoints); }
public override GpxModel clone() { GpxTrackModel newModel = null; trkType trk = (trkType)Track.Clone(); if (trk != null) { newModel = new GpxTrackModel(null, trk); } return(newModel); }
/// <summary> /// Return set of all unique 6-digit plus codes that intersect a track. /// </summary> /// <param name="track"></param> /// <returns></returns> public static HashSet <string> ComputeBounds(trkType track) { var codes = new HashSet <string>(); foreach (var seg in track.trkseg) { foreach (var point in seg.trkpt) { codes.Add(GetLocationCode(point)); } } return(codes); }
private IEnumerable<RouteData> ConvertTracksToRouteData(trkType[] trks) { var tracks = trks.Where(t => t.trkseg != null && t.trkseg.Any()).Select(t => new RouteData { name = t.name, segments = t.trkseg.Where(seg => seg.trkpt != null && seg.trkpt.Length > 1).Select(seg => new RouteSegmentData { latlngzs = seg.trkpt.Select(ToLatLngZ).ToList(), routePoint = ToLatLngZ(seg.trkpt.Last()), routingType = RoutingTypeConverter.FromXml(seg.extensions) }).ToList(), }); return tracks; }
private void gpx_save_Click(object sender, RoutedEventArgs e) { SaveFileDialog saveFileDialog1 = new SaveFileDialog(); saveFileDialog1.Filter = "GPX file|*.gpx"; saveFileDialog1.Title = "Save To GPX File"; saveFileDialog1.ShowDialog(); // If the file name is not an empty string open it for saving. if (saveFileDialog1.FileName != "") { GpxClass track = new GpxClass(); wptTypeCollection trkpt = new wptTypeCollection(); foreach (Location lc in gpx_locations) { wptType wpt = new wptType(); wpt.lat = (decimal)lc.Latitude; wpt.lon = (decimal)lc.Longitude; wpt.ele = (decimal)lc.Altitude; wpt.eleSpecified = true; trkpt.Add(wpt); } trksegType trk_seg = new trksegType(); trk_seg.trkpt = trkpt; trksegTypeCollection trk_seg_cl = new trksegTypeCollection(); trk_seg_cl.Addtrkseg(trk_seg); trkType trk = new trkType(); trk.name = DateTime.Now.ToString("MM/dd/yyyy h:mm tt"); trk.trkseg = trk_seg_cl; track.trk = new trkTypeCollection(); track.trk.Add(trk); track.ToFile(saveFileDialog1.FileName); System.Windows.Forms.MessageBox.Show("GPX file is saved!"); // back to the teleport mode. cur_click_mode = e_click_mode.teleport; gpx_create_button.Content = "Create GPX"; way_points.Text = ""; gpx_locations.Clear(); myMap.Children.Clear(); gpx_save_button.IsEnabled = false; } }
public string ToXmlString() { GpxClass gpx = new GpxClass() { creator = "Blue Diamond", trk = new trkTypeCollection() }; trkType track = new trkType() { name = Name, }; track.trkseg = new trksegTypeCollection(); trksegType segment = new trksegType() { trkpt = new wptTypeCollection() }; track.trkseg.Add(segment); foreach(var pt in this.Points) { wptType wpt = new wptType() { lat = (decimal)pt.Latitude, lon = (decimal)pt.Longitude, ele = (decimal)pt.Altitude, eleSpecified = true, time = pt.TimeStamp, }; segment.trkpt.Add(wpt); } gpx.trk.Add(track); try { var gpx11 = ToGpx1_1(gpx); XmlSerializer serializer = new XmlSerializer(gpx11.GetType()); Utf8StringWriter sw = new Utf8StringWriter(); serializer.Serialize(sw, gpx11); return sw.ToString(); } catch (Exception ex) { Trace.TraceError("error serializing:\r\n{0}",ex); return null; } //return gpx.ToXml(); }
public static IDictionary<string, object> LoadTrackAttributes( trkType trk, IDictionary<string, object> attributes ) { trk.RequireArgument<trkType>( "trk" ).NotNull<trkType>(); attributes.RequireArgument<IDictionary<string, object>>( "attributes" ).NotNull<IDictionary<string, object>>(); attributes.Add( "name", trk.name ); attributes.Add( "cmt", trk.cmt ); attributes.Add( "desc", trk.desc ); attributes.Add( "src", trk.src ); attributes.Add( "link", trk.link ); attributes.Add( "number", trk.number ); attributes.Add( "type", trk.type ); return attributes; }
private trkType[] CreateTracksFromMultiLineString(IFeature multiLineStringFeature) { var multiLineString = multiLineStringFeature.Geometry as MultiLineString; if (multiLineString == null) { return(new trkType[0]); } var name = GetFeatureName(multiLineStringFeature); var description = GetFeatureDescription(multiLineStringFeature); var tracks = new List <trkType>(); var currentTrack = new trkType { name = name, desc = description, trkseg = new trksegType[0] }; var nameIndex = 1; foreach (var lineString in multiLineString.Geometries.OfType <ILineString>().Where(ls => ls.Coordinates.Any())) { var currentSegment = new trksegType { trkpt = lineString.Coordinates.Select(p => CreateWayPoint(p, null, null)).ToArray() }; if (currentTrack.trkseg.Length == 0) { currentTrack.trkseg = new[] { currentSegment }; continue; } var lastPointInTrack = currentTrack.trkseg.Last().trkpt.Last(); var firstPointInSegment = currentSegment.trkpt.First(); if (lastPointInTrack.lat == firstPointInSegment.lat && lastPointInTrack.lon == firstPointInSegment.lon) { var list = currentTrack.trkseg.ToList(); list.Add(currentSegment); currentTrack.trkseg = list.ToArray(); } else { // need to start a new track. tracks.Add(currentTrack); currentTrack = new trkType { name = name + " " + nameIndex, desc = description, trkseg = new[] { currentSegment } }; nameIndex++; } } tracks.Add(currentTrack); return(tracks.ToArray()); }
internal static void Save(Stream stream, Route route) { GpxDocument gpxDocument = new GpxDocument((IXmlSource) new XmlStreamSource(stream)); gpxType gpxType = new gpxType(); gpxType.trk = new trkType[1]; List <wptType> wptTypeList1 = new List <wptType>(); trkType trkType = new trkType(); List <wptType> wptTypeList2 = new List <wptType>(); trkType.trkseg = new trksegType[1]; trksegType trksegType = new trksegType(); for (int index1 = 0; index1 < route.Segments.Count; ++index1) { RouteSegment segment = route.Segments[index1]; if (segment.Points != null) { for (int index2 = 0; index2 < segment.Points.Length; ++index2) { RouteStop point = segment.Points[index2]; RouteTags routeTags = point.Tags == null ? (RouteTags)null : ((IEnumerable <RouteTags>)point.Tags).FirstOrDefault <RouteTags>((Func <RouteTags, bool>)(x => x.Value == "name")); wptTypeList2.Add(new wptType() { lat = (Decimal)point.Latitude, lon = (Decimal)point.Longitude, name = routeTags == null ? string.Empty : routeTags.Value }); } } wptTypeList1.Add(new wptType() { lat = (Decimal)segment.Latitude, lon = (Decimal)segment.Longitude }); } trksegType.trkpt = wptTypeList1.ToArray(); trkType.trkseg[0] = trksegType; gpxType.trk[0] = trkType; gpxType.wpt = wptTypeList2.ToArray(); gpxDocument.Gpx = (object)gpxType; gpxDocument.Save(); }
public GpxTrackModel(GpxModel parent, trkType trk) { Parent = parent; if (trk == null) { Track = new trkType(); Track.name = "New Track"; } else { Track = trk; } Segments = new List <GpxTrackSegmentModel>(); if (Track.trkseg != null) { foreach (trksegType seg in Track.trkseg) { Segments.Add(new GpxTrackSegmentModel(this, seg)); } } }
/// <summary> /// Saves the route to a gpx file. /// </summary> /// <param name="file"></param> /// <param name="route"></param> internal static void Save(Stream stream, Route route) { XmlStreamSource source = new XmlStreamSource(stream); GpxDocument output_document = new GpxDocument(source); gpxType output_gpx = new gpxType(); output_gpx.trk = new trkType[1]; // initialize all objects. List <wptType> segments = new List <wptType>(); trkType track = new trkType(); List <wptType> poi_gpx = new List <wptType>(); track.trkseg = new trksegType[1]; // ============= CONSTRUCT TRACK SEGMENT ============== trksegType track_segment = new trksegType(); // loop over all points. for (int idx = 0; idx < route.Entries.Length; idx++) { // get the current entry. RoutePointEntry entry = route.Entries[idx]; // ================== INITIALIZE A NEW SEGMENT IF NEEDED! ======== wptType waypoint; if (entry.Points != null) { // loop over all points and create a waypoint for each. for (int p_idx = 0; p_idx < entry.Points.Length; p_idx++) { RoutePoint point = entry.Points[p_idx]; waypoint = new wptType(); waypoint.lat = (decimal)point.Latitude; waypoint.lon = (decimal)point.Longitude; waypoint.name = point.Name; poi_gpx.Add(waypoint); } } // insert poi's. double longitde = entry.Longitude; double latitude = entry.Latitude; waypoint = new wptType(); waypoint.lat = (decimal)entry.Latitude; waypoint.lon = (decimal)entry.Longitude; segments.Add(waypoint); } // put the segment in the track. track_segment.trkpt = segments.ToArray(); track.trkseg[0] = track_segment; // set the track to the output. output_gpx.trk[0] = track; output_gpx.wpt = poi_gpx.ToArray(); // save the ouput. output_document.Gpx = output_gpx; output_document.Save(); }
private static trkType ReadTrack( XElement element ) { element.RequireArgument<XElement>( "element" ).NotNull<XElement>(); XNamespace ns = element.Name.Namespace; trkType trk = new trkType(); if( element.Element( ns + "name" ) != null ) trk.name = element.Element( ns + "name" ).Value; if( element.Element( ns + "cmt" ) != null ) trk.cmt = element.Element( ns + "cmt" ).Value; if( element.Element( ns + "desc" ) != null ) trk.desc = element.Element( ns + "desc" ).Value; if( element.Element( ns + "src" ) != null ) trk.src = element.Element( ns + "src" ).Value; if( element.Element( ns + "link" ) != null ) trk.link = ReadLinks(element.Elements(ns + "link" ) ); if( element.Element( ns + "number" ) != null ) trk.number = element.Element( ns + "number" ).Value; //Ignore the extensions if( element.Element( ns + "trkseg" ) != null ) trk.trkseg = ReadTrackSegments(element.Elements( ns + "trkseg" ) ); return trk; }
private trkType[] CreateTracksFromMultiLineString(IFeature multiLineStringFeature) { var multiLineString = multiLineStringFeature.Geometry as MultiLineString; if (multiLineString == null) { return new trkType[0]; } var name = GetFeatureName(multiLineStringFeature); var tracks = new List<trkType>(); var currentTrack = new trkType { name = name, trkseg = new trksegType[0]}; foreach (var lineString in multiLineString.Geometries.OfType<ILineString>().Where(ls => ls.Coordinates.Any())) { var currentSegment = new trksegType { trkpt = lineString.Coordinates.Select(p => CreateWayPoint(p, null)).ToArray() }; if (currentTrack.trkseg.Length == 0) { currentTrack.trkseg = new[] {currentSegment}; continue; } var lastPointInTrack = currentTrack.trkseg.Last().trkpt.Last(); var firstPointInSegment = currentSegment.trkpt.First(); if (lastPointInTrack.lat == firstPointInSegment.lat && lastPointInTrack.lon == firstPointInSegment.lon) { var list = currentTrack.trkseg.ToList(); list.Add(currentSegment); currentTrack.trkseg = list.ToArray(); } else { // need to start a new track. tracks.Add(currentTrack); currentTrack = new trkType {name = name, trkseg = new[] {currentSegment}}; } } tracks.Add(currentTrack); return tracks.ToArray(); }
/// <summary> /// Exports in-memory data to a GPX file /// </summary> /// <param name="options">Export options in key-value pairs</param> public void ExportToGPXFile(Dictionary <string, string> options) { if (!options.ContainsKey("file")) { throw new ExportOptionException("Provide a file name to export to.\nEx: NeoFlyExport.exe --file=neofly.gpx"); } const double footMeterRatio = 0.3048; // Segment list List <trkType> trks = new List <trkType>(); // Rows to be exported IEnumerable <DataRow> exportRows; // If only the file name is provided, we export all selected rows if (options.Count == 1) { exportRows = TableLog.AsEnumerable().Where(row => row.Field <bool>("Export")); } // If a log ID is provided, we export only this one else if (options.ContainsKey("logid")) { exportRows = TableLog.AsEnumerable().Where(row => row.Field <int>("Id").ToString() == options["logid"]); } // Other filters are processed else { exportRows = TableLog.AsEnumerable(); // dateFrom: Exports all rows after this date if (options.ContainsKey("datefrom")) { if (!DateTime.TryParse(options["datefrom"], out DateTime dateFrom)) { throw new ExportOptionException($"Incorrect dateFrom value: {options["datefrom"]}."); } exportRows = exportRows.Where(row => row.Field <DateTime>("Date").Date >= dateFrom.Date); } // dateTo: Exports all rows before this date if (options.ContainsKey("dateto")) { if (!DateTime.TryParse(options["dateto"], out DateTime dateTo)) { throw new ExportOptionException($"Incorrect dateTo value: {options["dateto"]}."); } exportRows = exportRows.Where(row => row.Field <DateTime>("Date").Date <= dateTo.Date); } } foreach (DataRow row in exportRows) { // Trajectory waypoints DataRow[] trajectoryWaypoints = row.GetChildRows(RelationLoTrajectoryLog); if (trajectoryWaypoints.Length < 1) { continue; } // Waypoint list List <wptType> wpts = new List <wptType>(); foreach (DataRow dataRow in trajectoryWaypoints) { wpts.Add(new wptType() { lon = Convert.ToDecimal(dataRow["Lon"]), lat = Convert.ToDecimal(dataRow["Lat"]), ele = Convert.ToDecimal((int)dataRow["Altitude"] / footMeterRatio), eleSpecified = true }); } // Labels and time for departure and arrival wpts[0].name = (string)row["From"]; wpts[0].time = row.Field <DateTime>("Date").ToUniversalTime(); wpts[0].timeSpecified = true; wpts[wpts.Count - 1].name = (string)row["To"]; // Track trkType trk = new trkType() { name = $"{row["From"]}>{row["To"]}", trkseg = new trksegType[1] }; trk.trkseg[0] = new trksegType() { trkpt = wpts.ToArray() }; trks.Add(trk); } // GPX object gpxType gpxData = new gpxType() { trk = trks.ToArray(), creator = "NeoFlyExport " + typeof(NeoFlyData).Assembly.GetName().Version.ToString() }; // Write to xml file XmlSerializer xmlSerializer = new XmlSerializer(typeof(gpxType)); using (var swFile = new StreamWriter(options["file"])) xmlSerializer.Serialize(swFile, gpxData); }
public void WriteGpxData(GpxFile gpxFile, string fileName) { gpxType gpx = new gpxType(); List <trkType> destTracks = new List <trkType>(); // tracks foreach (Track track in gpxFile.Tracks) { List <trksegType> destSegments = new List <trksegType>(); foreach (TrackSegment segment in track.Segments) { trksegType destSegment = new trksegType(); List <wptType> destWaypoints = new List <wptType>(); foreach (TrackPoint point in segment.Points) { destWaypoints.Add(SaveTrackPoint(point)); } destSegment.trkpt = destWaypoints.ToArray(); destSegments.Add(destSegment); } if (destSegments.Count > 0) { trkType destTrack = new trkType(); destTrack.trkseg = destSegments.ToArray(); destTracks.Add(destTrack); } } if (destTracks.Count > 0) { gpx.trk = destTracks.ToArray(); } // waypoints List <wptType> destWaypoints2 = new List <wptType>(); foreach (TrackPoint waypoint in gpxFile.Waypoints) { destWaypoints2.Add(SaveTrackPoint(waypoint)); } if (destWaypoints2.Count > 0) { gpx.wpt = destWaypoints2.ToArray(); } // routes List <rteType> destRoutes = new List <rteType>(); foreach (Track route in gpxFile.Routes) { List <wptType> destRoutePoints = new List <wptType>(); foreach (TrackSegment segment in route.Segments) { foreach (TrackPoint routePoint in segment.Points) { destRoutePoints.Add(SaveTrackPoint(routePoint)); } } if (destRoutePoints.Count > 0) { rteType destRoute = new rteType(); destRoute.rtept = destRoutePoints.ToArray(); destRoutes.Add(destRoute); } } if (destRoutes.Count > 0) { gpx.rte = destRoutes.ToArray(); } using (FileStream stream = File.Open(fileName, FileMode.Create)) { XmlSerializer serializer = new XmlSerializer(typeof(gpxType)); serializer.Serialize(stream, gpx); } }