Esempio n. 1
0
        public void Constructor_Segments_CreateGpxTrackWithSegments()
        {
            GpxTrackSegment[] segments = new GpxTrackSegment[] { new GpxTrackSegment(), new GpxTrackSegment(), new GpxTrackSegment() };

            GpxTrack target = new GpxTrack(segments);

            Assert.Equal(segments.Length, target.Geometries.Count);
            for (int i = 0; i < target.Geometries.Count; i++) {
                Assert.Same(segments[i], target.Geometries[i]);
            }
        }
Esempio n. 2
0
        public void Constructor_Segments_CreateGpxTrackWithSegments()
        {
            GpxTrackSegment[] segments = new GpxTrackSegment[] { new GpxTrackSegment(), new GpxTrackSegment(), new GpxTrackSegment() };

            GpxTrack target = new GpxTrack(segments);

            Assert.Equal(segments.Length, target.Geometries.Count);
            for (int i = 0; i < target.Geometries.Count; i++)
            {
                Assert.Same(segments[i], target.Geometries[i]);
            }
        }
Esempio n. 3
0
        public void Read_ParsesTrackWithSingleSegmentAndExtensions()
        {
            MemoryStream data = new MemoryStream(GpxTestData.gpx_track_single_track_segment);

            GpxReader target = new GpxReader(data, new GpxReaderSettings()
            {
                ReadMetadata = false
            });
            var result = target.Read() as GpxTrack;

            Assert.Equal(1, result.Geometries.Count);

            GpxTrackSegment segment = result.Geometries[0];
        }
Esempio n. 4
0
        public void Read_ParsesTrackWithSingleSegmentAndExtensions()
        {
            var data = TestDataReader.Open("gpx-track-single-track-segment.gpx");

            GpxReader target = new GpxReader(data, new GpxReaderSettings()
            {
                ReadMetadata = false
            });
            var result = target.Read() as GpxTrack;

            Assert.Single(result.Geometries);

            GpxTrackSegment segment = result.Geometries[0];
        }
        public void Constructor_IEnumerablePoints_CreatesGpsTrackWithPoints()
        {
            List<GpxPoint> points = new List<GpxPoint> {
            new GpxPoint(16.5, 45.9, 100, new DateTime(2011, 2, 24, 20, 00, 00)),
            new GpxPoint(16.6, 46.0, 110, new DateTime(2011, 2, 24, 20, 00, 10)),
            new GpxPoint(16.5, 46.1, 200, new DateTime(2011, 2, 24, 20, 00, 20))};

            GpxTrackSegment target = new GpxTrackSegment(points);

            Assert.Equal(points.Count, target.Points.Count);
            for (int i = 0; i < target.Points.Count; i++) {
                Assert.Same(points[i], target.Points[i]);
            }
        }
Esempio n. 6
0
        private static void AddTrackSegment(SqlGeographyBuilder builder, GpxTrackSegment segment)
        {
            builder.BeginGeography(OpenGisGeographyType.LineString);

            builder.BeginFigure(segment.TrackPoints[0].Latitude, segment.TrackPoints[0].Longitude);

            for (int i = 1; i < segment.TrackPoints.Count; i++)
            {
                builder.AddLine(segment.TrackPoints[i].Latitude, segment.TrackPoints[i].Longitude);
            }

            builder.EndFigure();

            builder.EndGeography();
        }
Esempio n. 7
0
        public void Constructor_IEnumerablePoints_CreatesGpsTrackWithPoints()
        {
            List <GpxPoint> points = new List <GpxPoint> {
                new GpxPoint(16.5, 45.9, 100, new DateTime(2011, 2, 24, 20, 00, 00)),
                new GpxPoint(16.6, 46.0, 110, new DateTime(2011, 2, 24, 20, 00, 10)),
                new GpxPoint(16.5, 46.1, 200, new DateTime(2011, 2, 24, 20, 00, 20))
            };

            GpxTrackSegment target = new GpxTrackSegment(points);

            Assert.Equal(points.Count, target.Points.Count);
            for (int i = 0; i < target.Points.Count; i++)
            {
                Assert.Same(points[i], target.Points[i]);
            }
        }
