Skip to content

Commit e50ef00

Browse files
authored
Merge pull request #16 from mbacchi/elevation_nan
If FIT file has missing elevation data avoid adding <ele></ele> param instead of nan Merged agreed approach with @mbacchi
2 parents 9d6ade6 + d7bfba8 commit e50ef00

File tree

1 file changed

+18
-8
lines changed

1 file changed

+18
-8
lines changed

src/fit2gpx.py

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,12 @@
77
from datetime import datetime, timedelta
88
from typing import Dict, Optional, Tuple, Union
99

10-
import fitdecode
10+
import pandas as pd
11+
from math import isnan
1112
import lxml.etree as mod_etree
13+
14+
import fitdecode
1215
import gpxpy.gpx
13-
import pandas as pd
1416

1517

1618
# MAIN CONVERTER CLASS
@@ -186,12 +188,20 @@ def dataframe_to_gpx(self, df_points, col_lat='latitude', col_long='longitude',
186188
# Step 3: Add points from dataframe to GPX track:
187189
for idx in df_points.index:
188190
# Create trackpoint:
189-
track_point = gpxpy.gpx.GPXTrackPoint(
190-
latitude=df_points.loc[idx, col_lat],
191-
longitude=df_points.loc[idx, col_long],
192-
time=pd.Timestamp(df_points.loc[idx, col_time]) if col_time else None,
193-
elevation=df_points.loc[idx, col_alt] if col_alt else None
194-
)
191+
if isnan(df_points.loc[idx, col_alt]):
192+
track_point = gpxpy.gpx.GPXTrackPoint(
193+
latitude=df_points.loc[idx, col_lat],
194+
longitude=df_points.loc[idx, col_long],
195+
time=pd.Timestamp(df_points.loc[idx, col_time]) if col_time else None,
196+
# Do not include elevation if nan
197+
)
198+
else:
199+
track_point = gpxpy.gpx.GPXTrackPoint(
200+
latitude=df_points.loc[idx, col_lat],
201+
longitude=df_points.loc[idx, col_long],
202+
time=pd.Timestamp(df_points.loc[idx, col_time]) if col_time else None,
203+
elevation=df_points.loc[idx, col_alt] if col_alt else None,
204+
)
195205

196206
# add GPX extensions for heartrate and cadence
197207
if col_hr or col_cad:

0 commit comments

Comments
 (0)