All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
STDataLoaderFromMemDS.cpp
Go to the documentation of this file.
1 /* Copyright (C) 2001-2009 National Institute For Space Research (INPE) - Brazil.
2 
3  This file is part of the TerraLib - a Framework for building GIS enabled applications.
4 
5  TerraLib is free software: you can redistribute it and/or modify
6  it under the terms of the GNU Lesser General Public License as published by
7  the Free Software Foundation, either version 3 of the License,
8  or (at your option) any later version.
9 
10  TerraLib is distributed in the hope that it will be useful,
11  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  GNU Lesser General Public License for more details.
14 
15  You should have received a copy of the GNU Lesser General Public License
16  along with TerraLib. See COPYING. If not, write to
17  TerraLib Team at <terralib-team@terralib.org>.
18 */
19 
20 /*!
21  \file STDataLoaderFromMemDS.cpp
22 
23  \brief This file contains a class responsible for loading spatiotemporal data
24  from a ST in-memory DataSource which contains an internal chache of
25  in-memory DataSets indexed by space and time.
26 */
27 
28 //TerraLib
29 #include "../../dataaccess/datasource/DataSourceInfo.h"
30 #include "../../dataaccess/datasource/DataSourceManager.h"
31 #include "../../dataaccess/dataset/DataSet.h"
32 #include "../../dataaccess/utils/Utils.h"
33 #include "../../datatype/DateTimePeriod.h"
34 
35 //STMEM
36 #include "../../stmemory/DataSource.h"
37 #include "../../stmemory/DataSet.h"
38 
39 //ST
40 #include "../Exception.h"
41 #include "../Utils.h"
42 #include "../Globals.h"
43 #include "STDataLoaderFromMemDS.h"
44 #include "../core/observation/ObservationDataSetInfo.h"
45 #include "../core/trajectory/TrajectoryDataSetInfo.h"
46 #include "../core/timeseries/TimeSeriesDataSetInfo.h"
47 #include "../core/observation/ObservationDataSet.h"
48 #include "../core/trajectory/TrajectoryDataSet.h"
49 #include "../core/timeseries/TimeSeriesDataSet.h"
50 
51 //STL
52 #include <vector>
53 
55 {
56  //use the DataSourceManager to get the DataSource
58 
59  if(m_ds.get()==0)
60  throw Exception("The STDataLoader is not inialized! Please, use the method STDataLoader::initialize");
61 
62  if(!m_ds->isOpened())
63  m_ds->open();
64 }
65 
66 std::auto_ptr<te::st::ObservationDataSet>
68  te::common::TraverseType travType)
69 {
70 
71  //load the DataSet from its origin DataSource and put it into the In-Mem DataSource
72  if(!m_ds->dataSetExists(info.getDataSetName()))
73  loadDataSet(info.getDataSourceInfo(), info.getDataSetName(), info.getBeginTimePropIdx(),
74  info.getEndTimePropIdx(), info.getGeomPropIdx());
75 
76  std::auto_ptr<te::da::DataSet> dset(m_ds->getDataSet(info.getDataSetName(), travType));
77 
78  return buildDataSet(static_cast<te::stmem::DataSet*>(dset.release()), info);
79 }
80 
81 
82 std::auto_ptr<te::st::ObservationDataSet>
85 {
86  //load the DataSet from its origin DataSource and put it into the In-Mem DataSource
87  if(!m_ds->dataSetExists(info.getDataSetName()))
88  loadDataSet(info.getDataSourceInfo(), info.getDataSetName(), info.getBeginTimePropIdx(),
89  info.getEndTimePropIdx(), info.getGeomPropIdx());
90 
91  //get the geometry property name
92  std::auto_ptr<te::da::DataSetType> dsettype(m_ds->getDataSetType(info.getDataSetName()));
93  std::string geomPropName = dsettype->getProperty(info.getGeomPropIdx())->getName();
94 
95  //get the data set applying he filter
96  std::auto_ptr<te::da::DataSet> dset(m_ds->getDataSet(info.getDataSetName(), geomPropName, &e, r, travType));
97 
98  return buildDataSet(static_cast<te::stmem::DataSet*>(dset.release()), info);
99 }
100 
101 std::auto_ptr<te::st::ObservationDataSet>
104 {
105  //load the DataSet from its origin DataSource and put it into the In-Mem DataSource
106  if(!m_ds->dataSetExists(info.getDataSetName()))
107  loadDataSet(info.getDataSourceInfo(), info.getDataSetName(), info.getBeginTimePropIdx(),
108  info.getEndTimePropIdx(), info.getGeomPropIdx());
109 
110  //get the geometry property name
111  std::auto_ptr<te::da::DataSetType> dsettype(m_ds->getDataSetType(info.getDataSetName()));
112  std::string geomPropName = dsettype->getProperty(info.getGeomPropIdx())->getName();
113 
114  //get the data set applying he filter
115  std::auto_ptr<te::da::DataSet> dset(m_ds->getDataSet(info.getDataSetName(), geomPropName, &geom, r, travType));
116 
117  return buildDataSet(static_cast<te::stmem::DataSet*>(dset.release()), info);
118 }
119 
120 std::auto_ptr<te::st::ObservationDataSet>
123  te::common::TraverseType travType)
124 {
125  //load the DataSet from its origin DataSource and put it into the In-Mem DataSource
126  if(!m_ds->dataSetExists(info.getDataSetName()))
127  loadDataSet(info.getDataSourceInfo(), info.getDataSetName(), info.getBeginTimePropIdx(),
128  info.getEndTimePropIdx(), info.getGeomPropIdx());
129 
130  te::stmem::DataSource* inMemDataSource = static_cast<te::stmem::DataSource*>(m_ds.get());
131 
132  std::auto_ptr<te::da::DataSet> dset(inMemDataSource->getDataSet(info.getDataSetName(), &dt, r, travType));
133 
134  return buildDataSet(static_cast<te::stmem::DataSet*>(dset.release()), info);
135 }
136 
137 std::auto_ptr<te::st::ObservationDataSet>
141  te::common::TraverseType travType)
142 {
143  //load the DataSet from its origin DataSource and put it into the In-Mem DataSource
144  if(!m_ds->dataSetExists(info.getDataSetName()))
145  loadDataSet(info.getDataSourceInfo(), info.getDataSetName(), info.getBeginTimePropIdx(),
146  info.getEndTimePropIdx(), info.getGeomPropIdx());
147 
148  te::stmem::DataSource* inMemDataSource = static_cast<te::stmem::DataSource*>(m_ds.get());
149 
150  std::auto_ptr<te::da::DataSet> dset(inMemDataSource->getDataSet(info.getDataSetName(), &geom, sr, &dt, tr, travType));
151 
152  return buildDataSet(static_cast<te::stmem::DataSet*>(dset.release()), info);
153 }
154 
155 void
156 te::st::STDataLoaderFromMemDS::getInfo( const TrajectoryDataSetInfo& /*input*/, std::vector<TrajectoryDataSetInfo>& /*output*/)
157 {
158  return;
159 }
160 
161 std::auto_ptr<te::st::TrajectoryDataSet>
163 {
164  //load the DataSet from its origin DataSource and put it into the In-Mem DataSource
165  if(!m_ds->dataSetExists(info.getObservationDataSetInfo().getDataSetName()))
166  loadDataSet(info.getDataSourceInfo(), info.getObservationDataSetInfo().getDataSetName(),
170 
171  //get the data set
172  std::auto_ptr<te::da::DataSet> dset(m_ds->getDataSet(info.getObservationDataSetInfo().getDataSetName(), travType));
173 
174  return buildDataSet(static_cast<te::stmem::DataSet*>(dset.release()), info);
175 }
176 
177 std::auto_ptr<te::st::TrajectoryDataSet>
180  te::common::TraverseType travType)
181 {
182  //load the DataSet from its origin DataSource and put it into the In-Mem DataSource
183  if(!m_ds->dataSetExists(info.getObservationDataSetInfo().getDataSetName()))
184  loadDataSet(info.getDataSourceInfo(), info.getObservationDataSetInfo().getDataSetName(),
188 
189  //get data set type to get the geometry property name
190  std::auto_ptr<te::da::DataSetType> dsettype(m_ds->getDataSetType(info.getObservationDataSetInfo().getDataSetName()));
191  std::string geomPropName = dsettype->getProperty(info.getGeomPropIdx())->getName();
192 
193  //get the data set, applying the spatial filter
194  std::auto_ptr<te::da::DataSet> dset(m_ds->getDataSet(info.getObservationDataSetInfo().getDataSetName(),
195  geomPropName, &geom, r, travType));
196 
197  return buildDataSet(static_cast<te::stmem::DataSet*>(dset.release()), info);
198 }
199 
200 std::auto_ptr<te::st::TrajectoryDataSet>
203  te::common::TraverseType travType)
204 {
205  //load the DataSet from its origin DataSource and put it into the In-Mem DataSource
206  if(!m_ds->dataSetExists(info.getObservationDataSetInfo().getDataSetName()))
207  loadDataSet(info.getDataSourceInfo(), info.getObservationDataSetInfo().getDataSetName(),
211 
212  //get data set type to get the geometry property name
213  std::auto_ptr<te::da::DataSetType> dsettype(m_ds->getDataSetType(info.getObservationDataSetInfo().getDataSetName()));
214  std::string geomPropName = dsettype->getProperty(info.getGeomPropIdx())->getName();
215 
216  //get the data set, applying the spatial filter
217  std::auto_ptr<te::da::DataSet> dset(m_ds->getDataSet(info.getObservationDataSetInfo().getDataSetName(),
218  geomPropName, &e, r, travType));
219 
220  return buildDataSet(static_cast<te::stmem::DataSet*>(dset.release()), info);
221 }
222 
223 std::auto_ptr<te::st::TrajectoryDataSet>
226  te::common::TraverseType travType)
227 {
228  //load the DataSet from its origin DataSource and put it into the In-Mem DataSource
229  if(!m_ds->dataSetExists(info.getObservationDataSetInfo().getDataSetName()))
230  loadDataSet(info.getDataSourceInfo(), info.getObservationDataSetInfo().getDataSetName(),
234 
235  te::stmem::DataSource* inMemDataSource = static_cast<te::stmem::DataSource*>(m_ds.get());
236 
237  std::auto_ptr<te::da::DataSet> dset(inMemDataSource->getDataSet(
238  info.getObservationDataSetInfo().getDataSetName(), &dt, r, travType));
239 
240  return buildDataSet(static_cast<te::stmem::DataSet*>(dset.release()), info);
241 }
242 
243 std::auto_ptr<te::st::TrajectoryDataSet>
247  te::common::TraverseType travType)
248 {
249  //load the DataSet from its origin DataSource and put it into the In-Mem DataSource
250  if(!m_ds->dataSetExists(info.getObservationDataSetInfo().getDataSetName()))
251  loadDataSet(info.getDataSourceInfo(), info.getObservationDataSetInfo().getDataSetName(),
255 
256  te::stmem::DataSource* inMemDataSource = static_cast<te::stmem::DataSource*>(m_ds.get());
257 
258  std::auto_ptr<te::da::DataSet> dset(inMemDataSource->getDataSet(
259  info.getObservationDataSetInfo().getDataSetName(), &geom, sr, &dt, tr, travType));
260 
261  return buildDataSet(static_cast<te::stmem::DataSet*>(dset.release()), info);
262 }
263 
265  std::vector<TimeSeriesDataSetInfo>& /*output*/)
266 {
267  return;
268 }
269 
270 std::auto_ptr<te::st::TimeSeriesDataSet>
272  te::common::TraverseType travType)
273 {
274  //load the DataSet from its origin DataSource and put it into the In-Mem DataSource
275  if(!m_ds->dataSetExists(info.getObservationDataSetInfo().getDataSetName()))
276  loadDataSet(info.getDataSourceInfo(), info.getObservationDataSetInfo().getDataSetName(),
280 
281  //get the data set
282  std::auto_ptr<te::da::DataSet> dset(m_ds->getDataSet(info.getObservationDataSetInfo().getDataSetName(), travType));
283 
284  return buildDataSet(static_cast<te::stmem::DataSet*>(dset.release()), info);
285 }
286 
287 std::auto_ptr<te::st::TimeSeriesDataSet>
290  te::common::TraverseType travType)
291 {
292  //load the DataSet from its origin DataSource and put it into the In-Mem DataSource
293  if(!m_ds->dataSetExists(info.getObservationDataSetInfo().getDataSetName()))
294  loadDataSet(info.getDataSourceInfo(), info.getObservationDataSetInfo().getDataSetName(),
298 
299  te::stmem::DataSource* inMemDataSource = static_cast<te::stmem::DataSource*>(m_ds.get());
300 
301  std::auto_ptr<te::da::DataSet> dset(inMemDataSource->getDataSet(
302  info.getObservationDataSetInfo().getDataSetName(), &dt, r, travType));
303 
304  return buildDataSet(static_cast<te::stmem::DataSet*>(dset.release()), info);
305 }
306 
307 std::auto_ptr<te::dt::DateTimePeriod>
309 {
310  //load the DataSet from its origin DataSource and put it into the In-Mem DataSource
311  if(!m_ds->dataSetExists(info.getDataSetName()))
312  loadDataSet(info.getDataSourceInfo(), info.getDataSetName(), info.getBeginTimePropIdx(),
313  info.getEndTimePropIdx(), info.getGeomPropIdx());
314 
315  te::stmem::DataSource* inMemDataSource = static_cast<te::stmem::DataSource*>(m_ds.get());
316 
317  return inMemDataSource->getTemporalExtent(info.getDataSetName());
318 }
319 
320 std::auto_ptr<te::dt::DateTimePeriod>
322 {
323  //load the DataSet from its origin DataSource and put it into the In-Mem DataSource
324  if(!m_ds->dataSetExists(info.getObservationDataSetInfo().getDataSetName()))
325  loadDataSet(info.getDataSourceInfo(), info.getObservationDataSetInfo().getDataSetName(),
329 
330  te::stmem::DataSource* inMemDataSource = static_cast<te::stmem::DataSource*>(m_ds.get());
331 
332  return inMemDataSource->getTemporalExtent(info.getObservationDataSetInfo().getDataSetName());
333 }
334 
335 std::auto_ptr<te::dt::DateTimePeriod>
337 {
338  //load the DataSet from its origin DataSource and put it into the In-Mem DataSource
339  if(!m_ds->dataSetExists(info.getObservationDataSetInfo().getDataSetName()))
340  loadDataSet(info.getDataSourceInfo(), info.getObservationDataSetInfo().getDataSetName(),
344 
345  te::stmem::DataSource* inMemDataSource = static_cast<te::stmem::DataSource*>(m_ds.get());
346 
347  return inMemDataSource->getTemporalExtent(info.getObservationDataSetInfo().getDataSetName());
348 }
349 
352 {
353  //load the DataSet from its origin DataSource and put it into the In-Mem DataSource
354  if(!m_ds->dataSetExists(info.getDataSetName()))
355  loadDataSet(info.getDataSourceInfo(), info.getDataSetName(), info.getBeginTimePropIdx(),
356  info.getEndTimePropIdx(), info.getGeomPropIdx());
357 
358  std::auto_ptr<te::gm::Envelope> res(m_ds->getExtent(info.getDataSetName(), info.getGeomPropIdx()));
359  return *res.get();
360 }
361 
364 {
365  //load the DataSet from its origin DataSource and put it into the In-Mem DataSource
366  if(!m_ds->dataSetExists(info.getObservationDataSetInfo().getDataSetName()))
367  loadDataSet(info.getDataSourceInfo(), info.getObservationDataSetInfo().getDataSetName(),
371 
372  std::auto_ptr<te::gm::Envelope> res(m_ds->getExtent(info.getObservationDataSetInfo().getDataSetName(),
374  return *res.get();
375 }
376 
377 //protected
378 void te::st::STDataLoaderFromMemDS::loadDataSet(const te::da::DataSourceInfo& info, const std::string dsname,
379  int begTimePropIdx, int endTimePropIdx, int gmPropIdx)
380 {
381  std::auto_ptr<te::da::DataSet> dset(te::da::GetDataSet(dsname, info.getId()));
382  if(!dset.get())
383  throw Exception("The DataSet was not loaded correctly!");
384 
385  std::auto_ptr<te::da::DataSetType> dsettype(te::da::GetDataSetType(dsname, info.getId()));
386  if(!dsettype.get())
387  throw Exception("The DataSetType was not loaded correctly!");
388 
389  //Before creating a stmem DataSet, we need to put it in a right place to be copied.
390  dset->moveNext();
391  te::stmem::DataSet* inMemdset = new te::stmem::DataSet(dset.get(), begTimePropIdx, endTimePropIdx, gmPropIdx, 0);
392 
393  //Add them into the in-mem data source
394  te::stmem::DataSource* memDS = static_cast<te::stmem::DataSource*>(m_ds.get());
395  memDS->add(dsname, dsettype.release(), inMemdset);
396 }
397 
398 std::auto_ptr<te::st::ObservationDataSet>
400 {
401  //get temporal and spatial extents
402  std::auto_ptr<te::dt::DateTimePeriod> period(ds->getTemporalExtent());
403  te::gm::Envelope ev;
404  if(info.getGeomPropIdx()>=0)
405  {
406  std::auto_ptr<te::gm::Envelope> aux = ds->getExtent(info.getGeomPropIdx());
407  ev = *aux.get();
408  }
409 
410  return std::auto_ptr<ObservationDataSet> (new ObservationDataSet(ds,
411  te::st::GetType(info), period.release(), ev));
412 }
413 
414 std::auto_ptr<te::st::TrajectoryDataSet>
416 {
417  //get temporal and spatial extents
418  std::auto_ptr<te::dt::DateTimePeriod> period(ds->getTemporalExtent());
419  std::auto_ptr<te::gm::Envelope> ev = ds->getExtent(info.getGeomPropIdx());
420 
421  return std::auto_ptr<TrajectoryDataSet> ( new TrajectoryDataSet(ds, te::st::GetType(info),
422  period.release(), *ev.get()));
423 }
424 
425 std::auto_ptr<te::st::TimeSeriesDataSet>
427 {
428  //get temporal and spatial extents
429  std::auto_ptr<te::dt::DateTimePeriod> period(ds->getTemporalExtent());
430 
431  return std::auto_ptr<TimeSeriesDataSet> ( new TimeSeriesDataSet(ds, te::st::GetType(info),
432  period.release()));
433 }
434 
436 {
437 }
438 
439 
440 
const te::da::DataSourceInfo & getDataSourceInfo() const
It returns the information about the DataSource.
void loadDataSet(const te::da::DataSourceInfo &info, const std::string dsname, int begTimePropIdx, int endTimePropIdx, int gmPropIdx)
It loads DataSet from the original DataSource and put it in the In-Memory DataSource.
std::auto_ptr< ObservationDataSet > buildDataSet(te::stmem::DataSet *ds, const ObservationDataSetInfo &info)
It builds an ObservationDataSet from a given DataSet.
A class that contains infos about a DataSet that contains observations of one or more time series...
This file contains a class responsible for loading spatiotemporal data from a ST in-memory DataSource...
const std::string & getId() const
A class that contains infos about a DataSet that contains observations.
void add(const std::string &name, te::da::DataSetType *t, DataSet *d)
It adds a new DataSet and DataSetType into the DataSource.
Definition: DataSource.cpp:179
std::auto_ptr< ObservationDataSet > getDataSet(const ObservationDataSetInfo &info, te::common::TraverseType travType=te::common::FORWARDONLY)
It returns a ObservationDataSet, that is, a DataSet that contains observations.
std::string getDataSetName() const
It returns the DataSet name.
Implementation of a in-memory data set that contains spatiotemporal observations indexed by time and ...
Definition: DataSet.h:61
A class that represents a data source component.
TEDATAACCESSEXPORT DataSet * GetDataSet(const std::string &name, const std::string &datasourceId)
Definition: Utils.cpp:209
int getBeginTimePropIdx() const
It returns the index of the DataSet property that contains the phenomenon beginning time...
static const std::string sm_STMemoryDataSourceId
The global id of the st memory data source.
Definition: Globals.h:51
SpatialRelation
Spatial relations between geometric objects.
Definition: Enums.h:122
A class to represent a DataSet that contains observations.
TESTEXPORT ObservationDataSetType GetType(const ObservationDataSetInfo &info)
An auxiliary function that transform ObservationDataSetInfo into ObservationDataSetType.
Definition: Utils.cpp:46
std::auto_ptr< te::dt::DateTimePeriod > getTemporalExtent(const std::string &name)
It returns the temporal extent associated to a DataSet.
Definition: DataSource.cpp:210
void getInfo(const TrajectoryDataSetInfo &input, std::vector< TrajectoryDataSetInfo > &output)
It returns the information about all trajectories that exist in a single DataSet. ...
A class to represent a time series data set.
std::auto_ptr< te::dt::DateTimePeriod > getTemporalExtent() const
It returns the temporal extent of the observations.
Definition: DataSet.cpp:338
Geometry is the root class of the geometries hierarchy, it follows OGC and ISO standards.
Definition: Geometry.h:73
TemporalRelation
Temporal relations between date and time (Source: Allen, 1991).
Definition: Enums.h:76
A class that contains infos about a DataSet that contains observations of one or more trajectories...
TEDATAACCESSEXPORT DataSetType * GetDataSetType(const std::string &name, const std::string &datasourceId)
Definition: Utils.cpp:224
Implements a DataSource that contains In-Memory DataSets indexed by space and time.
Definition: DataSource.h:57
TraverseType
A dataset can be traversed in two ways:
Definition: Enums.h:53
int getGeomPropIdx() const
It returns the index of the property that is a geometry property.
const te::da::DataSourceInfo & getDataSourceInfo() const
It returns information about the DataSource from which the DataSet comes.
int getEndTimePropIdx() const
It returns the index of the DataSet property that contains the phenomenon end time.
const ObservationDataSetInfo & getObservationDataSetInfo() const
It returns information about the DataSet that contians the time series observations.
const ObservationDataSetInfo & getObservationDataSetInfo() const
It returns information about the DataSet that contians the trajectory observations.
const te::da::DataSourceInfo & getDataSourceInfo() const
It returns information about the DataSource from which the DataSet comes.
static DataSourceManager & getInstance()
It returns a reference to the singleton instance.
int getGeomPropIdx() const
It returns the indexes of the DataSet properties that contains the geometries associated to the traje...
An Envelope defines a 2D rectangular region.
Definition: Envelope.h:51
te::gm::Envelope getSpatialExtent(const ObservationDataSetInfo &info)
It returns the temporal extent of the data set with observations of a coverage series.
A class to represent a trajectory data set.
std::auto_ptr< te::dt::DateTimePeriod > getTemporalExtent(const ObservationDataSetInfo &info)
It returns the temporal extent of the data set with observations.
std::auto_ptr< te::gm::Envelope > getExtent(std::size_t i)
It computes the bounding rectangle for a spatial property of the dataset.
Definition: DataSet.cpp:542