Permalink
Browse files

Basic Garmin flightplan support

  • Loading branch information...
1 parent ee3ee36 commit 44aec501b22d3e37509981bc7cc38dcbb828908f @sibartlett committed Sep 9, 2012
@@ -103,6 +103,7 @@
<ItemGroup>
<Compile Include="Geo\GeoPointCalculationsTests.cs" />
<Compile Include="Geo\GeoPointTests.cs" />
+ <Compile Include="Gps\Serialization\GarminFlightplanDeSerializerTests.cs" />
<Compile Include="Gps\Serialization\GpsDeSerializerTests.cs" />
<Compile Include="Gps\Serialization\GpxSerializerTests.cs" />
<Compile Include="Gps\Serialization\IgcDeSerializerTests.cs" />
@@ -0,0 +1,26 @@
+using System.IO;
+using System.Linq;
+using Geo.Gps.Serialization;
+using NUnit.Framework;
+
+namespace Geo.Tests.Gps.Serialization
+{
+ [TestFixture]
+ public class GarminFlightplanDeSerializerTests : SerializerTestFixtureBase
+ {
+ [Test]
+ public void CanParse()
+ {
+ var fileInfo =
+ GetReferenceFileDirectory("garmin").EnumerateFiles().First(x => x.Name == "garmin.fpl");
+
+ using (var stream = new FileStream(fileInfo.FullName, FileMode.Open))
+ {
+ var file = new GarminFlightplanDeSerializer().DeSerialize(new StreamWrapper(stream));
+ Assert.That(file, Is.Not.Null);
+ Assert.That(file.Routes.Count, Is.EqualTo(1));
+ Assert.That(file.Routes[0].LineString.Points.Count, Is.EqualTo(5));
+ }
+ }
+ }
+}
@@ -1,7 +1,6 @@
using System.IO;
using System.Linq;
using Geo.Gps.Serialization;
-using Geo.Measure;
using NUnit.Framework;
namespace Geo.Tests.Gps.Serialization
View
Binary file not shown.
View
@@ -70,6 +70,7 @@
<Compile Include="Gps\Metadata\RouteMetadata.cs" />
<Compile Include="Gps\Metadata\TrackMetadata.cs" />
<Compile Include="Gps\Route.cs" />
+ <Compile Include="Gps\Serialization\GarminFlightplanDeSerializer.cs" />
<Compile Include="Gps\Serialization\PocketFmsFlightplanDeSerializer.cs" />
<Compile Include="Gps\Serialization\SkyDemonFlightplanDeSerializer.cs" />
<Compile Include="Gps\Serialization\StreamWrapper.cs" />
@@ -78,6 +79,10 @@
<Compile Include="Gps\Serialization\IgcDeSerializer.cs" />
<Compile Include="Gps\Serialization\IGpsFileDeSerializer.cs" />
<Compile Include="Gps\Serialization\NmeaDeSerializer.cs" />
+ <Compile Include="Gps\Serialization\Xml\Garmin\GarminFlightplan.cs" />
+ <Compile Include="Gps\Serialization\Xml\Garmin\GarminRoute.cs" />
+ <Compile Include="Gps\Serialization\Xml\Garmin\GarminRoutePoint.cs" />
+ <Compile Include="Gps\Serialization\Xml\Garmin\GarminWaypoint.cs" />
<Compile Include="Gps\Serialization\Xml\GpsXmlDeSerializer.cs" />
<Compile Include="Gps\Serialization\Xml\GpsXmlSerializer.cs" />
<Compile Include="Gps\Serialization\Xml\Gpx\Gpx10\GpxBounds.cs" />
View
@@ -23,7 +23,9 @@ static GpsData()
{
new IgcDeSerializer(),
new NmeaDeSerializer(),
+ new GarminFlightplanDeSerializer(),
new PocketFmsFlightplanDeSerializer(),
+ new SkyDemonFlightplanDeSerializer(),
};
}
@@ -0,0 +1,43 @@
+using System.Linq;
+using Geo.Geometries;
+using Geo.Gps.Serialization.Xml;
+using Geo.Gps.Serialization.Xml.Garmin;
+
+namespace Geo.Gps.Serialization
+{
+ public class GarminFlightplanDeSerializer : GpsXmlDeSerializer<GarminFlightplan>
+ {
+ public override GpsFileFormat[] FileFormats
+ {
+ get
+ {
+ return new[]
+ {
+ new GpsFileFormat("fpl", "Garmin Flightplan"),
+ };
+ }
+ }
+
+ public override GpsFeatures SupportedFeatures
+ {
+ get { return GpsFeatures.Routes; }
+ }
+
+ protected override GpsData DeSerialize(GarminFlightplan xml)
+ {
+ var data = new GpsData();
+ foreach (var route in xml.route)
+ {
+ var rte = new Route();
+ rte.Metadata.Attribute(x => x.Name, route.routename);
+ foreach (var point in route.routepoint)
+ {
+ var wp = xml.waypointtable.Single(x => x.identifier == point.waypointidentifier);
+ rte.LineString.Add(new Point(wp.lat, wp.lon));
+ }
+ data.Routes.Add(rte);
+ }
+ return data;
+ }
+ }
+}
@@ -0,0 +1,17 @@
+using System.Xml.Serialization;
+
+namespace Geo.Gps.Serialization.Xml.Garmin
+{
+ [XmlType(AnonymousType=true, Namespace="http://www8.garmin.com/xmlschemas/FlightPlan/v1")]
+ [XmlRoot("flight-plan", Namespace="http://www8.garmin.com/xmlschemas/FlightPlan/v1", IsNullable=false)]
+ public class GarminFlightplan {
+ //public string created { get; set; }
+
+ [XmlArray("waypoint-table")]
+ [XmlArrayItem("waypoint", typeof (GarminWaypoint), IsNullable = false)]
+ public GarminWaypoint[] waypointtable { get; set; }
+
+ [XmlElement("route")]
+ public GarminRoute[] route { get; set; }
+ }
+}
@@ -0,0 +1,16 @@
+using System.Xml.Serialization;
+
+namespace Geo.Gps.Serialization.Xml.Garmin
+{
+ [XmlType(AnonymousType=true, Namespace="http://www8.garmin.com/xmlschemas/FlightPlan/v1")]
+ public class GarminRoute {
+ [XmlElement("route-name")]
+ public string routename { get; set; }
+
+ //[XmlElement("flight-plan-index")]
+ //public string flightplanindex { get; set; }
+
+ [XmlElement("route-point")]
+ public GarminRoutePoint[] routepoint { get; set; }
+ }
+}
@@ -0,0 +1,16 @@
+using System.Xml.Serialization;
+
+namespace Geo.Gps.Serialization.Xml.Garmin
+{
+ [XmlType(AnonymousType=true, Namespace="http://www8.garmin.com/xmlschemas/FlightPlan/v1")]
+ public class GarminRoutePoint {
+ [XmlElement("waypoint-identifier")]
+ public string waypointidentifier { get; set; }
+
+ //[XmlElement("waypoint-type")]
+ //public string waypointtype { get; set; }
+
+ //[XmlElement("waypoint-country-code")]
+ //public string waypointcountrycode { get; set; }
+ }
+}
@@ -0,0 +1,20 @@
+using System.Xml.Serialization;
+
+namespace Geo.Gps.Serialization.Xml.Garmin
+{
+ [XmlType(AnonymousType=true, Namespace="http://www8.garmin.com/xmlschemas/FlightPlan/v1")]
+ public class GarminWaypoint {
+ public string identifier { get; set; }
+
+ //public string type { get; set; }
+
+ //[XmlElement("country-code")]
+ //public string countrycode { get; set; }
+
+ public double lat { get; set; }
+
+ public double lon { get; set; }
+
+ //public string comment { get; set; }
+ }
+}
@@ -0,0 +1,75 @@
+<?xml version="1.0" encoding="utf-8"?>
+<flight-plan xmlns="http://www8.garmin.com/xmlschemas/FlightPlan/v1">
+ <created>2012-09-09T20:47:59Z</created>
+ <waypoint-table>
+ <waypoint>
+ <identifier>EGLG</identifier>
+ <type>AIRPORT</type>
+ <country-code>GB</country-code>
+ <lat>51.801944</lat>
+ <lon>-0.158333</lon>
+ <comment />
+ </waypoint>
+ <waypoint>
+ <identifier>MISC2</identifier>
+ <type>USER WAYPOINT</type>
+ <country-code>GB</country-code>
+ <lat>51.946125</lat>
+ <lon>-0.018417</lon>
+ <comment />
+ </waypoint>
+ <waypoint>
+ <identifier>MISC4</identifier>
+ <type>USER WAYPOINT</type>
+ <country-code>GB</country-code>
+ <lat>52.127403</lat>
+ <lon>0.232722</lon>
+ <comment />
+ </waypoint>
+ <waypoint>
+ <identifier>EGSH</identifier>
+ <type>AIRPORT</type>
+ <country-code>GB</country-code>
+ <lat>52.675833</lat>
+ <lon>1.282778</lon>
+ <comment />
+ </waypoint>
+ <waypoint>
+ <identifier>EGSC</identifier>
+ <type>AIRPORT</type>
+ <country-code>GB</country-code>
+ <lat>52.205000</lat>
+ <lon>0.175000</lon>
+ <comment />
+ </waypoint>
+ </waypoint-table>
+ <route>
+ <route-name>Panshanger - Norwich</route-name>
+ <flight-plan-index>1</flight-plan-index>
+ <route-point>
+ <waypoint-identifier>EGLG</waypoint-identifier>
+ <waypoint-type>AIRPORT</waypoint-type>
+ <waypoint-country-code>GB</waypoint-country-code>
+ </route-point>
+ <route-point>
+ <waypoint-identifier>MISC2</waypoint-identifier>
+ <waypoint-type>USER WAYPOINT</waypoint-type>
+ <waypoint-country-code>GB</waypoint-country-code>
+ </route-point>
+ <route-point>
+ <waypoint-identifier>MISC4</waypoint-identifier>
+ <waypoint-type>USER WAYPOINT</waypoint-type>
+ <waypoint-country-code>GB</waypoint-country-code>
+ </route-point>
+ <route-point>
+ <waypoint-identifier>EGSH</waypoint-identifier>
+ <waypoint-type>AIRPORT</waypoint-type>
+ <waypoint-country-code>GB</waypoint-country-code>
+ </route-point>
+ <route-point>
+ <waypoint-identifier>EGSC</waypoint-identifier>
+ <waypoint-type>AIRPORT</waypoint-type>
+ <waypoint-country-code>GB</waypoint-country-code>
+ </route-point>
+ </route>
+</flight-plan>

0 comments on commit 44aec50

Please sign in to comment.