Esempio n. 8
0
        public static TrackSegment Create(GpxTrackSegment gpxTrackSegment)
        {
            var trackSegment = new TrackSegment();
            List <TrackPoint> trackPoints = new List <TrackPoint>();

            foreach (var point in gpxTrackSegment.TrackPoints)
            {
                trackPoints.Add(TrackPoint.Create(point));
            }
            trackSegment.TrackPoints = trackPoints;
            trackSegment.Elevation   = ElevationProcessor.SegmentElevation(trackPoints);
            trackSegment.Duration    = DurationProcessor.SegmentDuration(trackPoints);
            trackSegment.Distance    = DistanceProcessor.SegmentDistance(trackPoints);

            return(trackSegment);
        }
Esempio n. 9
0
        private GpxTrackSegment ReadGpxTrackSegment()
        {
            GpxTrackSegment segment = new GpxTrackSegment();

            if (reader.IsEmptyElement)
            {
                return(segment);
            }

            string elementName = reader.Name;

            while (reader.Read())
            {
                switch (reader.NodeType)
                {
                case XmlNodeType.Element:

                    switch (reader.Name)
                    {
                    case GpxSymbol.TrackPoint:
                        segment.Add(ReadGpxTrackPoint());
                        break;

                    case "extensions":
                        ReadTrackSegmentExtensions();
                        break;

                    default:
                        reader.SkipElement();
                        break;
                    }

                    break;

                case XmlNodeType.EndElement:
                    if (reader.Name != elementName)
                    {
                        throw new FormatException(reader.Name);
                    }
                    return(segment);
                }
            }

            throw new FormatException(elementName);
        }
Esempio n. 10
0
        public static SqlGeography AsGeography(this GpxTrackSegment trackSegment)
        {
            SqlGeographyBuilder builder = new SqlGeographyBuilder();

            builder.SetSrid(SridHelper.GeodeticWGS84);

            //builder.BeginGeography(OpenGisGeographyType.LineString);
            if (trackSegment.TrackPoints.Count < 2)
            {
                return(null);
            }

            AddTrackSegment(builder, trackSegment);

            //builder.EndGeography();

            return(builder.ConstructedGeography.STIsValid().Value ? builder.ConstructedGeography : builder.ConstructedGeography.MakeValid());
        }
Esempio n. 11
0
        private bool isOnTrack(IGeoPoint point, float accuracy, out double dist)
        {
            Stopwatch watch = new Stopwatch();

            watch.Start();
            dist = double.MaxValue;
            int closest_track   = 0;
            int closest_segment = 0;

            //float accuracy_offset = Math.Max(0, location.Accuracy-statistics.Accuracy);

            for (int t = 0; t < trackSegments.Value.Count; ++t)
            {
                GpxTrackSegment seg = trackSegments.Value[t];
                for (int s = seg.TrackPoints.Count - 1; s > 0; --s)
                {
                    double d = Math.Max(0, point.GetDistanceToArcSegment(seg.TrackPoints[s - 1],
                                                                         seg.TrackPoints[s]).Meters - accuracy);

                    if (dist > d)
                    {
                        dist            = d;
                        closest_segment = s;
                        closest_track   = t;
                    }
                    if (d <= prefs.Value.OffTrackAlarmDistance)
                    {
                        watch.Stop();
                        logDebug(LogLevel.Verbose, $"On [{s}]" + d.ToString("0.0") + " (" + seg.TrackPoints[s - 1].ToString(geoPointFormat) + " -- "
                                 + seg.TrackPoints[s].ToString(geoPointFormat) + ") in " + watch.Elapsed.ToString());
                        dist = -dist;
                        return(true);
                    }
                }
            }


            watch.Stop();
            this.serviceLog.Value.WriteLine(LogLevel.Verbose, $"dist {dist.ToString("0.0")} point {point.ToString(geoPointFormat)}"
                                            + $" segment {trackSegments.Value[closest_track].TrackPoints[closest_segment - 1].ToString(geoPointFormat)}"
                                            + $" -- {trackSegments.Value[closest_track].TrackPoints[closest_segment].ToString(geoPointFormat)}");
            logDebug(LogLevel.Verbose, $"Off [{closest_segment}]" + dist.ToString("0.0") + " in " + watch.Elapsed.ToString());
            return(false);
        }
