コード例 #1
0
ファイル: GpxDataSource.cs プロジェクト: jorik041/osmsharp
        /// <summary>
        /// Creates a new osm data source.
        /// </summary>
        /// <param name="document"></param>
        public GpxDataSource(GpxDocument document)
        {
            _document = document;
            _id = Guid.NewGuid();

            _read = false;
            _nodes = new Dictionary<long, Node>();
            _ways = new Dictionary<long, Way>();
            _relations = new Dictionary<long, Relation>();

            _ways_per_node = new Dictionary<long, List<long>>();
            _relations_per_member = new Dictionary<long, List<long>>();
        }
コード例 #2
0
ファイル: GpxXmlTest.cs プロジェクト: jorik041/osmsharp
        public void GpxReadv1_0Test()
        {
            // instantiate and load the gpx test document.
            XmlStreamSource source = new XmlStreamSource(
                Assembly.GetExecutingAssembly().GetManifestResourceStream("OsmSharp.UnitTests.test.v1.0.gpx"));
            GpxDocument document = new GpxDocument(source);
            object gpx = document.Gpx;

            if (gpx is OsmSharp.Tools.Xml.Gpx.v1_0.gpx)
            { // all ok here!
                OsmSharp.Tools.Xml.Gpx.v1_0.gpx gpx_type = (gpx as OsmSharp.Tools.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!");
            }

            document.Close();
            source.Close();
        }
コード例 #3
0
ファイル: OsmSharpRouteGpx.cs プロジェクト: jorik041/osmsharp
        /// <summary>
        /// Saves the route to a gpx file.
        /// </summary>
        /// <param name="file"></param>
        /// <param name="route"></param>
        internal static void Save(FileInfo file, OsmSharpRoute route)
        {
            XmlFileSource source = new XmlFileSource(file);
            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();
        }