Input¶
Point Input¶
There are three ways to get point data into Tracktable:
Instantiate and populate
base_point_type
andtrajectory_point_type
objects by hand.Load points from a delimited text file.
Create points algorithmically.
Manually instantiate Points¶
For instructions on manually instantiating both base_point_type
and trajectory_point_type
objects refer to the Point Classes section of
the C++ user guide.
Loading Points from Delimited Text¶
Tracktable has a flexible point reader for delimited text files. Each point domain provides two versions of it, one for loading base points (coordinates only) and one for loading trajectory points.
1#include <tracktable/Domain/Terrestrial.h>
2#include <tracktable/Analysis/AssembleTrajectories.h>
3
4typedef tracktable::domain::terrestrial::trajectory_point_reader_type reader_type;
5typedef tracktable::domain::terrestrial::trajectory_type trajectory_type;
6typedef tracktable::AssembleTrajectories<trajectory_type, reader_type::iterator> assembler_type;
7
8reader_type point_reader;
9assembler_type trajectory_builder;
10
11trajectory_builder.set_separation_time(tracktable::minutes(20));
12trajectory_builder.set_separation_distance(100);
13trajectory_builder.set_minimum_trajectory_length(500);
14
15std::string = "point_data.csv";
16std::ifstream infile(filename.c_str());
17
18if (!infile)
19{
20 std::cerr << "ERROR: Could not open file '" << filename << "'\n";
21 return -1;
22}
23
24point_reader.set_input(infile);
25point_reader.set_object_id_column(0);
26point_reader.set_timestamp_column(1);
27point_reader.set_longitude_column(2);
28point_reader.set_latitude_column(3);
29
30for (reader_type it = point_reader.begin(); it != point_reader.end(); ++it) {
31 // Do whatever you want with the points here
32}
Algorithmically Creating Points¶
Important
To create points algorithmically we will need to supply (at a minimum) coordinates, a timestamp and an ID.
The TrajectoryPoint
class can generate points interpolated between
each trajectory point of a given trajectory. TrajectoryPoint
s are inherited in each type of domain
under under the trajectory_point_type
. These points can then be assembled
into trajectories which is show below but is explained in further detail in the
Trajectory Assembly section.
1#include <tracktable/Domain/Terrestrial.h>
2
3using tracktable::domain::terrestrial::trajectory_point_type;
4using tracktable::domain::terrestrial::trajectory_type;
5
6trajectory_point_type albuquerque;
7trajectory_point_type santa_fe;
8trajectory_point_type roswell;
9trajectory_type trajectory;
10
11std::string obj_id("GreenChileExpress001");
12albuquerque.set_latitude(35.1107);
13albuquerque.set_longitude(-106.6100);
14albuquerque.set_object_id(obj_id);
15albuquerque.set_timestamp(tracktable::time_from_string("2014-05-01 12:00:00"));
16
17santa_fe.set_latitude(35.6672);
18santa_fe.set_longitude(-105.9644);
19santa_fe.set_object_id(obj_id);
20santa_fe.set_timestamp(tracktable::time_from_string("2014-05-01 13:00:00"));
21
22roswell.set_latitude(33.3872);
23roswell.set_longitude(-104.5281);
24roswell.set_object_id(obj_id);
25roswell.set_timestamp(tracktable::time_from_string("2014-05-01 14:00:00"));
26
27trajectory.push_back(albuquerque);
28trajectory.push_back(santa_fe);
29trajectory.push_back(roswell);
Trajectory Input¶
There are two ways to get trajectory data into Tracktable:
Instantiate and populate
trajectory_type
objects by hand.Load trajectories from a delimited text file.
Manually instantiate Trajectories¶
For instructions on manually instantiating Trajectory
objects refer to the Trajectories section
of the C++ user guide.
Loading Trajectories from Delimited File¶
Tracktable has a flexible trajectory reader for delimited text files. Each point domain provides a trajectory reader. The trajectory reader functionality is the same across all point domains. Trajectories can be loaded from standard CSV and TSV delimited files as well as tracktable’s own TRAJ file type. Refer to the Tracktable Data page for more information about the TRAJ format.
1#include <tracktable/RW/TrajectoryReader.h>
2#include <tracktable/Core/Trajectory.h>
3#include <tracktable/Core/TrajectoryPoint.h>
4
5typedef tracktable::TrajectoryPoint<point_type> trajectory_point_type;
6typedef tracktable::Trajectory<trajectory_point_type> trajectory_type;
7
8std::string filename = "trajectories.csv";
9std::ifstream infile(filename.c_str());
10
11tracktable::TrajectoryReader<trajectory_type> reader(infile);
12
13for (trajectory_type iter = reader.begin(); iter != reader.end(); ++iter)
14{
15 // Do whatever you want with the trajectories here
16}
Output¶
Point Output¶
Both base_point_type
and trajectory_point_type
are output by the
PointWriter
. Each point domain has it’s own version of the writer.
Output can be directed to a delimited file or a standard output buffer.
Below is an example of exporting points of type trajectory_point_type
to a file, exporting points of the type base_point_type
or using a
buffer would have a similar structure.
1#include <tracktable/Core/TrajectoryPoint.h>
2#include <tracktable/RW/PointWriter.h>
3
4std::string filename = "points.csv";
5std::ofstream ofile(filename.c_str());
6
7// Generate/Read points here
8
9tracktable::PointWriter writer(ofile);
10writer.write(points.begin(), points.end());
Trajectory Output¶
Similar to the point output, in order to output a Trajectory
from Tracktable the
TrajectoryWriter
is be used. The functionality of the writer is the same as the
base_point_type
and trajectory_point_type
writers.
1#include <tracktable/RW/TrajectoryWriter.h>
2#include <tracktable/Core/Trajectory.h>
3#include <tracktable/Core/TrajectoryPoint.h>
4
5std::string filename = "trajectories.csv"; // "trajectories.traj"
6std::ofstream ofile(filename.c_str());
7
8// Generate/Read trajectories here
9
10tracktable::TrajectoryWriter writer(ofile);
11writer.write(trajectory);