Esempio n. 1
0
        private static void ReadWaypoint(XmlReader reader, GpxReaderSettings settings, GpxVisitorBase visitor)
        {
            var element  = (XElement)XNode.ReadFrom(reader);
            var waypoint = GpxWaypoint.Load(element, settings, settings.ExtensionReader.ConvertWaypointExtensionElement);

            visitor.VisitWaypoint(waypoint);
        }
Esempio n. 2
0
        public void RoundTripForValuesVeryNearZeroShouldSucceed()
        {
            var expectedWaypoint = new GpxWaypoint(new GpxLongitude(0.00001), new GpxLatitude(double.Epsilon), -double.Epsilon);
            var file             = new GpxFile
            {
                Waypoints = { expectedWaypoint },
            };

            file = GpxFile.Parse(file.BuildString(null), null);

            var actualWaypoint = Assert.Single(file.Waypoints);

            Assert.Equal(expectedWaypoint, actualWaypoint);
        }
        /// <summary>
        /// Creates an <see cref="IPoint"/> <see cref="Feature"/> that contains the same data stored
        /// in a given <see cref="GpxWaypoint"/>.
        /// </summary>
        /// <param name="waypoint">
        /// The <see cref="GpxWaypoint"/> source.
        /// </param>
        /// <param name="geometryFactory">
        /// The <see cref="IGeometryFactory"/> to use to create the <see cref="IPoint"/>, or
        /// <see langword="null"/> to create a new one to use on-the-fly using the current
        /// <see cref="GeometryServiceProvider"/>.
        /// </param>
        /// <returns>
        /// A <see cref="Feature"/> that contains the same data as <paramref name="waypoint"/>.
        /// </returns>
        /// <exception cref="ArgumentNullException">
        /// Thrown when <paramref name="waypoint"/> is <see langword="null"/>
        /// </exception>
        /// <remarks>
        /// The values of <see cref="Feature.Attributes"/> will be populated with the values of the
        /// <see cref="GpxWaypoint"/> properties, even when <see langword="null"/>, with exceptions:
        /// <list type="bullet">
        /// <item><description><see cref="GpxWaypoint.Longitude"/> goes to <see cref="IPoint.X"/> instead,</description></item>
        /// <item><description><see cref="GpxWaypoint.Latitude"/> goes to <see cref="IPoint.Y"/> instead, and</description></item>
        /// <item><description><see cref="GpxWaypoint.ElevationInMeters"/> goes to <see cref="IPoint.Z"/> instead (when it's set)</description></item>
        /// </list>
        /// </remarks>
        public static Feature ToFeature(GpxWaypoint waypoint, IGeometryFactory geometryFactory)
        {
            if (waypoint is null)
            {
                throw new ArgumentNullException(nameof(waypoint));
            }

            if (geometryFactory is null)
            {
                geometryFactory = GeometryServiceProvider.Instance.CreateGeometryFactory();
            }

            // a waypoint all on its own is an IPoint feature.
            var coord      = new Coordinate(waypoint.Longitude, waypoint.Latitude, waypoint.ElevationInMeters ?? Coordinate.NullOrdinate);
            var point      = geometryFactory.CreatePoint(coord);
            var attributes = new AttributesTable
            {
                { nameof(waypoint.TimestampUtc), waypoint.TimestampUtc },
                { nameof(waypoint.Name), waypoint.Name },
                { nameof(waypoint.Description), waypoint.Description },
                { nameof(waypoint.SymbolText), waypoint.SymbolText },
                { nameof(waypoint.MagneticVariation), waypoint.MagneticVariation },
                { nameof(waypoint.GeoidHeight), waypoint.GeoidHeight },
                { nameof(waypoint.Comment), waypoint.Comment },
                { nameof(waypoint.Source), waypoint.Source },
                { nameof(waypoint.Links), waypoint.Links },
                { nameof(waypoint.Classification), waypoint.Classification },
                { nameof(waypoint.FixKind), waypoint.FixKind },
                { nameof(waypoint.NumberOfSatellites), waypoint.NumberOfSatellites },
                { nameof(waypoint.HorizontalDilutionOfPrecision), waypoint.HorizontalDilutionOfPrecision },
                { nameof(waypoint.VerticalDilutionOfPrecision), waypoint.VerticalDilutionOfPrecision },
                { nameof(waypoint.PositionDilutionOfPrecision), waypoint.PositionDilutionOfPrecision },
                { nameof(waypoint.SecondsSinceLastDgpsUpdate), waypoint.SecondsSinceLastDgpsUpdate },
                { nameof(waypoint.DgpsStationId), waypoint.DgpsStationId },
                { nameof(waypoint.Extensions), waypoint.Extensions },
            };

            return(new Feature(point, attributes));
        }