|
7 | 7 | from datetime import datetime, timedelta |
8 | 8 | from typing import Dict, Optional, Tuple, Union |
9 | 9 |
|
10 | | -import fitdecode |
| 10 | +import pandas as pd |
| 11 | +from math import isnan |
11 | 12 | import lxml.etree as mod_etree |
| 13 | + |
| 14 | +import fitdecode |
12 | 15 | import gpxpy.gpx |
13 | | -import pandas as pd |
14 | 16 |
|
15 | 17 |
|
16 | 18 | # MAIN CONVERTER CLASS |
@@ -186,12 +188,20 @@ def dataframe_to_gpx(self, df_points, col_lat='latitude', col_long='longitude', |
186 | 188 | # Step 3: Add points from dataframe to GPX track: |
187 | 189 | for idx in df_points.index: |
188 | 190 | # 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 | + ) |
195 | 205 |
|
196 | 206 | # add GPX extensions for heartrate and cadence |
197 | 207 | if col_hr or col_cad: |
|
0 commit comments