MovingPandas provides a trajectory datatype based on GeoPandas. The project home is at https://github.com/movingpandas/movingpandas
The documentation is available at https://movingpandas.readthedocs.io/en/main/
import warnings
warnings.filterwarnings('ignore')
import pandas as pd
import geopandas as gpd
import movingpandas as mpd
from hvplot import pandas
from datetime import datetime, timedelta
The MovingPandas repository contains a demo GeoPackage file that can be loaded as follows:
gdf = gpd.read_file('../data/geolife_small.gpkg')
gdf.plot(figsize=(9,5))
gdf.hvplot(geo=True).opts(active_tools=['pan', 'wheel_zoom'])
After reading the trajectory point data from file, we want to construct the trajectories.
tc = mpd.TrajectoryCollection(gdf, 'trajectory_id', t='t')
tc
tc.plot(column='trajectory_id', legend=True, figsize=(9,5))
tc.plot(column='speed', linewidth=5, capstyle='round', legend=True, vmax=20, figsize=(9,5))
detector = mpd.TrajectoryStopDetector(tc)
stop_points = detector.get_stop_points(min_duration=timedelta(seconds=120), max_diameter=100)
ax = tc.plot(figsize=(9,5))
stop_points.plot(ax=ax, color='red', markersize=100)
( tc.hvplot(line_width=7, tiles=None, frame_width=400, frame_height=400) *
stop_points.hvplot(geo=True, color='black', size=100) )