Esempio n. 12
0
        public static List <GpxTrack> Convert(string xmlFilePath)
        {
            List <GpxTrack> result = new List <GpxTrack>();

            string      xmlContent = File.ReadAllText(xmlFilePath);
            XmlDocument doc        = new XmlDocument();

            doc.LoadXml(xmlContent);    // full document
            if (doc.HasChildNodes)
            {
                var gpx = doc.GetElementsByTagName("gpx");
                foreach (XmlNode gpxNode in gpx)
                {
                    GpxTrack track = new GpxTrack();
                    track.Track = new List <GpxTrackSegment>();
                    XmlNode metadata = GetChild(gpxNode, "metadata");
                    track.StartTime = GetChildValue(metadata, "time");

                    var tracks = GetChildren(gpxNode, "trk");
                    foreach (XmlNode trkNode in tracks)
                    {
                        var seg = GetChildren(trkNode, "trkseg");
                        foreach (XmlNode segNode in seg)
                        {
                            GpxTrackSegment segment = new GpxTrackSegment();
                            segment.Track = new List <GpxTrackpoint>();
                            var trackpoints = GetChildren(segNode, "trkpt");

                            foreach (XmlNode trackpointNode in trackpoints)
                            {
                                var trackpoint = LoadTrackpoint(trackpointNode);
                                segment.Track.Add(trackpoint);
                            }

                            track.Track.Add(segment);
                        }
                    }
                    result.Add(track);
                }
            }

            return(result);
        }
Esempio n. 13
0
        /// <summary>
        /// Reades a GPX track from the internal XmlReader
        /// </summary>
        /// <returns>the track parsed form the XmlReader</returns>
        private GpxTrack ReadTrack()
        {
            GpxTrack result = new GpxTrack();

            if (_xmlReader.IsEmptyElement == false)
            {
                _xmlReader.Read();

                GpxTrackMetadata metadata = null;
                if (this.Settings.ReadMetadata)
                {
                    metadata = new GpxTrackMetadata();
                }

                while ((_xmlReader.NodeType == XmlNodeType.EndElement && _xmlReader.Name == "trk") == false)
                {
                    bool elementParsed = false;
                    if (_xmlReader.Name == "trkseg")
                    {
                        GpxTrackSegment segment = ReadTrackSegment();
                        result.Geometries.Add(segment);
                        elementParsed = true;
                    }

                    if (this.Settings.ReadMetadata)
                    {
                        elementParsed = elementParsed || this.TryReadTrackMetadata(metadata);
                    }

                    if (!elementParsed)
                    {
                        _xmlReader.Skip();
                    }
                }

                result.Metadata = metadata;
            }
            _xmlReader.Skip();

            return(result);
        }
Esempio n. 14
0
        /// <summary>
        /// Tracks mit mehreren Segmenten splitten
        /// </summary>
        public void Segment2Track2()
        {
            int trackcount = TrackCount();

            for (int t = 0; t < trackcount; t++)
            {
                int tracksegmentcount = TrackSegmentCount(t);
                if (tracksegmentcount > 1)
                {
                    GpxTrack tr = GetPoorTrack(t, true);
                    if (tr == null)
                    {
                        tr = new GpxTrack {
                            Name = GetTrackname(t)
                        };

                        while (TrackSegmentCount(t) > 1)
                        {
                            GpxTrackSegment ts = new GpxTrackSegment();
                            ts.Points.AddRange(GetTrackSegmentPointList(t, 1));
                            tr.Segments.Add(ts);
                        }
                    }
                    while (TrackSegmentCount(t) > 1)
                    {
                        DeleteSegment(t, 1);
                    }

                    for (int s = 0; s < tr.Segments.Count; s++)
                    {
                        GpxTrack newtr = new GpxTrack();
                        newtr.Segments.Add(tr.Segments[s]);
                        newtr.Name = CreateUniqueObjectName(newtr.Name, ObjectType.Track);
                        InsertTrack(t + 1 + s, newtr);
                    }

                    t          += tracksegmentcount - 1;
                    trackcount += tracksegmentcount - 1;
                }
            }
        }
Esempio n. 15
0
        public void Read_ParsesTrackWithSingleSegment()
        {
            var data = TestDataReader.Open("gpx-track-single-track-segment.gpx");

            GpxReader target = new GpxReader(data, new GpxReaderSettings()
            {
                ReadMetadata = false
            });
            var result = target.Read() as GpxTrack;

            Assert.Single(result.Geometries);

            GpxTrackSegment segment = result.Geometries[0];

            Assert.Equal(new Coordinate(-76.638178825, 39.449270368), segment.Points[0].Position);
            Assert.Equal(new DateTime(1970, 1, 1, 7, 10, 23, DateTimeKind.Utc), segment.Points[0].Timestamp);
            Assert.Equal(new Coordinate(-76.638012528, 39.449130893), segment.Points[1].Position);
            Assert.Equal(new DateTime(1970, 1, 1, 7, 10, 28, DateTimeKind.Utc), segment.Points[1].Timestamp);
            Assert.Equal(new Coordinate(-76.637980342, 39.449098706), segment.Points[2].Position);
            Assert.Equal(new DateTime(1970, 1, 1, 7, 10, 33, DateTimeKind.Utc), segment.Points[2].Timestamp);
        }
