Trajectory#

Functions for identifying and grouping trajectories from point data.

cuspatial.derive_trajectories(object_ids, points: GeoSeries, timestamps)#

Derive trajectories from object ids, points, and timestamps.

Parameters
object_ids

column of object (e.g., vehicle) ids

pointsGeoSeries

The points of the trajectories

timestamps

column of timestamps in any resolution

Returns
resulttuple (objects, traj_offsets)
objectscudf.DataFrame

object_ids, xs, ys, and timestamps sorted by (object_id, timestamp), used by trajectory_bounding_boxes and trajectory_distances_and_speeds

traj_offsetscudf.Series

offsets of discovered trajectories

Examples

Compute sorted objects and discovered trajectories

>>> objects, traj_offsets = cuspatial.derive_trajectories(
        [0, 1, 0, 1],  # object_id
        [0, 0, 1, 1],  # x
        [0, 0, 1, 1],  # y
        [0, 10000, 0, 10000] # timestamp
    )
>>> print(traj_offsets)
    0  0
    1  2
>>> print(objects)
    object_id    x    y           timestamp
    0          0  0.0  0.0 1970-01-01 00:00:00
    1          0  1.0  1.0 1970-01-01 00:00:10
    2          1  0.0  0.0 1970-01-01 00:00:00
    3          1  1.0  1.0 1970-01-01 00:00:10
cuspatial.trajectory_distances_and_speeds(num_trajectories, object_ids, points: GeoSeries, timestamps)#

Compute the distance traveled and speed of sets of trajectories

Parameters
num_trajectories

number of trajectories (unique object ids)

object_ids

column of object (e.g., vehicle) ids

points: GeoSeries

A series of points

timestamps

column of timestamps in any resolution

Returns
resultcudf.DataFrame
meterscudf.Series

trajectory distance (in kilometers)

speedcudf.Series

trajectory speed (in meters/second)

Examples

Compute the distances and speeds of derived trajectories

>>> objects, traj_offsets = cuspatial.derive_trajectories(...)
>>> dists_and_speeds = cuspatial.trajectory_distances_and_speeds(
        len(traj_offsets)
        objects['object_id'],
        objects['x'],
        objects['y'],
        objects['timestamp']
    )
>>> print(dists_and_speeds)
                      distance       speed
    trajectory_id
    0              1414.213562  141.421356
    1              1414.213562  141.421356
cuspatial.trajectory_bounding_boxes(num_trajectories, object_ids, points: GeoSeries)#

Compute the bounding boxes of sets of trajectories.

Parameters
num_trajectories

number of trajectories (unique object ids)

object_ids

column of object (e.g., vehicle) ids

points: GeoSeries

Series of trajectory points

Returns
resultcudf.DataFrame

minimum bounding boxes (in kilometers) for each trajectory

x_mincudf.Series

the minimum x-coordinate of each bounding box

y_mincudf.Series

the minimum y-coordinate of each bounding box

x_maxcudf.Series

the maximum x-coordinate of each bounding box

y_maxcudf.Series

the maximum y-coordinate of each bounding box

Examples

Compute the minimum bounding boxes of derived trajectories

>>> objects, traj_offsets = cuspatial.derive_trajectories(
        [0, 0, 1, 1],  # object_id
        [0, 1, 2, 3],  # x
        [0, 0, 1, 1],  # y
        [0, 10, 0, 10] # timestamp
    )
>>> traj_bounding_boxes = cuspatial.trajectory_bounding_boxes(
        len(traj_offsets),
        objects['object_id'],
        objects['x'],
        objects['y']
    )
>>> print(traj_bounding_boxes)
    x_min   y_min   x_max   y_max
0     0.0     0.0     2.0     2.0
1     1.0     1.0     3.0     3.0