From ecbd07fd6e568580c69df7c38fcddd7bdd2f5dc6 Mon Sep 17 00:00:00 2001 From: Gareth Coco Date: Mon, 25 Oct 2010 22:40:05 -0400 Subject: [PATCH] Resolve Lat/Long issue on FIT file import The FIT parser will attempt to interpolate data when filling in for smart recording or if a record is missed. A problem occurs if one of the lat/long points is missing or 0,0. This patch will record a 0,0 lat,long if the record is missing in the FIT file and when interpolating, will set any interpolated data points to 0,0 if the start or end record is also 0,0. A 0,0 record is not plotted on the MAP tab. Fixes #111 --- src/FitRideFile.cpp | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/src/FitRideFile.cpp b/src/FitRideFile.cpp index a3b9b7ee1..2f0c49233 100644 --- a/src/FitRideFile.cpp +++ b/src/FitRideFile.cpp @@ -207,7 +207,7 @@ struct FitFileReaderState time_t time = 0; if (time_offset > 0) time = last_time + time_offset; - double alt = 0, cad = 0, km = 0, grade = 0, hr = 0, lat = 0, lng = 0; + double alt = 0, cad = 0, km = 0, grade = 0, hr = 0, lat = 0, lng = 0, badgps = 0; double resistance = 0, kph = 0, temperature = 0, time_from_course = 0, watts = 0; int lati = 0x7fffffff, lngi = 0x7fffffff; int i = 0; @@ -245,6 +245,12 @@ struct FitFileReaderState if (lati != 0x7fffffff && lngi != 0x7fffffff) { lat = lati * 180.0 / 0x7fffffff; lng = lngi * 180.0 / 0x7fffffff; + } else + { + // If lat/lng are missng, set to 0/0 and fill point from last point as 0/0) + lat = 0; + lng = 0; + badgps = 1; } if (start_time == 0) { start_time = time - 1; // XXX: recording interval? @@ -263,6 +269,10 @@ struct FitFileReaderState assert(deltaSecs == secs - prevPoint->secs); // no fractional part // This is only true if the previous record was of type record: assert(deltaSecs == time - last_time); + // If the last lat/lng was missing (0/0) then all points up to lat/lng are marked as 0/0. + if (prevPoint->lat == 0 && prevPoint->lon == 0 ) { + badgps = 1; + } double deltaCad = cad - prevPoint->cad; double deltaHr = hr - prevPoint->hr; double deltaDist = km - prevPoint->km; @@ -284,8 +294,8 @@ struct FitFileReaderState prevPoint->nm + (deltaTorque * weight), prevPoint->watts + (deltaPower * weight), prevPoint->alt + (deltaAlt * weight), - prevPoint->lon + (deltaLon * weight), - prevPoint->lat + (deltaLat * weight), + (badgps == 1) ? 0 : prevPoint->lon + (deltaLon * weight), + (badgps == 1) ? 0 : prevPoint->lat + (deltaLat * weight), prevPoint->headwind + (deltaHeadwind * weight), interval); }