Esempio n. 16
0
        public void Read_ParsesTrackWithSingleSegment()
        {
            MemoryStream data = new MemoryStream(GpxTestData.gpx_track_single_track_segment);

            GpxReader target = new GpxReader(data, new GpxReaderSettings()
            {
                ReadMetadata = false
            });
            var result = target.Read() as GpxTrack;

            Assert.Equal(1, result.Geometries.Count);

            GpxTrackSegment segment = result.Geometries[0];

            Assert.Equal(new Coordinate(-76.638178825, 39.449270368), segment.Points[0].Position);
            Assert.Equal(new DateTime(1970, 1, 1, 7, 10, 23, DateTimeKind.Utc), segment.Points[0].Timestamp);
            Assert.Equal(new Coordinate(-76.638012528, 39.449130893), segment.Points[1].Position);
            Assert.Equal(new DateTime(1970, 1, 1, 7, 10, 28, DateTimeKind.Utc), segment.Points[1].Timestamp);
            Assert.Equal(new Coordinate(-76.637980342, 39.449098706), segment.Points[2].Position);
            Assert.Equal(new DateTime(1970, 1, 1, 7, 10, 33, DateTimeKind.Utc), segment.Points[2].Timestamp);
        }
Esempio n. 17
0
        public void Constructor_CreatesEmptyGpsTrack()
        {
            GpxTrackSegment target = new GpxTrackSegment();

            Assert.Empty(target.Points);
        }
 public LoadedGpxFileTourSegmentInfo(GpxTrackSegment trackSegment)
 {
     this.Points = trackSegment.Points;
 }
Esempio n. 19
0
        /// <summary>
        /// Reads a GPX traxk segment from the intrnal XmlReader.
        /// </summary>
        /// <returns>the track parsed from the XmlReader</returns>
        private GpxTrackSegment ReadTrackSegment()
        {
            GpxTrackSegment result = new GpxTrackSegment();

            if (_xmlReader.IsEmptyElement == false) {
                _xmlReader.Read();

                while ((_xmlReader.NodeType == XmlNodeType.EndElement && _xmlReader.Name == "trkseg") == false) {
                    if (_xmlReader.Name == "trkpt") {
                        GpxPoint point = ReadPoint("trkpt");
                        result.Points.Add(point);
                    } else {
                        _xmlReader.Skip();
                    }
                }
            }
            _xmlReader.Skip();

            return result;
        }
Esempio n. 20
0
        private GpxTrackSegment ReadGpxTrackSegment(XmlReader reader)
        {
            GpxTrackSegment segment = new GpxTrackSegment();
            if (reader.IsEmptyElement) return segment;

            string elementName = reader.Name;

            while (reader.Read())
            {
                switch (reader.NodeType)
                {
                    case XmlNodeType.Element:

                        switch (reader.Name)
                        {
                            case "trkpt":
                                segment.TrackPoints.Add(ReadGpxTrackPoint(reader));
                                break;
                            case "extensions":
                                ReadTrackSegmentExtensions(reader);
                                break;
                            default:
                                throw new FormatException(reader.Name);
                        }

                        break;

                    case XmlNodeType.EndElement:
                        if (reader.Name != elementName) throw new FormatException(reader.Name);
                        return segment;
                }
            }

            throw new FormatException(elementName);
        }
Esempio n. 21
0
        private void WriteTrackSegment(string elementName, GpxTrackSegment segment)
        {
            Writer_.WriteStartElement(elementName);

            foreach (GpxTrackPoint trackPoint in segment.TrackPoints)
            {
                WriteTrackPoint("trkpt", trackPoint);
            }

            Writer_.WriteEndElement();
        }
        public void Constructor_CreatesEmptyGpsTrack()
        {
            GpxTrackSegment target = new GpxTrackSegment();

            Assert.Empty(target.Points);
        }