TrajectoryCollection#

class movingpandas.TrajectoryCollection(data, traj_id_col=None, obj_id_col=None, t=None, x=None, y=None, crs='epsg:4326', min_length=0, min_duration=None)#
__init__(data, traj_id_col=None, obj_id_col=None, t=None, x=None, y=None, crs='epsg:4326', min_length=0, min_duration=None)#

Create TrajectoryCollection from list of trajectories or GeoDataFrame

Parameters:
  • data (list[Trajectory] or GeoDataFrame or DataFrame) – List of Trajectory objects or a GeoDataFrame with trajectory IDs, point geometry column and timestamp index

  • traj_id_col (string) – Name of the GeoDataFrame column containing trajectory IDs

  • obj_id_col (string) – Name of the GeoDataFrame column containing moving object IDs

  • 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

  • min_length (numeric) – Desired minimum length of trajectories. Length is calculated using CRS units, except if the CRS is geographic (e.g. EPSG:4326 WGS84) then length is calculated in meters. (Shorter trajectories are discarded.)

  • min_duration (timedelta) – Desired minimum duration of trajectories. (Shorter trajectories are discarded.)

Examples

>>> import geopandas as read_file
>>> import movingpandas as mpd
>>>
>>> gdf = read_file('data.gpkg')
>>> collection = mpd.TrajectoryCollection(gdf, 'trajectory_id', t='t')

Conversion#

TrajectoryCollection.to_line_gdf([columns])

Return the trajectories' line segments as GeoDataFrame.

TrajectoryCollection.to_mf_json([...])

Converts a TrajectoryCollection to a dictionary compatible with the Moving Features JSON (MF-JSON) specification.

TrajectoryCollection.to_point_gdf()

Return the trajectories' points as GeoDataFrame.

TrajectoryCollection.to_traj_gdf([wkt, agg])

Return a GeoDataFrame with one row per Trajectory within the TrajectoryCollection

Enrichment#

TrajectoryCollection.add_acceleration([...])

Add acceleration column and values to the trajectories.

TrajectoryCollection.add_angular_difference([...])

Add angular difference to the trajectory's DataFrame.

TrajectoryCollection.add_direction([...])

Add direction column and values to the trajectories.

TrajectoryCollection.add_distance([...])

Add distance column and values to the trajectories.

TrajectoryCollection.add_speed([overwrite, ...])

Add speed column and values to the trajectories.

TrajectoryCollection.add_timedelta([...])

Add timedelta column and values to the trajectories.

TrajectoryCollection.add_traj_id([overwrite])

Add trajectory id column and values to the trajectories.

General methods and attributes#

TrajectoryCollection.copy()

Return a copy of the trajectory collection.

TrajectoryCollection.drop(**kwargs)

Drop columns or rows from the trajectories' DataFrames

TrajectoryCollection.filter(property_name, ...)

Filter trajectories by property

TrajectoryCollection.get_max(column)

Return maximum value in the provided DataFrame column over all trajectories

TrajectoryCollection.get_min(column)

Return minimum value in the provided DataFrame column over all trajectories

TrajectoryCollection.get_trajectories(obj_id)

Return the trajectories of the requested moving object

TrajectoryCollection.get_trajectory(traj_id)

Return the Trajectory with the requested ID

Plotting#

TrajectoryCollection.explore(*args, **kwargs)

Generate a plot using GeoPandas explore (folium/leaflet.js) https://geopandas.org/en/stable/docs/reference/api/geopandas.GeoDataFrame.explore.html

TrajectoryCollection.hvplot(*args, **kwargs)

Generate an interactive trajectory plot.

TrajectoryCollection.hvplot_pts(*args, **kwargs)

Generate an interactive plot of trajectory points.

TrajectoryCollection.plot(*args, **kwargs)

Generate a plot.

Spatiotemporal analysis#

TrajectoryCollection.clip(polygon[, point_based])

Clip trajectories by the given polygon.

TrajectoryCollection.get_crs()

Return the CRS of the trajectories

TrajectoryCollection.get_end_locations([...])

Returns GeoDataFrame with trajectory end locations

TrajectoryCollection.get_intersecting(polygon)

Return trajectories that intersect the given polygon.

TrajectoryCollection.get_locations_at(t[, ...])

Returns GeoDataFrame with trajectory locations at the specified timestamp

TrajectoryCollection.get_segments_between(t1, t2)

Return Trajectory segments between times t1 and t2.

TrajectoryCollection.get_start_locations([...])

Returns GeoDataFrame with trajectory start locations

TrajectoryCollection.intersection(feature[, ...])

Intersect trajectories with the given polygon feature.

TrajectoryCollection.is_latlon()

Return True if the trajectory CRS is geographic (e.g. EPSG:4326 WGS84).

Spatiotemporal columns#

TrajectoryCollection.get_column_names()

Return the list of column names

TrajectoryCollection.get_direction_col()

Return name of the direction column

TrajectoryCollection.get_geom_col()

Return name of the geometry column

TrajectoryCollection.get_speed_col()

Return name of the speed column

TrajectoryCollection.get_traj_id_col()

Return name of the trajectory ID column