Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

If FIT file has missing elevation data avoid adding <ele></ele> param instead of nan #16

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 15 additions & 6 deletions src/fit2gpx.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import pandas as pd
import gpxpy.gpx
import fitdecode
from math import isnan


# MAIN CONVERTER CLASS
Expand Down Expand Up @@ -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)
Expand Down