public void GPXXmlDataWriterWriteRouteWritesRoute()
        {
            MemoryStream ms = new MemoryStream();

            GPXRoute route = new GPXRoute("ROUTE NAME");
            GPXPoint point1 = new GPXPoint(18.5, 50.1);
            GPXPoint point2 = new GPXPoint(10.3, 20.5);

            route.Nodes.Add(point1);
            route.Nodes.Add(point2);

            using (GPXXmlDataWriter target = new GPXXmlDataWriter(ms)) {
                target.WriteRoute(route);
            }

            ms.Seek(0, 0);

            XElement gpxRoot = XDocument.Load(new StreamReader(ms)).Root;
            XElement routeElement = gpxRoot.Element("rte");

            Assert.NotNull(routeElement);

            Assert.Equal(route.Name, routeElement.Element("name").Value);

            var points = routeElement.Elements("rtept").ToList();
            Assert.Equal(2, points.Count);
            Assert.Equal(point1.Latitude, double.Parse(points[0].Attribute("lat").Value, System.Globalization.CultureInfo.InvariantCulture));
            Assert.Equal(point1.Longitude, double.Parse(points[0].Attribute("lon").Value, System.Globalization.CultureInfo.InvariantCulture));
            Assert.Equal(point2.Latitude, double.Parse(points[1].Attribute("lat").Value, System.Globalization.CultureInfo.InvariantCulture));
            Assert.Equal(point2.Longitude, double.Parse(points[1].Attribute("lon").Value, System.Globalization.CultureInfo.InvariantCulture));
        }
예제 #2
0
        public void GPXSegmentTravelTimeReturnsTimeDifferenceBetweenStartAndEndPoint()
        {
            GPXPoint start = new GPXPoint(13, 15, new DateTime(2010, 5, 30, 12, 00, 00));
            GPXPoint end = new GPXPoint(13.1, 15.1, new DateTime(2010, 5, 30, 13, 05, 00));

            GPXSegment target = new GPXSegment(start, end);

            Assert.Equal(end.Time - start.Time, target.TravelTime);
        }
예제 #3
0
        public void PointGeoConstructorSetsLatitudeAndLongitude()
        {
            double lat = 10.1;
            double lon = 12.8;

            GPXPoint target = new GPXPoint(lat, lon);

            Assert.Equal(lat, target.Latitude);
            Assert.Equal(lon, target.Longitude);
        }
        public void GPXTrackSegmentConstructorAcceptsListOfGPXPoints()
        {
            GPXPoint pt1 = new GPXPoint(10.4, 5.2);
            GPXPoint pt2 = new GPXPoint(10.8, 5.3);

            GPXTrackSegment target = new GPXTrackSegment(new GPXPoint[] { pt1, pt2 });

            Assert.Equal(2, target.NodesCount);
            Assert.Equal(pt1, target.Nodes[0]);
            Assert.Equal(pt2, target.Nodes[1]);
        }
예제 #5
0
        public void PointGeoConstructorSetsLatitudeLongitudeAndTime()
        {
            double lat = 10.1;
            double lon = 12.8;
            DateTime time = new DateTime(2010, 5, 1, 13, 10, 1);

            GPXPoint target = new GPXPoint(lat, lon, time);

            Assert.Equal(lat, target.Latitude);
            Assert.Equal(lon, target.Longitude);
            Assert.Equal(time, target.Time);
        }
        public void CreateLayerAddsLayerIntoGraph()
        {
            CandidatesGraph target = new CandidatesGraph();

            GPXPoint originalPt = new GPXPoint(1, 1.1);
            CandidatePoint pt1 = new CandidatePoint() { MapPoint = new PointGeo() { Latitude = 1, Longitude = 1 } };
            CandidatePoint pt2 = new CandidatePoint() { MapPoint = new PointGeo() { Latitude = 2.1, Longitude = 2.1 } };

            target.CreateLayer(originalPt, new CandidatePoint[] { pt1, pt2 });

            Assert.Equal(1, target.Layers.Count);
            Assert.Equal(2, target.Layers[0].Candidates.Count);
        }
