diff --git a/src/fit2gpx.py b/src/fit2gpx.py index cf931db..281aa60 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 @@ -176,12 +177,20 @@ 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: # 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)