sibartlett / Geo

A geospatial library for .NET
https://www.nuget.org/packages/Geo/
GNU Lesser General Public License v3.0
176 stars 39 forks source link

Support waypoint attributes #32

Closed mfeingol closed 4 years ago

mfeingol commented 7 years ago

I'm using the Geo library for a UWP app, and I need to know the names of waypoints in GPX files. Unfortunately, the Geo library doesn't seem to support that.

Any chance you could integrate the following changes (or better)?

Thanks!

Waypoint.cs:

using Geo.Abstractions.Interfaces;
using Geo.Geometries;
using Geo.Measure;

namespace Geo.Gps
{
    public class Waypoint : IRavenIndexable, IHasLength
    {
        public string Name { get; private set; }
        public Point Point { get; set; }

        public Waypoint(string name, Point point)
        {
            Name = name;
            Point = point;
        }

        public Coordinate Coordinate
        {
            get { return Point.Coordinate; }
        }

        public LineString ToLineString()
        {
            return new LineString(Point.Coordinate);
        }

        ISpatial4nShape IRavenIndexable.GetSpatial4nShape()
        {
            return ToLineString();
        }

        public Distance GetLength()
        {
            return ToLineString().GetLength();
        }
    }
}

Rest of diff:

O:\Build\External\Geo>git diff
diff --git a/Geo/Geo.csproj b/Geo/Geo.csproj
index 899c4f5..f81e3d0 100644
--- a/Geo/Geo.csproj
+++ b/Geo/Geo.csproj
@@ -179,6 +179,7 @@
     <Compile Include="Gps\Serialization\Xml\SkyDemon\SkyDemonFlightplan.cs" />
     <Compile Include="Gps\Track.cs" />
     <Compile Include="Gps\TrackSegment.cs" />
+    <Compile Include="Gps\Waypoint.cs" />
     <Compile Include="InternalHelpers.cs" />
     <Compile Include="IO\GeoJson\Feature.cs" />
     <Compile Include="IO\GeoJson\FeatureCollection.cs" />
diff --git a/Geo/Gps/GpsData.cs b/Geo/Gps/GpsData.cs
index 2857036..7623e57 100644
--- a/Geo/Gps/GpsData.cs
+++ b/Geo/Gps/GpsData.cs
@@ -34,13 +34,13 @@ namespace Geo.Gps
             Metadata = new GpsMetadata();
             Routes = new List<Route>();
             Tracks = new List<Track>();
-            Waypoints = new List<Point>();
+            Waypoints = new List<Waypoint>();
         }

         public GpsMetadata Metadata { get; private set; }
         public List<Route> Routes { get; set; }
         public List<Track> Tracks { get; set; }
-        public List<Point> Waypoints { get; set; }
+        public List<Waypoint> Waypoints { get; set; }

         public string ToGpx()
         {
diff --git a/Geo/Gps/Serialization/Gpx10Serializer.cs b/Geo/Gps/Serialization/Gpx10Serializer.cs
index 817aa92..a8ecb67 100644
--- a/Geo/Gps/Serialization/Gpx10Serializer.cs
+++ b/Geo/Gps/Serialization/Gpx10Serializer.cs
@@ -186,7 +186,8 @@ namespace Geo.Gps.Serialization
                 foreach (var wptType in xml.wpt)
                 {
                     var fix = new Point((double)wptType.lat, (double)wptType.lon, (double)wptType.ele);
-                    data.Waypoints.Add(fix);
+                    string name = wptType.name;
+                    data.Waypoints.Add(new Waypoint(name, fix));
                 }
         }
     }
diff --git a/Geo/Gps/Serialization/Gpx11Serializer.cs b/Geo/Gps/Serialization/Gpx11Serializer.cs
index 68db591..c89bbe8 100644
--- a/Geo/Gps/Serialization/Gpx11Serializer.cs
+++ b/Geo/Gps/Serialization/Gpx11Serializer.cs
@@ -283,7 +283,8 @@ namespace Geo.Gps.Serialization
                 foreach (var wptType in xml.wpt)
                 {
                     var fix = new Point((double)wptType.lat, (double)wptType.lon, (double)wptType.ele);
-                    data.Waypoints.Add(fix);
+                    string name = wptType.name;
+                    data.Waypoints.Add(new Waypoint(name, fix));
                 }
         }
     }
diff --git a/Geo/Gps/Serialization/NmeaDeSerializer.cs b/Geo/Gps/Serialization/NmeaDeSerializer.cs
index b3b7f77..01cfa3e 100644
--- a/Geo/Gps/Serialization/NmeaDeSerializer.cs
+++ b/Geo/Gps/Serialization/NmeaDeSerializer.cs
@@ -95,7 +95,9 @@ namespace Geo.Gps.Serialization
                 double lat = ConvertOrd(match.Groups["lat"].Value, match.Groups["latd"].Value);
                 double lon = ConvertOrd(match.Groups["lon"].Value, match.Groups["lond"].Value);
                 var fix = new Point(lat, lon);
-                data.Waypoints.Add(fix);
+
+                string name = String.Empty;
+                data.Waypoints.Add(new Waypoint(name, fix));

                 return true;
             }
mfeingol commented 5 years ago

Addressed in https://github.com/sibartlett/Geo/pull/37

sibartlett commented 4 years ago

Merged in: 058e413574ffe8f4c958536783a4ab81283b7c70