public void GpxWritev1_0Test() { // instantiate and load the gpx test document. XmlStreamSource source = new XmlStreamSource( Assembly.GetExecutingAssembly().GetManifestResourceStream("OsmSharp.Test.Unittests.test.v1.0.gpx")); GpxDocument document = new GpxDocument(source); object gpx = document.Gpx; if (gpx is OsmSharp.IO.Xml.Gpx.v1_0.gpx) { // all ok here! // get the target file. MemoryStream write_file = new MemoryStream(); // create a new xml source. XmlStreamSource write_source = new XmlStreamSource(write_file); GpxDocument gpx_target = new GpxDocument(write_source); // set the target data the same as the source document. gpx_target.Gpx = gpx; // save the data. gpx_target.Save(); // close the old document. document.Close(); source.Close(); // check to see if the data was written correctly. // instantiate and load the gpx test document. source = new XmlStreamSource(write_file); document = new GpxDocument(source); gpx = document.Gpx; if (gpx is OsmSharp.IO.Xml.Gpx.v1_0.gpx) { // all ok here! OsmSharp.IO.Xml.Gpx.v1_0.gpx gpx_type = (gpx as OsmSharp.IO.Xml.Gpx.v1_0.gpx); // test the gpx test file content. Assert.IsNotNull(gpx_type.trk, "Gpx has not track!"); Assert.AreEqual(gpx_type.trk[0].trkseg.Length, 424, "Not the correct number of track segments found!"); } else { Assert.Fail("No gpx data was read, or data was of the incorrect type!"); } } else { Assert.Fail("No gpx data was read, or data was of the incorrect type!"); } document.Close(); source.Close(); }
public void GpxReadv1_0Test() { // instantiate and load the gpx test document. XmlStreamSource source = new XmlStreamSource( Assembly.GetExecutingAssembly().GetManifestResourceStream("OsmSharp.Test.Unittests.test.v1.0.gpx")); GpxDocument document = new GpxDocument(source); object gpx = document.Gpx; if (gpx is OsmSharp.IO.Xml.Gpx.v1_0.gpx) { // all ok here! OsmSharp.IO.Xml.Gpx.v1_0.gpx gpx_type = (gpx as OsmSharp.IO.Xml.Gpx.v1_0.gpx); // test the gpx test file content. Assert.IsNotNull(gpx_type.trk, "Gpx has no track!"); Assert.AreEqual(gpx_type.trk[0].trkseg.Length, 424, "Not the correct number of track segments found!"); } else { Assert.Fail("No gpx data was read, or data was of the incorrect type!"); } document.Close(); source.Close(); }
/// <summary> /// Reads a gpx v1.0 object into corresponding geometries. /// </summary> /// <param name="gpx"></param> private void ReadGpxv1_0(OsmSharp.IO.Xml.Gpx.v1_0.gpx gpx) { this.FeatureCollection.Clear(); // do the waypoints. if (gpx.wpt != null) { // there are waypoints. foreach (var wpt in gpx.wpt) { var point = new Feature(new Point(new GeoCoordinate((double)wpt.lat, (double)wpt.lon))); if (wpt.ageofdgpsdataSpecified) { point.Attributes.Add("ageofdgpsdata", wpt.ageofdgpsdata); } if (wpt.eleSpecified) { point.Attributes.Add("ele", wpt.ele); } if (wpt.fixSpecified) { point.Attributes.Add("fix", wpt.fix); } if (wpt.geoidheightSpecified) { point.Attributes.Add("geoidheight", wpt.geoidheight); } if (wpt.hdopSpecified) { point.Attributes.Add("hdop", wpt.hdop); } if (wpt.magvarSpecified) { point.Attributes.Add("magvar", wpt.magvar); } if (wpt.pdopSpecified) { point.Attributes.Add("pdop", wpt.pdop); } if (wpt.timeSpecified) { point.Attributes.Add("time", wpt.time); } if (wpt.vdopSpecified) { point.Attributes.Add("vdop", wpt.vdop); } if (wpt.Any != null) { point.Attributes.Add("Any", wpt.Any); } if (wpt.cmt != null) { point.Attributes.Add("cmt", wpt.cmt); } if (wpt.desc != null) { point.Attributes.Add("desc", wpt.desc); } if (wpt.dgpsid != null) { point.Attributes.Add("dgpsid", wpt.dgpsid); } if (wpt.name != null) { point.Attributes.Add("name", wpt.name); } if (wpt.sat != null) { point.Attributes.Add("sat", wpt.sat); } if (wpt.src != null) { point.Attributes.Add("src", wpt.src); } if (wpt.sym != null) { point.Attributes.Add("sym", wpt.sym); } if (wpt.url != null) { point.Attributes.Add("url", wpt.url); } if (wpt.urlname != null) { point.Attributes.Add("urlname", wpt.urlname); } if (wpt.type != null) { point.Attributes.Add("type", wpt.type); } this.FeatureCollection.Add(point); } } // do the routes. if (gpx.rte != null) { foreach (var rte in gpx.rte) { // convert to a line-string var coordinates = new List <GeoCoordinate>(); foreach (var rtept in rte.rtept) { var coordinate = new GeoCoordinate((double)rtept.lat, (double)rtept.lon); coordinates.Add(coordinate); if (_createTrackPoints) { var point = new Feature(new Point(coordinate)); if (rtept.ageofdgpsdataSpecified) { point.Attributes.Add("ageofdgpsdata", rtept.ageofdgpsdata); } if (rtept.eleSpecified) { point.Attributes.Add("ele", rtept.ele); } if (rtept.fixSpecified) { point.Attributes.Add("fix", rtept.fix); } if (rtept.geoidheightSpecified) { point.Attributes.Add("geoidheight", rtept.geoidheight); } if (rtept.hdopSpecified) { point.Attributes.Add("hdop", rtept.hdop); } if (rtept.magvarSpecified) { point.Attributes.Add("magvar", rtept.magvar); } if (rtept.pdopSpecified) { point.Attributes.Add("pdop", rtept.pdop); } if (rtept.timeSpecified) { point.Attributes.Add("time", rtept.time); } if (rtept.vdopSpecified) { point.Attributes.Add("vdop", rtept.vdop); } if (rtept.Any != null) { point.Attributes.Add("Any", rtept.Any); } if (rtept.cmt != null) { point.Attributes.Add("cmt", rtept.cmt); } if (rtept.desc != null) { point.Attributes.Add("desc", rtept.desc); } if (rtept.dgpsid != null) { point.Attributes.Add("dgpsid", rtept.dgpsid); } if (rtept.name != null) { point.Attributes.Add("name", rtept.name); } if (rtept.sat != null) { point.Attributes.Add("sat", rtept.sat); } if (rtept.src != null) { point.Attributes.Add("src", rtept.src); } if (rtept.sym != null) { point.Attributes.Add("sym", rtept.sym); } if (rtept.url != null) { point.Attributes.Add("url", rtept.url); } if (rtept.urlname != null) { point.Attributes.Add("urlname", rtept.urlname); } if (rtept.type != null) { point.Attributes.Add("type", rtept.type); } this.FeatureCollection.Add(point); } } // creates a new linestring. var lineString = new Feature(new LineString(coordinates)); if (rte.Any != null) { lineString.Attributes.Add("Any", rte.Any); } if (rte.cmt != null) { lineString.Attributes.Add("cmt", rte.cmt); } if (rte.desc != null) { lineString.Attributes.Add("desc", rte.desc); } if (rte.name != null) { lineString.Attributes.Add("name", rte.name); } if (rte.number != null) { lineString.Attributes.Add("number", rte.number); } if (rte.src != null) { lineString.Attributes.Add("src", rte.src); } if (rte.url != null) { lineString.Attributes.Add("url", rte.url); } if (rte.urlname != null) { lineString.Attributes.Add("urlname", rte.urlname); } this.FeatureCollection.Add(lineString); } } // do the tracks. foreach (var trk in gpx.trk) { // convert to a line-string List <GeoCoordinate> coordinates = new List <GeoCoordinate>(); foreach (var trkseg in trk.trkseg) { GeoCoordinate coordinate = new GeoCoordinate((double)trkseg.lat, (double)trkseg.lon); coordinates.Add(coordinate); if (_createTrackPoints) { var point = new Feature(new Point(coordinate)); if (trkseg.ageofdgpsdataSpecified) { point.Attributes.Add("ageofdgpsdata", trkseg.ageofdgpsdata); } if (trkseg.eleSpecified) { point.Attributes.Add("ele", trkseg.ele); } if (trkseg.fixSpecified) { point.Attributes.Add("fix", trkseg.fix); } if (trkseg.geoidheightSpecified) { point.Attributes.Add("geoidheight", trkseg.geoidheight); } if (trkseg.hdopSpecified) { point.Attributes.Add("hdop", trkseg.hdop); } if (trkseg.magvarSpecified) { point.Attributes.Add("magvar", trkseg.magvar); } if (trkseg.pdopSpecified) { point.Attributes.Add("pdop", trkseg.pdop); } if (trkseg.timeSpecified) { point.Attributes.Add("time", trkseg.time); } if (trkseg.vdopSpecified) { point.Attributes.Add("vdop", trkseg.vdop); } if (trkseg.Any != null) { point.Attributes.Add("Any", trkseg.Any); } if (trkseg.cmt != null) { point.Attributes.Add("cmt", trkseg.cmt); } if (trkseg.desc != null) { point.Attributes.Add("desc", trkseg.desc); } if (trkseg.dgpsid != null) { point.Attributes.Add("dgpsid", trkseg.dgpsid); } if (trkseg.name != null) { point.Attributes.Add("name", trkseg.name); } if (trkseg.sat != null) { point.Attributes.Add("sat", trkseg.sat); } if (trkseg.src != null) { point.Attributes.Add("src", trkseg.src); } if (trkseg.sym != null) { point.Attributes.Add("sym", trkseg.sym); } if (trkseg.url != null) { point.Attributes.Add("url", trkseg.url); } if (trkseg.urlname != null) { point.Attributes.Add("urlname", trkseg.urlname); } if (trkseg.type != null) { point.Attributes.Add("type", trkseg.type); } this.FeatureCollection.Add(point); } } // creates a new linestring. var lineString = new Feature(new LineString(coordinates)); if (trk.Any != null) { lineString.Attributes.Add("Any", trk.Any); } if (trk.cmt != null) { lineString.Attributes.Add("cmt", trk.cmt); } if (trk.desc != null) { lineString.Attributes.Add("desc", trk.desc); } if (trk.name != null) { lineString.Attributes.Add("name", trk.name); } if (trk.number != null) { lineString.Attributes.Add("number", trk.number); } if (trk.src != null) { lineString.Attributes.Add("src", trk.src); } if (trk.url != null) { lineString.Attributes.Add("url", trk.url); } if (trk.urlname != null) { lineString.Attributes.Add("urlname", trk.urlname); } this.FeatureCollection.Add(lineString); } }