I am looking for a C# library or class to help write GPX files from a collection of waypoints I have (lat/long, etc).
I have found quite a few readers - but not so much for writing.
Bonus points if it works on Compact Framework/WinMobile 6.5 - but that is not a hard requirement. I can make it work on 开发者_如何学JAVAa desktop doing post-processing - the Mobile device does not have to build these files.
Does anyone know of some, or a simple way to write the files?
Have you taken a look at OGL (Open GPS-LBS)?
From the class docs:
This GPX class provide converts GPS data(waypoints, routes, and tracks) to be compatible with GPX format file.
Regarding the Windows Mobile note, the library supports:
"...applications on PC(Windows) or PocketPC(CE)."
The simplest (as in most lo-fi, not most time-efficient) way is opening any gpx file in a text editor and pasting your coordinates in the correct spot, or writing a new one as below. GPX is a type of XML-file, so if you know some HTML, it's easy to pick up on.
The most basic format that I can open (using GPX Viewer on Android) is
<?xml version="1.0" encoding="UTF-8" standalone="no" ?>
<gpx>
<!--Waypoint 1-->
<wpt lat="50.888090" lon="4.698118">
</wpt>
<!--Waypoint 2-->
<wpt lat="50.788090" lon="4.798118">
</wpt>
<!--etc-->
<wpt lat="50.988090" lon="4.618118">
</wpt>
</gpx>
Add or remove waypoints to taste.
Similar things can be done for tracks and routes, and you can add a lot more information like elevation and time, but you'll have to google for GPX documentation for that.
Take a look at https://nettopologysuite.github.io/
It has a GPXFile class https://nettopologysuite.github.io/NetTopologySuite.IO.GPX/
A pretty simple way to generate using pure c#:
using System;
using System.Collections.Generic;
public class Program
{
public static void Main()
{
List<int> heartRateList = new List<int>() { 80, 81, 82 };
List<DateTime> timeList = new List<DateTime>() { DateTime.Now.AddSeconds(1), DateTime.Now.AddSeconds(2), DateTime.Now.AddSeconds(3) };
string trkpt = "";
for(int c = 0; c < heartRateList.Count; c++)
{
trkpt += "<trkpt>"
+ "<time>" + timeList[c].ToString("s") + "Z</time>"
+ "<extensions>"
+ "<gpxtpx:TrackPointExtension>"
+ "<gpxtpx:hr>" + heartRateList[c] + "</gpxtpx:hr>"
+ "</gpxtpx:TrackPointExtension>"
+ "</extensions>"
+ "</trkpt>";
}
string gpx = "<?xml version=\"1.0\" encoding=\"utf-8\"?>"
+ "<gpx xmlns=\"http://www.topografix.com/GPX/1/1\" xmlns:gpxtpx=\"http://www.garmin.com/xmlschemas/TrackPointExtension/v1\" xmlns:gpxx=\"http://www.garmin.com/xmlschemas/GpxExtensions/v3\" xmlns:ns1=\"http://www.cluetrust.com/XML/GPXDATA/1/0\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" creator=\"Zamfit\" version=\"1.3\" xsi:schemaLocation=\"http://www.topografix.com/GPX/1/1 http://www.topografix.com/GPX/1/1/gpx.xsd http://www.garmin.com/xmlschemas/GpxExtensions/v3 http://www.garmin.com/xmlschemas/GpxExtensionsv3.xsd http://www.garmin.com/xmlschemas/TrackPointExtension/v1 http://www.garmin.com/xmlschemas/TrackPointExtensionv1.xsd\">"
+ "<metadata><time>2022-01-01T00:00:00Z</time></metadata>"
+ "<trk>"
+ "<name>Activity Name</name>"
+ "<trkseg>"
+ trkpt
+ "</trkseg>"
+ "</trk>"
+ "</gpx>";
Console.WriteLine(gpx);
}
}
精彩评论