TrajectoryExamples.cpp
Go to the documentation of this file.
1 // Examples
2 #include "STExamples.h"
3 
4 // TerraLib
5 #include <terralib/common.h>
6 #include <terralib/dataaccess.h>
7 #include <terralib/geometry.h>
8 #include <terralib/st.h>
9 
10 // STL
11 #include <iostream>
12 
14 {
15  try
16  {
17  //Output container
18  boost::ptr_vector<te::st::TrajectoryDataSet> output;
19 
20  //Load the trajectories from a KML Data Source
22 
23  //Print trajectory data set info: spatial and temporal extent
25 
26  //Get the trajectories from the trajectory data sets to execute other operations
27  boost::ptr_vector<te::st::Trajectory> trajectories;
28  for(std::size_t i=0; i<output.size(); ++i)
29  {
30  te::st::TrajectoryDataSet& ds = output[i];
31  ds.moveBeforeFirst();
32  trajectories.push_back(ds.getTrajectory().release());
33  }
34 
35  //Calculate and print the distance between the two first trajectories
36  if(trajectories.size()>1)
37  TrajectoryDistance(&trajectories[0], &trajectories[1]);
38 
39  //Calculate the intersection between the first trajectory and a geometry
40  //Load the geometry from a shapefile
41  const std::string connInfo("file://" TERRALIB_DATA_DIR "/st/trajectory/t41_region.shp");
42 
43  std::unique_ptr<te::da::DataSource> ds(te::da::DataSourceFactory::make("OGR", connInfo));
44  ds->open();
45 
46  std::unique_ptr<te::da::DataSet> dSet = ds->getDataSet("t41_region");
47  std::unique_ptr<te::gm::Geometry> geom;
48 
49  if(dSet->moveNext())
50  {
51  std::size_t geomPos = te::da::GetFirstPropertyPos(dSet.get(), te::dt::GEOMETRY_TYPE);
52  geom = dSet->getGeometry(geomPos);
53 
54  //Calculate the intersection and print the result!
55  TrajectoryIntersection(&trajectories[1], geom.get());
56  }
57  }
58 
59  catch(const std::exception& e)
60  {
61  std::cout << std::endl << "An exception has occurred in TrajectoryExamples: " << e.what() << std::endl;
62  }
63  catch(...)
64  {
65  std::cout << std::endl << "An unexpected exception has occurred in TrajectoryExamples!" << std::endl;
66  }
67 }
68 
static std::unique_ptr< DataSource > make(const std::string &driver, const te::core::URI &connInfo)
std::unique_ptr< Trajectory > getTrajectory(AbstractTrajectoryInterp *interp)
It returns the trajectory from the DataSet.
void TrajectoryDistance(te::st::Trajectory *tj1, te::st::Trajectory *tj2)
It calculates the distance between two trajectories (TrajectoryDistance.cpp).
void TrajectoryExamples()
It groups the examples with trajectories (TrajectoryExamples.cpp).
static te::dt::Date ds(2010, 01, 01)
Examples on how to load/manipulate st types.
void TrajectoryIntersection(te::st::Trajectory *tj, te::gm::Geometry *geom)
It calculates the intersection between a trajectory and a geometry (TrajectoryInstersection.cpp).
A class to represent a trajectory data set.
void PrintTrajectoryDataSetInfo(boost::ptr_vector< te::st::TrajectoryDataSet > &output)
It prints information about the trajectory data set: its spatial and temporal extent (PrintTrajectory...
void LoadTrajectoryDataSetFromKML(boost::ptr_vector< te::st::TrajectoryDataSet > &output)
It loads trajectory data set from KML file.
This file contains include headers for the TerraLib Common Runtime module.
This file contains include headers for the TerraLib ST module.
TEDATAACCESSEXPORT std::size_t GetFirstPropertyPos(const te::da::DataSet *dataset, int datatype)
This file contains include headers for the Vector Geometry model of TerraLib.
This file contains include headers for the Data Access module of TerraLib.