Trajectory Reader ExampleΒΆ

Purpose: Demonstrate how to create and use a Trajectory Reader
If you have a file of already formed trajectories, you can use the Trajectory Reader to read them from file. Like the point reader, you can iterate over the trajectories you have and access the properties of the points in each trajectory.
In [1]:
from tracktable.domain.terrestrial import TrajectoryReader
from tracktable.core import data_directory
import os.path

The trajectory reader is set up in a similar way as a point reader. In the example below, we give it a file containing trajectories and we use the default which is the terrestrial point reader. Terrestrial is typically used on real data. In order to access the trajectories, iterate over the reader.

In [2]:
data_filename = os.path.join(data_directory(), 'SampleTrajectories.traj')
inFile = open(data_filename, 'r')
reader = TrajectoryReader()
reader.input = inFile
i = 1                                            # Used to limit the number of results we see
for x in reader:                                 # Each object in the reader is an iterator pointer here
    print(*x)
    print("\n")
    i -= 1
    if i <= 0:
        break
[TSTBOSEWR1@ 2014-07-01 15:45:43: (-71.0052, 42.3643) Properties: ( )] [TSTBOSEWR1@ 2014-07-01 15:46:48: (-71.1853, 42.2738) Properties: ( )] [TSTBOSEWR1@ 2014-07-01 15:47:52: (-71.3648, 42.1829) Properties: ( )] [TSTBOSEWR1@ 2014-07-01 15:48:57: (-71.5439, 42.0918) Properties: ( )] [TSTBOSEWR1@ 2014-07-01 15:50:01: (-71.7224, 42.0004) Properties: ( )] [TSTBOSEWR1@ 2014-07-01 15:51:05: (-71.9004, 41.9087) Properties: ( )] [TSTBOSEWR1@ 2014-07-01 15:52:10: (-72.0779, 41.8168) Properties: ( )] [TSTBOSEWR1@ 2014-07-01 15:53:14: (-72.2549, 41.7245) Properties: ( )] [TSTBOSEWR1@ 2014-07-01 15:54:19: (-72.4314, 41.632) Properties: ( )] [TSTBOSEWR1@ 2014-07-01 15:55:23: (-72.6074, 41.5393) Properties: ( )] [TSTBOSEWR1@ 2014-07-01 15:56:28: (-72.7828, 41.4462) Properties: ( )] [TSTBOSEWR1@ 2014-07-01 15:57:32: (-72.9578, 41.3529) Properties: ( )] [TSTBOSEWR1@ 2014-07-01 15:58:36: (-73.1323, 41.2594) Properties: ( )] [TSTBOSEWR1@ 2014-07-01 15:59:41: (-73.3063, 41.1655) Properties: ( )] [TSTBOSEWR1@ 2014-07-01 16:00:45: (-73.4797, 41.0714) Properties: ( )] [TSTBOSEWR1@ 2014-07-01 16:01:50: (-73.6527, 40.9771) Properties: ( )] [TSTBOSEWR1@ 2014-07-01 16:02:54: (-73.8252, 40.8825) Properties: ( )] [TSTBOSEWR1@ 2014-07-01 16:03:59: (-73.9972, 40.7876) Properties: ( )] [TSTBOSEWR1@ 2014-07-01 16:05:03: (-74.1687, 40.6925) Properties: ( )]


Note that by iterating over the reader, you get a collection of points together as trajectories. Just like the point reader, you can edit the delimiting character and comment character as well as the column properties.