TSP GPX
Posted on Sat 21 April 2018 in Projects
In [3]:
import os
import pandas as pd
import gpxpy.gpx
import altair as alt
from bokeh.models import GMapPlot, GMapOptions, ColumnDataSource, Circle, Range1d, PanTool, WheelZoomTool, ResetTool, SaveTool
from bokeh.io import show, output_notebook
In [ ]:
gpx = gpxpy.parse(open('../images/TSPdata/allTSP/ladypackTSP.gpx'))
In [3]:
track_coords = [[point.latitude, point.longitude, point.elevation]
for track in gpx.tracks
for segment in track.segments
for point in segment.points]
locs = pd.DataFrame(track_coords)
locs.columns = ['Latitude', 'Longitude', 'Altitude']
locs
Out[3]:
In [4]:
alt.data_transformers.enable('default', max_rows=None)
Out[4]:
In [5]:
states = alt.topo_feature(data.us_10m.url, 'states')
# US states background
background = alt.Chart(states).mark_geoshape(
fill='lightgray',
stroke='white'
).properties(
title='US State Capitols',
width=700,
height=400
).project('albersUsa')
# GPS Track
GPS = alt.Chart(locs).mark_point().encode(
longitude='Longitude:Q',
latitude='Latitude:Q',
color='Altitude:Q'
)
background + GPS
Out[5]:
In [22]:
midlat = locs['Latitude'].min()+((locs['Latitude'].max()-locs['Latitude'].min())/2)
midlon = locs['Longitude'].min()+((locs['Longitude'].max()-locs['Longitude'].min())/2)
map_options = GMapOptions(lat=midlat, lng=midlon, map_type="roadmap", zoom=7)
activitymap = GMapPlot(x_range=Range1d(), y_range=Range1d(), map_options=map_options)
activitymap.api_key = "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"
source = ColumnDataSource(data=locs)
circle = Circle(x="Longitude", y="Latitude", size=3, fill_color="blue", fill_alpha=0.9, line_color=None)
activitymap.add_glyph(source, circle)
activitymap.add_tools(PanTool(), WheelZoomTool(), ResetTool())
In [25]:
show(activitymap)