예제 #7
0
        public void GPXSegmentAverageSpeedReturnsAvarageSpeedOnTheSegment()
        {
            // Segment 1000 m length
            GPXPoint start = new GPXPoint(50.50673, 16.00795, new DateTime(2010, 5, 30, 12, 00, 00));
            GPXPoint end = new GPXPoint(50.51572, 16.00795, new DateTime(2010, 5, 30, 12, 02, 00));

            GPXSegment target = new GPXSegment(start, end);

            // 1km, 2 minutes => 30 km/h
            double expectedSpeed = 30;
            double error = Math.Abs(expectedSpeed - target.AverageSpeed);

            Assert.True(error < 0.1);
        }
예제 #8
0
        /// <summary>
        /// Finds all candidates points for given GPS track point
        /// </summary>
        /// <param name="gpxPt">GPS point</param>
        /// <returns>Collection of points candidate points on road segments</returns>
        public IEnumerable<CandidatePoint> FindCandidatePoints(GPXPoint gpxPt)
        {
            List<CandidatePoint> result = new List<CandidatePoint>();
            BBox gpxBbox = new BBox(new IPointGeo[] { gpxPt });
            gpxBbox.Inflate(0.0007, 0.0011);

            foreach (var road in _trackCutout) {
                if (Topology.Intersects(gpxBbox, road.BBox)) {
                    Segment<IPointGeo> roadSegment;
                    IPointGeo projectedPoint = Topology.ProjectPoint(gpxPt, road, out roadSegment);
                    result.Add(new CandidatePoint() { MapPoint = projectedPoint,
                                                        Road = road, RoadSegment = roadSegment,
                                                                                        ObservationProbability = CalculateObservationProbability(gpxPt, projectedPoint) });
                }
            }

            if (result.Count == 0) {
                throw new Exception(string.Format("Can not find any candidate point for {0}", gpxPt));
            }

            return result;
        }
 void ProcessWaypoint(GPXPoint waypoint)
 {
     _waypoints.Add(waypoint);
 }
예제 #10
0
 /// <summary>
 /// Calculates observation probability
 /// </summary>
 /// <param name="original">GPS track point</param>
 /// <param name="candidate">Candidate point</param>
 /// <returns>double representing probability that GPS track point corresponds with Candidate point</returns>
 double CalculateObservationProbability(GPXPoint original, IPointGeo candidate)
 {
     double sigma = 30;
     double distance = Calculations.GetDistance2D(original, candidate);
     return Math.Exp(-distance * distance / (2 * sigma * sigma)) / (sigma * Math.Sqrt(Math.PI * 2));
 }
