import pandas as pd
import gpxpy
import gpxpy.gpx
import matplotlib.pyplot as plt
import os
import folium
“Strava GPX Plotter: Mapping Beautiful Journeys with Folium in Python” is a tool that allows users to visualize their Strava activities on interactive maps. By using Python and the Folium library, this tool reads GPX files from Strava and plots the routes on a map, highlighting the beauty of each journey. Users can customize the maps, adding markers and different styles to enhance the visual appeal. This tool is perfect for athletes and outdoor enthusiasts who want to see their activities in a new light, making it easy to share and analyze their adventures.
Read gpx File
# path from gpx file
= "Princesa_Toa_.gpx"
path # load data from gpx strava activity and parse
with open(path, 'r') as gpx_file:
= gpxpy.parse(gpx_file) gpx
Extract latitude, longitude and elevation
# extract in gpx file latitude, longitude and elevation
= [{'latitude': point.latitude,'longitude': point.longitude,'elevation': point.elevation}
route_info for track in gpx.tracks
for segment in track.segments
for point in segment.points ]
# route_df Dataframe
= pd.DataFrame(route_info)
df df.head()
latitude | longitude | elevation | |
---|---|---|---|
0 | -0.216083 | -78.436892 | 2388.8 |
1 | -0.216085 | -78.436895 | 2388.8 |
2 | -0.216141 | -78.436849 | 2388.9 |
3 | -0.216161 | -78.436832 | 2388.9 |
4 | -0.216211 | -78.436803 | 2389.0 |
# Calculate the middle index
= len(df) // 2
middle_index # Get the middle element using iloc
= df.iloc[middle_index] point
Plot Folium Map Strava default Tile
= folium.Map(location=[point['latitude'], point['longitude']] , zoom_start=12 )
my_map = df[['latitude','longitude']].values.tolist()
points ="red", weight=1.5, opacity=2.5).add_to(my_map) folium.PolyLine(points, color
<folium.vector_layers.PolyLine at 0x213f3814e20>
my_map
Make this Notebook Trusted to load map: File -> Trust Notebook
Plot Folium Map Strava stamen_terrain Tile
='https://tiles.stadiamaps.com/tiles/stamen_terrain/{z}/{x}/{y}{r}.png'
tiles='© <a href="https://www.stadiamaps.com/" target="_blank">Stadia Maps</a> © <a href="https://www.stamen.com/" target="_blank">Stamen Design</a> © <a href="https://openmaptiles.org/" target="_blank">OpenMapTiles</a> © <a href="https://www.openstreetmap.org/copyright">OpenStreetMap</a> contributors' attr
= folium.Map(location=[point['latitude'], point['longitude']],tiles= tiles,attr=attr,zoom_start=12 )
my_map = df[['latitude','longitude']].values.tolist()
points ="red", weight=1.5, opacity=2.5).add_to(my_map) folium.PolyLine(points, color
<folium.vector_layers.PolyLine at 0x213ed8dc8e0>
my_map
Make this Notebook Trusted to load map: File -> Trust Notebook