tracktable.applications.assemble_trajectories module

Module contents

tracktable.applications.assemble_trajectories - Sources that turn a sequence of points into a sequence of trajectories.

class tracktable.applications.assemble_trajectories.AssembleTrajectoryFromPoints[source]

Bases: object

Turn a sequence of points into a set of trajectories

We begin with an input sequence of TrajectoryPoints sorted by increasing timestamp. As we iterate over that sequence, we separate points by their object IDs and build up a new trajectory for each object ID. When we see a gap of duration ‘separation_time’ or distance ‘separation_distance’ between the previous and latest point for a given object ID, we package up the points so far, emit a new trajectory and use the latest point to start a new one.

input

Sequence of TrajectoryPoint objects sorted by timestamp

Type

iterable

separation_time

Maximum permissible time difference between adjacent points in a trajectory

Type

datetime.timedelta

separation_distance

Maximum permissible geographic distance (in KM) between adjacent points in a trajectory

Type

float

minimum_length

Complete trajectories with fewer than this many points will be discarded

Type

integer

Example:

p_source = SomePointSource()
(configure point source here)

t_source = AssembleTrajectoryFromPoints()
t_source.input = p_source.points()
t_source.separation_time = datetime.timedelta(minutes=30)
t_source.separation_distance = 100
t_source.minimum_length = 10

for trajectory in t_source.trajectories():
    # (do whatever you want)
trajectories()[source]

Return trajectories assembled from input points.

Once you have supplied a point source in the ‘input’ attribute (which can be any iterable but is commonly the output of a PointSource) you can call trajectories() to get an iterable of trajectories. All the computation happens on demand so the execution time between getting one trajectory and getting the next one is unpredictable.

There are only loose guarantees on the order in which trajectories become available. Given trajectories A and B, if timestamp(A.end) < timestamp(B.end) then A will come up before B.

The input sequence of trajectories will only be traversed once.

Yields

Trajectories built from input points