Exemplo n.º 1
0
        private static void ReadTrack(XmlReader reader, GpxReaderSettings settings, GpxVisitorBase visitor)
        {
            var element = (XElement)XNode.ReadFrom(reader);
            var track   = GpxTrack.Load(element, settings);

            visitor.VisitTrack(track);
        }
        /// <summary>
        /// Creates an <see cref="IMultiLineString"/> <see cref="Feature"/> that contains the same data
        /// stored in a given <see cref="GpxTrack"/>.
        /// </summary>
        /// <param name="track">
        /// The <see cref="GpxTrack"/> source.
        /// </param>
        /// <param name="geometryFactory">
        /// The <see cref="IGeometryFactory"/> to use to create the <see cref="IMultiLineString"/>,
        /// 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="track"/>.
        /// </returns>
        /// <exception cref="ArgumentNullException">
        /// Thrown when <paramref name="track"/> is <see langword="null"/>
        /// </exception>
        /// <remarks>
        /// The values of <see cref="Feature.Attributes"/> will be populated with the values of the
        /// <see cref="GpxTrack"/> properties, even when <see langword="null"/>.
        /// </remarks>
        public static Feature ToFeature(GpxTrack track, IGeometryFactory geometryFactory)
        {
            if (track is null)
            {
                throw new ArgumentNullException(nameof(track));
            }

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

            // a track is an IMultiLineString feature.
            var lineStrings = new ILineString[track.Segments.Length];

            for (int i = 0; i < lineStrings.Length; i++)
            {
                lineStrings[i] = BuildLineString(track.Segments[i].Waypoints, geometryFactory);
            }

            var multiLineString = geometryFactory.CreateMultiLineString(lineStrings);
            var attributes      = new AttributesTable
            {
                { nameof(track.Name), track.Name },
                { nameof(track.Comment), track.Comment },
                { nameof(track.Description), track.Description },
                { nameof(track.Source), track.Source },
                { nameof(track.Links), track.Links },
                { nameof(track.Number), track.Number },
                { nameof(track.Classification), track.Classification },
                { nameof(track.Segments), track.Segments },
                { nameof(track.Extensions), track.Extensions },
            };

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