Based on GeoPandas and Holoviews.
import warnings
warnings.filterwarnings('ignore')
from datetime import datetime, timedelta
import sys
sys.path.append("..")
from geopandas import gpd
gdf = gpd.read_file('data/demodata_geolife.gpkg')
gdf
gdf.plot(figsize=(9,5))
After reading the trajectory point data from file, we want to construct the trajectories.
import movingpandas as mpd
traj_collection = mpd.TrajectoryCollection(gdf, 'trajectory_id', t='t')
print(traj_collection)
traj_collection.plot(column='trajectory_id', linewidth=5, legend=True, figsize=(9,5))
traj_collection.plot(column='speed', linewidth=5, capstyle='round', legend=True, vmax=20, figsize=(9,5))
my_traj = traj_collection.get_trajectory(2)
print(my_traj)
my_traj.hvplot(c='speed', line_width=7.0, tiles='StamenTonerBackground', cmap='Viridis', colorbar=True, clim=(0,20), width=700, height=400)
detector = mpd.TrajectoryStopDetector(traj_collection)
stop_points = detector.get_stop_points(min_duration=timedelta(seconds=120), max_diameter=100)
stop_points.head()
ax = traj_collection.plot(figsize=(9,5), linewidth=5)
stop_points.plot(ax=ax, color='deeppink', markersize=100)
my_traj = traj_collection.get_trajectory(1)
split = mpd.StopSplitter(my_traj).split(min_duration=timedelta(seconds=60), max_diameter=100)
split
ax = split.trajectories[0].plot(figsize=(9,6), linewidth=5)
for i, traj in enumerate(split):
traj.plot(ax=ax, color=['deeppink', 'slategray'][i%2], linewidth=5)
Examples: https://github.com/anitagraser/movingpandas-examples
Repo: https://github.com/anitagraser/movingpandas
Documentation: https://movingpandas.readthedocs.io/en/master/