LoadTrajectoryDateSetFromKML.cpp
Go to the documentation of this file.
1 // TerraLib
2 #include <terralib/dataaccess.h>
3 #include <terralib/stmemory.h>
4 #include <terralib/st.h>
5 #include <terralib/datatype.h>
6 
7 // Examples
8 #include "STExamples.h"
9 
10 // STL
11 #include <iostream>
12 
13 void LoadTrajectoryDataSetFromKML(boost::ptr_vector<te::st::TrajectoryDataSet>& output)
14 {
15  try
16  {
17  //Indicates the data source
19  const std::string connInfo("file://" TERRALIB_DATA_DIR "/st/trajectory/t_40_41.kml");
20  dsinfo.setConnInfo(connInfo);
21  dsinfo.setType("OGR");
22 
23  //It creates a new Data Source and put it into the manager
25 
26  //Indicates how the trajectories are stored in the data source -> This structure is fixed for OGR driver
27  //int phTimeIdx = 3; /* property name: timestamp */
28  std::string phTimeName = "timestamp";
29 
30  //int geomIdx = 12; /* property name: geom */
31  std::string geomName = "geom";
32 
33  //Use the STDataLoader to create a TrajectoryDataSet with all observations
34  te::st::TrajectoryDataSetInfo tjinfo40(dsinfo, "40: locations", phTimeName, geomName, "", "40");
35 
36  std::unique_ptr<te::st::TrajectoryDataSet> tjDS40 = te::st::STDataLoader::getDataSet(tjinfo40);
37 
38  //Use the STDataLoader to create a TrajectoryDataSet with all observations
39  te::st::TrajectoryDataSetInfo tjinfo41(dsinfo, "41: locations", phTimeName, geomName, "", "41");
40  std::unique_ptr<te::st::TrajectoryDataSet> tjDS41 = te::st::STDataLoader::getDataSet(tjinfo41);
41 
42  //Print the spatial and temporal extent as well as the observations of the loaded trajectories
43  PrintTrajectoryDataSet(tjDS40.get());
44  PrintTrajectoryDataSet(tjDS41.get());
45 
46  //Insert into the result container
47  tjDS40->moveBeforeFirst();
48  output.push_back(tjDS40.release());
49  tjDS41->moveBeforeFirst();
50  output.push_back(tjDS41.release());
51 
52  //Use the STDataLoader to create a TrajectoryDataSet with the observations during a given period
53  te::dt::TimeInstant time1(te::dt::Date(2008,01,01), te::dt::TimeDuration(0,0,0));
54  te::dt::TimeInstant time2(te::dt::Date(2008,03,31), te::dt::TimeDuration(23,59,59));
55  te::dt::TimePeriod period(time1, time2);
56 
57  std::unique_ptr<te::st::TrajectoryDataSet> tjDS40period = te::st::STDataLoader::getDataSet(tjinfo40, period, te::dt::DURING);
58  std::unique_ptr<te::st::TrajectoryDataSet> tjDS41period = te::st::STDataLoader::getDataSet(tjinfo41, period, te::dt::DURING);
59 
60  //Print the spatial and temporal extent as well as the observations of the loaded trajectories
61  //PrintTrajectoryDataSet(tjDS40period.get());
62  //PrintTrajectoryDataSet(tjDS41period.get());
63 
64  //Insert into the result container
65  tjDS40period->moveBeforeFirst();
66  output.push_back(tjDS40period.release());
67  tjDS41period->moveBeforeFirst();
68  output.push_back(tjDS41period.release());
69  }
70  catch(const std::exception& e)
71  {
72  std::cout << std::endl << "An exception has occurred in TrajectoryExamplesFromKML: " << e.what() << std::endl;
73  }
74  catch(...)
75  {
76  std::cout << std::endl << "An unexpected exception has occurred in TrajectoryExamplesFromKML!" << std::endl;
77  }
78 }
79 
This file contains include headers for the Data Type module of TerraLib.
void PrintTrajectoryDataSet(boost::ptr_vector< te::st::TrajectoryDataSet > &output)
It prints all observations of the trajectory data set (PrintTrajectoryDataSet.cpp) ...
Examples on how to load/manipulate st types.
A class to represent time instant.
Definition: TimeInstant.h:55
This file contains include headers for the TerraLib ST memory module.
void setType(const std::string &dsType)
void CreateDataSourceAndUpdateManager(te::da::DataSourceInfo &dsinfo)
It creates a new DataSource and put it into the DataSource manager, using a random id...
void setConnInfo(const te::core::URI &conninfo)
A base class for date data types.
Definition: Date.h:53
static std::unique_ptr< ObservationDataSet > getDataSet(const ObservationDataSetInfo &info, te::common::TraverseType travType=te::common::FORWARDONLY)
It returns a ObservationDataSet, that is, a DataSet that contains observations.
A class that contains infos about a DataSet that contains observations of one or more trajectories...
A class to represent time period.
Definition: TimePeriod.h:54
A class to represent time duration with nano-second/micro-second resolution.
Definition: TimeDuration.h:51
void LoadTrajectoryDataSetFromKML(boost::ptr_vector< te::st::TrajectoryDataSet > &output)
It loads trajectory data set from KML file.
A class that represents a data source component.
This file contains include headers for the TerraLib ST module.
This file contains include headers for the Data Access module of TerraLib.