Trajectory#
- class movingpandas.Trajectory(df, traj_id, traj_id_col=None, obj_id=None, t=None, x=None, y=None, crs='epsg:4326', parent=None)#
- __init__(df, traj_id, traj_id_col=None, obj_id=None, t=None, x=None, y=None, crs='epsg:4326', parent=None)#
Create Trajectory from GeoDataFrame or DataFrame.
- Parameters:
df (GeoDataFrame or DataFrame) – GeoDataFrame with point geometry column and timestamp index
traj_id (any) – Trajectory ID
obj_id (any) – Moving object ID
t (string) – Name of the DataFrame column containing the timestamp
x (string) – Name of the DataFrame column containing the x coordinate
y (string) – Name of the DataFrame column containing the y coordinate
crs (string) – CRS of the x/y coordinates
parent (Trajectory) – Parent trajectory
Examples
Creating a trajectory from scratch:
>>> import pandas as pd >>> import geopandas as gpd >>> import movingpandas as mpd >>> >>> df = pd.DataFrame([ ... {'geometry':Point(0,0), 't':datetime(2018,1,1,12,0,0)}, ... {'geometry':Point(6,0), 't':datetime(2018,1,1,12,6,0)}, ... {'geometry':Point(6,6), 't':datetime(2018,1,1,12,10,0)}, ... {'geometry':Point(9,9), 't':datetime(2018,1,1,12,15,0)} ... ]).set_index('t') >>> gdf = gpd.GeoDataFrame(df, crs=31256) >>> traj = mpd.Trajectory(gdf, 1)
For more examples, see the tutorial notebooks.
Conversion#
|
Return the trajectory's line segments as GeoDataFrame. |
Return trajectory geometry as LineString. |
|
Return the WKT string of the trajectory LineStringM representation. |
|
|
Converts a Trajectory to a dictionary compatible with the Moving Features JSON (MF-JSON) specification. |
|
Return the trajectory's points as GeoDataFrame. |
|
Return a GeoDataFrame with one row containing the trajectory as a single LineString. |
Enrichment#
|
Add acceleration column and values to the trajectory's DataFrame. |
Add angular difference to the trajectory's DataFrame. |
|
|
Add direction column and values to the trajectory's DataFrame. |
|
Add distance column and values to the trajectory's DataFrame. |
|
Add speed column and values to the trajectory's DataFrame. |
|
Add timedelta column and values to the trajectory's DataFrame. |
|
Add trajectory id column and values to the trajectory's DataFrame. |
General methods and attributes#
Return a copy of the trajectory. |
|
|
Drop columns or rows from the trajectory DataFrame |
|
Return maximum value in the provided DataFrame column |
|
Return minimum value in the provided DataFrame column |
Return whether the trajectory meets minimum requirements. |
|
Returns number of rows in Trajectory.df |
Plotting#
|
Generate a plot using GeoPandas explore (folium/leaflet.js) https://geopandas.org/en/stable/docs/reference/api/geopandas.GeoDataFrame.explore.html |
|
Generate an interactive plot using HoloViews. |
|
Generate an interactive plot of trajectory points. |
|
Generate a plot using GeoPandas default plotting (Matplotlib). |
Spatiotemporal analysis#
|
Return trajectory segments clipped by the given polygon. |
|
Return the minimum distance to the other geometric object (based on shapely https://shapely.readthedocs.io/en/stable/manual.html#object.distance). |
Return the trajectory's bounding box. |
|
Return the CRS of the trajectory |
|
Return the direction of the trajectory. |
|
Return the trajectory's duration from start to end. |
|
Return the trajectory's end location. |
|
Return the trajectory's end time. |
|
|
Return the length of the trajectory. |
|
Return LineString of segment between times t1 and t2. |
Return the Minimum Convex Polygon of the trajectory data |
|
|
Compute and return position at time t. |
|
Return row of the trajectory's DataFrame at time t. |
Return the sampling interval of the trajectory. |
|
|
Return Trajectory segment between times t1 and t2. |
Return the trajectory's start location. |
|
Return the trajectory's start time. |
|
|
Return the Hausdorff distance to the other geometric object (based on shapely https://shapely.readthedocs.io/en/stable/manual.html#object.hausdorff_distance). |
Compute and return interpolated position at time t. |
|
|
Return the trajectory segments that intersects the given polygon feature. |
|
Return whether the trajectory intersects the given polygon. |
Return True if the trajectory CRS is geographic (e.g. EPSG:4326 WGS84). |
|
|
Return the trajectory reprojected to the target CRS |
Spatiotemporal columns#
Return name of the angular difference column |
|
Return the list of column names |
|
Return name of the direction column |
|
Return name of the distance column |
|
Return name of the geometry column |
|
Return name of the speed column |
|
Return name of the timedelta column |
|
Return name of the trajectory ID column |