TrajectoryWriter module

Module contents

class TrajectoryWriter

Write trajectories of any type as delimited text

This class writes subclasses of tracktable::Trajectory (including the domain classes) to a stream as delimited text. It will write one trajectory per line. The resulting file will contain enough header information to reconstruct the trajectory exactly as long as the user asks for the correct class.

Public Functions

inline TrajectoryWriter()

Instantiate TrajectoryWriter using a default configuration

Set the default configuration values of the writer

Defaults:

  • coordinate_precision = 8

  • field_delimiter = “,”

  • quote_character = “””

    * record_delimiter = “\n”

    * timestamp_format = “Y-m-d H:M:S”

inline TrajectoryWriter(std::ostream &_output)

Instantiate a TrajectoryWriter using a std::ostream and default configuration

Set the default configuration values of the writer

Defaults:

  • coordinate_precision = 8

  • field_delimiter = “,”

  • quote_character = “””

    * record_delimiter = “\n”

    * timestamp_format = “Y-m-d H:M:S”

Parameters:

_output[in] Stream to output to

inline TrajectoryWriter(TrajectoryWriter const &other)

Copy contructor, create a writer with a copy of another

Parameters:

other[in] TrajectoryWriter to copy from

inline virtual ~TrajectoryWriter()

Destructor.

inline TrajectoryWriter &operator=(TrajectoryWriter const &other)

Assign a TrajectoryWriter to the value of another.

Parameters:

other[in] TrajectoryWriter to assign value of

Returns:

Writer with the new assigned value

inline bool operator==(TrajectoryWriter const &other) const

Check whether one writer is equal to another by comparing all the properties.

Two writers are equal if all of their streams are properties.

Parameters:

other[in] TrajectoryWriter for comparison

Returns:

Boolean indicating equivalency

inline bool operator!=(TrajectoryWriter const &other) const

Check whether two TrajectoryWriters are unequal.

Parameters:

other[in] TrajectoryWriter for comparison

Returns:

Boolean indicating equivalency

inline void set_output(std::ostream &out)

Set the stream where points will be written

This can be any std::ostream.

Note

You are resposible for ensuring that the stream does not go out of scope until you are done writing points.

Parameters:

out[in] Stream where points will be written

inline std::ostream &output() const

Return the stream where points will be written

Returns:

output stream

inline void set_field_delimiter(string_type const &delim)

Set the field delimiter

This string will be inserted between each field as points are written.

Parameters:

delim[in] Delimiter string

inline string_type field_delimiter() const

Return the field delimiter

Returns:

Field delimiter

inline void set_record_delimiter(string_type const &delim)

Set the record separator (end-of-line string)

This string will be written after each point. By default it’s std::endl (the newline string).

Parameters:

sep[in] String separator

inline string_type record_delimiter() const

Retrieve the record separator (end-of-line string)

Returns:

Return the record separator (end-of-line string)

inline void set_quote_character(string_type const &quote)

Set the quote character

This character may be used to enclose a field containing lots of characters that would otherwise need to be escaped. We have to know what it is so that we can escape it ourselves when we encounter the quote character inside fields.

Parameters:

quotes[in] Zero or one character to be used as quotation marks

inline string_type quote_character() const

Return the current quote characters

Returns:

Current quote character

inline void set_timestamp_format(string_type const &format)

Set format for writing timestamps

There are as many ways to write timestamps as there are programs to write them. We have our default (YYYY-MM-DD HH:MM:SS) but sometimes you will need to specify some other format for interoperability.

This method sets a format string for timestamps using the flags in boost::date_time::time_facet.

Parameters:

format[in] Format string for timestamps

inline string_type timestamp_format() const

Retrieve the timestamp format

Returns:

The time timestamp format

inline void set_null_value(string_type const &new_null_value)

Set the string representation for nulls

Property values that were never set are considered to hold a null value. This method lets you set how nulls will be written to disk. The default value is the empty string “”.

Parameters:

new_null_value[in] Desired string representation of nulls

inline string_type null_value() const

Retreive the null value

Returns:

The representation of the null value

template<typename trajectory_type>
inline void write(trajectory_type const &trajectory)

Write a single trajectory

Parameters:

trajectory[in] Trajectory to write our

template<typename source_iter_type>
inline void write(source_iter_type traj_begin, source_iter_type traj_end)

Write many trajectories

Parameters:
  • traj_begin[in] Start of trajectories to write out

  • traj_end[in] End of trajectories to write out

inline void set_coordinate_precision(std::size_t num_digits)

Set the decimal precision for writing coordinates

Internally, Tracktable stores coordinates as double-precision floating numbers. It is highly unlikely that trajectory data needs absolutely all of that precision. Since it takes up lots of space when we write data to disk, it is useful to be able to ask for reduced (or increased) precision.

Parameters:

num_digits[in] Number of digits of precision

inline std::size_t coordinate_precision() const

Retreive the coordinate decimal precision

Returns:

The decimal precision

Private Types

typedef std::vector<tracktable::settings::string_type> string_vector_type

Private Functions

template<typename trajectory_type, typename out_iter_type>
inline void write_trajectory_header(trajectory_type const &trajectory, out_iter_type output_iter)

Write tokens out the header

Parameters:
  • trajectory[in] Trajectory with tokens to write to header

  • output_iter[in] Iterator to write out

inline void set_default_configuration()

Set the default configuration values of the writer

Defaults:

  • coordinate_precision = 8

  • field_delimiter = “,”

  • quote_character = “””

    * record_delimiter = “\n”

    * timestamp_format = “Y-m-d H:M:S”

Private Members

std::size_t CoordinatePrecision
string_type FieldDelimiter
std::ostream *OutputStream
string_type QuoteCharacter
string_type RecordDelimiter
string_type TimestampFormat
PointWriter TrajectoryPointWriter
rw::detail::TrajectoryHeader _TrajectoryHeader