예제 #11
0
        /// <summary>
        /// Reads a point from gpx document
        /// </summary>
        private GPXPoint ReadPoint()
        {
            // latitude attribute
            string lat = _xmlReader.GetAttribute("lat");

            if (string.IsNullOrEmpty(lat)) {
                throw new XmlException("Attribute 'lat' is missing.");
            }
            double pointLat = double.Parse(lat, System.Globalization.CultureInfo.InvariantCulture);

            // longitude attribute
            string lon = _xmlReader.GetAttribute("lon");

            if (string.IsNullOrEmpty(lon)) {
                throw new XmlException("Attribute 'lon' is missing.");
            }
            double pointLon = double.Parse(lon, System.Globalization.CultureInfo.InvariantCulture);

            GPXPoint parsedPoint = new GPXPoint(pointLat, pointLon);

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

                while (_xmlReader.NodeType != XmlNodeType.EndElement) {
                    if (_xmlReader.NodeType == XmlNodeType.Element) {
                        switch(_xmlReader.Name) {
                            case "ele":
                                string ele = _xmlReader.ReadString();
                                parsedPoint.Elevation = double.Parse(ele, System.Globalization.CultureInfo.InvariantCulture);
                                _xmlReader.Skip();
                                break;
                            case "time":
                                string time = _xmlReader.ReadString();
                                parsedPoint.Time = DateTime.Parse(time, System.Globalization.CultureInfo.InvariantCulture, System.Globalization.DateTimeStyles.AdjustToUniversal | System.Globalization.DateTimeStyles.AssumeUniversal);

                            //parsedPoint.Time = DateTime.ParseExact(time, "yyyy'-'MM'-'dd'T'HH':'mm':'ss'Z'", System.Globalization.CultureInfo.InvariantCulture, System.Globalization.DateTimeStyles.AdjustToUniversal | System.Globalization.DateTimeStyles.AssumeUniversal);
                                _xmlReader.Skip();
                                break;
                            case "name":
                                parsedPoint.Name = _xmlReader.ReadString();
                                _xmlReader.Skip();
                                break;
                            case "desc":
                                parsedPoint.Description = _xmlReader.ReadString();
                                _xmlReader.Skip();
                                break;
                            case "cmt":
                                parsedPoint.Commenet = _xmlReader.ReadString();
                                _xmlReader.Skip();
                                break;
                            default:
                                _xmlReader.Skip();
                                break;
                        }
                    }
                    else {
                        _xmlReader.Skip();
                    }
                }
            }

            _xmlReader.Skip();
            return parsedPoint;
        }
예제 #12
0
 /// <summary>
 /// Raises the WaypointRead event
 /// </summary>
 /// <param name="node">The waypoint read from the xml</param>
 protected void OnWaypointRead(GPXPoint waypoint)
 {
     GPXWaypointReadHandler temp = WaypointRead;
     if (temp != null) {
         temp(waypoint);
     }
 }
