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

TrkSeg can be empty on GPX 1.1 #23

Closed alex-piccione closed 8 years ago

alex-piccione commented 8 years ago

With a GPX 1.1 you have this error parsing a GPX file: NullReferenceException if the file contains an empty trkseg element ()

trkseg can be an empty element: http://www.topografix.com/GPX/1/1/#type_trksegType (it is a complex element and contains a sequence of [0..*] trkpt elements)

The problem is in Gps\Serialization\Gpx11Serializer.cs

private static void ParseTracks(GpxFile xml, GpsData data)
[...]
foreach (var wptType in trksegType.trkpt)

trksegType.trkpt is null if trkseg element doesn't contain any point.

(problem exists in version 0.13 and 0.14)

Alessandro

alex-piccione commented 8 years ago

A segment is added in track only for adding points, so it can be ignored if it hasn't points. Proposed solution. from: foreach (var trksegType in trkType.trkseg) to: foreach (var trksegType in trkType.trkseg.Where(seg => seg.trkpt != null))

sibartlett commented 8 years ago

0.14.1 pushed to NuGet.