LoadTimeSeriesDataSetFromPGIS.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 // Boost
14 #include <boost/uuid/random_generator.hpp>
15 #include <boost/uuid/uuid_io.hpp>
16 
17 void LoadTimeSeriesDataSetFromPGIS(boost::ptr_vector<te::st::TimeSeries>& output)
18 {
19  try
20  {
21  //Container used to store the resulting timeseries before outputting them ack
22  std::vector<te::st::TimeSeries*> series;
23 
24  // let's give the minimal server connection information needed to connect to the database server
25  std::string connInfo("pgsql://postgres:postgres@localhost:5432/timeseries");
26 
27  //Indicates the data source
29  dsInfo.setConnInfo(connInfo);
30  dsInfo.setTitle("TimeSeries");
31  dsInfo.setAccessDriver("POSTGIS");
32  dsInfo.setType("POSTGIS");
33 
34  //It creates a new Data Source and put it into the manager
36 
37  te::st::TimeSeriesDataSetInfo tsInfo(dsInfo, "ordered_cells_view", "time", "value", "spatial_data", "id_cell", "");
38 
39  te::gm::Envelope e(622000, 9291000, 625000, 9294000); //Creating a spatial restriction to load a small number of TimeSeries
40  std::unique_ptr<te::st::TimeSeriesDataSet> timeSeriesDS = te::st::STDataLoader::getDataSet(tsInfo, e);
41 
42  timeSeriesDS->moveBeforeFirst();
43  timeSeriesDS->getTimeSeriesSet(&te::st::NearestValueAtTimeInterp::getInstance(), tsInfo.getObservationDataSetInfo().getIdPropName(), series);
44  for(size_t i = 0; i < series.size(); i++)
45  {
46  output.push_back(series[i]);
47  }
48  }
49  catch(const std::exception& e)
50  {
51  std::cout << std::endl << "An exception has occurred in TimeSeriesExamplesFromKML: " << e.what() << std::endl;
52  }
53  catch(...)
54  {
55  std::cout << std::endl << "An unexpected exception has occurred in TimeSeriesExamplesFromKML!" << std::endl;
56  }
57 }
58 
This file contains include headers for the Data Type module of TerraLib.
const ObservationDataSetInfo & getObservationDataSetInfo() const
It returns information about the DataSet that contains the time series observations.
void setAccessDriver(const std::string &d)
Examples on how to load/manipulate st types.
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)
static NearestValueAtTimeInterp & getInstance()
It returns a reference to the singleton instance.
An Envelope defines a 2D rectangular region.
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.
void LoadTimeSeriesDataSetFromPGIS(boost::ptr_vector< te::st::TimeSeries > &output)
It loads a Time Series data set from a PostGIS database.
A class that contains infos about a DataSet that contains observations of one or more time series...
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.
std::string getIdPropName() const
It returns the name of the property that contains identifiers that groups observations.
void setTitle(const std::string &title)