예제 #13
0
        /// <summary>
        /// Creates a new layer in the CandidatesGraph
        /// </summary>
        /// <param name="originalPoint">GPX track point</param>
        /// <param name="candidates">Candidate points for the original point</param>
        public void CreateLayer(GPXPoint originalPoint, IEnumerable<CandidatePoint> candidates)
        {
            CandidateGraphLayer result = new CandidateGraphLayer() { TrackPoint = originalPoint };
            result.Candidates.AddRange(candidates);

            foreach (var candidate in candidates) {
                candidate.Layer = result;
            }
            _layers.Add(result);
        }
        public void GPXXmlDataWriterWriteRouteWritesRoutePointsWithAllAttributes()
        {
            MemoryStream ms = new MemoryStream();

            GPXRoute route = new GPXRoute();

            GPXPoint point = new GPXPoint(18.5, 50.1);
            point.Elevation = 1600;
            point.Time = new DateTime(2009, 12, 31, 23, 50, 0, DateTimeKind.Utc);
            point.Name = "NAME";
            point.Description = "DESCRIPTION";
            point.Commenet = "COMMENT";

            route.Nodes.Add(point);

            using (GPXXmlDataWriter target = new GPXXmlDataWriter(ms)) {
                target.WriteRoute(route);
            }

            ms.Seek(0, 0);

            XElement gpxRoot = XDocument.Load(new StreamReader(ms)).Root;
            XElement routeElement = gpxRoot.Element("rte");

            Assert.NotNull(routeElement);

            XElement pointElement = routeElement.Element("rtept");

            Assert.NotNull(pointElement);

            Assert.Equal(point.Latitude, double.Parse(pointElement.Attribute("lat").Value, System.Globalization.CultureInfo.InvariantCulture));
            Assert.Equal(point.Longitude, double.Parse(pointElement.Attribute("lon").Value, System.Globalization.CultureInfo.InvariantCulture));
            Assert.Equal(point.Elevation, double.Parse(pointElement.Element("ele").Value, System.Globalization.CultureInfo.InvariantCulture));
            Assert.Equal(point.Time, DateTime.Parse(pointElement.Element("time").Value, System.Globalization.CultureInfo.InvariantCulture, System.Globalization.DateTimeStyles.AdjustToUniversal));
            Assert.Equal(point.Name, pointElement.Element("name").Value);
            Assert.Equal(point.Description, pointElement.Element("desc").Value);
            Assert.Equal(point.Commenet, pointElement.Element("cmt").Value);
        }
        public void GPXXmlDataWriterWriteTrackWithMultipleSegments()
        {
            MemoryStream ms = new MemoryStream();

            GPXTrack track = new GPXTrack();
            track.Name = "TRACK NAME";

            GPXPoint point1 = new GPXPoint(18.5, 50.1);
            GPXPoint point2 = new GPXPoint(10.3, 20.5);
            GPXPoint point3 = new GPXPoint(8.2, 28.8);

            GPXTrackSegment segment1 = new GPXTrackSegment();
            segment1.Nodes.Add(point1);
            segment1.Nodes.Add(point2);
            segment1.Nodes.Add(point3);
            track.Segments.Add(segment1);

            GPXTrackSegment segment2 = new GPXTrackSegment();
            segment2.Nodes.Add(point1);
            segment2.Nodes.Add(point2);
            track.Segments.Add(segment2);

            using (GPXXmlDataWriter target = new GPXXmlDataWriter(ms)) {
                target.WriteTrack(track);
            }

            ms.Seek(0, 0);

            XElement gpxRoot = XDocument.Load(new StreamReader(ms)).Root;

            XElement trackElement = gpxRoot.Element("trk");
            Assert.NotNull(trackElement);
            Assert.Equal(track.Name, trackElement.Element("name").Value);

            var trackSegments = trackElement.Elements("trkseg").ToList();
            Assert.Equal(track.Segments.Count, trackSegments.Count);

            var points = trackSegments[0].Elements("trkpt").ToList();
            Assert.Equal(track.Segments[0].NodesCount, points.Count);

            points = trackSegments[1].Elements("trkpt").ToList();
            Assert.Equal(track.Segments[1].NodesCount, points.Count);
        }
        public void GPXXmlDataWriterWriteSimpleTrack()
        {
            MemoryStream ms = new MemoryStream();

            GPXTrack track = new GPXTrack();
            track.Name = "TRACK NAME";

            GPXPoint point1 = new GPXPoint(18.5, 50.1);
            GPXPoint point2 = new GPXPoint(10.3, 20.5);

            GPXTrackSegment segment = new GPXTrackSegment();
            segment.Nodes.Add(point1);
            segment.Nodes.Add(point2);

            track.Segments.Add(segment);

            using (GPXXmlDataWriter target = new GPXXmlDataWriter(ms)) {
                target.WriteTrack(track);
            }

            ms.Seek(0, 0);

            XElement gpxRoot = XDocument.Load(new StreamReader(ms)).Root;

            XElement trackElement = gpxRoot.Element("trk");
            Assert.NotNull(trackElement);
            Assert.Equal(track.Name, trackElement.Element("name").Value);

            XElement trackSegmentElement = trackElement.Element("trkseg");
            Assert.NotNull(trackSegmentElement);

            var points = trackSegmentElement.Elements("trkpt").ToList();
            Assert.Equal(2, points.Count);
            Assert.Equal(point1.Latitude, double.Parse(points[0].Attribute("lat").Value, System.Globalization.CultureInfo.InvariantCulture));
            Assert.Equal(point1.Longitude, double.Parse(points[0].Attribute("lon").Value, System.Globalization.CultureInfo.InvariantCulture));
            Assert.Equal(point2.Latitude, double.Parse(points[1].Attribute("lat").Value, System.Globalization.CultureInfo.InvariantCulture));
            Assert.Equal(point2.Longitude, double.Parse(points[1].Attribute("lon").Value, System.Globalization.CultureInfo.InvariantCulture));
        }