From c11cebc6fae6e8934ebfb4590548e093fd92ab2e Mon Sep 17 00:00:00 2001 From: Matt Bacchi Date: Tue, 6 Aug 2024 07:10:37 -0400 Subject: [PATCH 1/2] Represent missing elevation data as 0 rather than nan Resolves: https://github.com/dodo-saba/fit2gpx/issues/15 --- src/fit2gpx.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/fit2gpx.py b/src/fit2gpx.py index cf931db..2b46d6a 100644 --- a/src/fit2gpx.py +++ b/src/fit2gpx.py @@ -8,6 +8,7 @@ import pandas as pd import gpxpy.gpx import fitdecode +from math import isnan # MAIN CONVERTER CLASS @@ -175,6 +176,8 @@ def dataframe_to_gpx(self, df_points, col_lat='latitude', col_long='longitude', # Step 3: Add points from dataframe to GPX track: for idx in df_points.index: + if isnan(df_points.loc[idx, col_alt]): + df_points.loc[idx, col_alt] = 0 # Create trackpoint: track_point = gpxpy.gpx.GPXTrackPoint( latitude=df_points.loc[idx, col_lat], From ac92044ce58e031eec51673644d1ccb088be2dc2 Mon Sep 17 00:00:00 2001 From: Matt Bacchi Date: Wed, 4 Sep 2024 21:42:47 -0400 Subject: [PATCH 2/2] After discussing with @dodo-saba, decided to not arbitrarily add 0 rather to not add any parms if the FIT value is NaN --- src/fit2gpx.py | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/src/fit2gpx.py b/src/fit2gpx.py index 2b46d6a..281aa60 100644 --- a/src/fit2gpx.py +++ b/src/fit2gpx.py @@ -176,15 +176,21 @@ def dataframe_to_gpx(self, df_points, col_lat='latitude', col_long='longitude', # Step 3: Add points from dataframe to GPX track: for idx in df_points.index: - if isnan(df_points.loc[idx, col_alt]): - df_points.loc[idx, col_alt] = 0 # Create trackpoint: - track_point = gpxpy.gpx.GPXTrackPoint( - latitude=df_points.loc[idx, col_lat], - longitude=df_points.loc[idx, col_long], - time=pd.Timestamp(df_points.loc[idx, col_time]) if col_time else None, - elevation=df_points.loc[idx, col_alt] if col_alt else None - ) + if isnan(df_points.loc[idx, col_alt]): + track_point = gpxpy.gpx.GPXTrackPoint( + latitude=df_points.loc[idx, col_lat], + longitude=df_points.loc[idx, col_long], + time=pd.Timestamp(df_points.loc[idx, col_time]) if col_time else None, + # Do not include elevation if nan + ) + else: + track_point = gpxpy.gpx.GPXTrackPoint( + latitude=df_points.loc[idx, col_lat], + longitude=df_points.loc[idx, col_long], + time=pd.Timestamp(df_points.loc[idx, col_time]) if col_time else None, + elevation=df_points.loc[idx, col_alt] if col_alt else None, + ) # Append GPX_TrackPoint to segment: gpx_segment.points.append(track_point)