All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
STDataLoader.cpp
Go to the documentation of this file.
1 /* Copyright (C) 2008 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 STDataLoader.cpp
22 
23  \brief This file contains a class that contains a set of static methods
24  to load spatiotemporal data from data sources.
25 */
26 
27 //TerraLib
28 #include "../../dataaccess/datasource/DataSourceInfo.h"
29 #include "../../dataaccess/utils/Utils.h"
30 #include "../../dataaccess/datasource/DataSourceManager.h"
31 
32 //ST
33 #include "STDataLoader.h"
34 #include "STDataLoaderImpl.h"
36 #include "../core/observation/ObservationDataSet.h"
37 #include "../core/observation/ObservationDataSetInfo.h"
38 #include "../core/trajectory/TrajectoryDataSet.h"
39 #include "../core/trajectory/TrajectoryDataSetInfo.h"
40 #include "../core/timeseries/TimeSeriesDataSet.h"
41 #include "../core/timeseries/TimeSeriesDataSetInfo.h"
42 #include "../core/coverage/CoverageSeries.h"
43 #include "../core/coverage/Coverage.h"
44 #include "../core/coverage/PointCoverage.h"
45 #include "../core/coverage/RasterCoverage.h"
46 #include "../core/coverage/RasterCoverageDataSetInfo.h"
47 #include "../core/coverage/PointCoverageDataSetInfo.h"
48 #include "../Exception.h"
49 #include "../Globals.h"
50 
52 
54 {
55 }
56 
57 std::auto_ptr<te::st::ObservationDataSet>
59  te::common::TraverseType travType)
60 {
61  std::auto_ptr<STDataLoaderImpl> impl(STDataLoaderImplFactory::make(info.getDataSourceInfo().getType()));
62  return impl->getDataSet(info, travType);
63 }
64 
65 std::auto_ptr<te::st::ObservationDataSet>
68 {
69  std::auto_ptr<STDataLoaderImpl> impl(STDataLoaderImplFactory::make(info.getDataSourceInfo().getType()));
70  return impl->getDataSet(info, e, r, travType);
71 }
72 
73 std::auto_ptr<te::st::ObservationDataSet>
76 {
77  std::auto_ptr<STDataLoaderImpl> impl(STDataLoaderImplFactory::make(info.getDataSourceInfo().getType()));
78  return impl->getDataSet(info, geom, r, travType);
79 }
80 
81 std::auto_ptr<te::st::ObservationDataSet>
84  te::common::TraverseType travType)
85 {
86  std::auto_ptr<STDataLoaderImpl> impl(STDataLoaderImplFactory::make(info.getDataSourceInfo().getType()));
87  return impl->getDataSet(info, dt, r, travType);
88 }
89 
90 std::auto_ptr<te::st::ObservationDataSet>
92  const te::dt::DateTime& dt,
94  const te::gm::Envelope& e,
96  te::common::TraverseType travType)
97 {
98  std::auto_ptr<STDataLoaderImpl> impl(STDataLoaderImplFactory::make(info.getDataSourceInfo().getType()));
99  return impl->getDataSet(info, dt, tr, e, sr, travType);
100 }
101 
102 std::auto_ptr<te::st::ObservationDataSet>
106  te::common::TraverseType travType)
107 {
108  std::auto_ptr<STDataLoaderImpl> impl(STDataLoaderImplFactory::make(info.getDataSourceInfo().getType()));
109  return impl->getDataSet(info, geom, sr, dt, tr, travType);
110 }
111 
113  std::vector<te::st::TrajectoryDataSetInfo>& output)
114 {
115  std::auto_ptr<STDataLoaderImpl> impl(STDataLoaderImplFactory::make(input.getObservationDataSetInfo().getDataSourceInfo().getType()));
116  return impl->getInfo(input, output);
117 }
118 
119 std::auto_ptr<te::st::TrajectoryDataSet>
121 {
122  std::auto_ptr<STDataLoaderImpl> impl(STDataLoaderImplFactory::make(info.getObservationDataSetInfo().getDataSourceInfo().getType()));
123  return impl->getDataSet(info, travType);
124 }
125 
126 std::auto_ptr<te::st::TrajectoryDataSet>
129  te::common::TraverseType travType)
130 {
131  std::auto_ptr<STDataLoaderImpl> impl(STDataLoaderImplFactory::make(info.getObservationDataSetInfo().getDataSourceInfo().getType()));
132  return impl->getDataSet(info, travType);
133 }
134 
135 std::auto_ptr<te::st::TrajectoryDataSet>
137  te::common::TraverseType travType)
138 {
139  std::auto_ptr<STDataLoaderImpl> impl(STDataLoaderImplFactory::make(info.getObservationDataSetInfo().getDataSourceInfo().getType()));
140  return impl->getDataSet(info, e, r, travType);
141 }
142 
143 std::auto_ptr<te::st::TrajectoryDataSet>
146  te::common::TraverseType travType)
147 {
148  std::auto_ptr<STDataLoaderImpl> impl(STDataLoaderImplFactory::make(info.getObservationDataSetInfo().getDataSourceInfo().getType()));
149  return impl->getDataSet(info, dt, r, travType);
150 }
151 
152 std::auto_ptr<te::st::TrajectoryDataSet>
154  const te::dt::DateTime& dt,
156  const te::gm::Envelope& e,
158  te::common::TraverseType travType)
159 {
160  std::auto_ptr<STDataLoaderImpl> impl(STDataLoaderImplFactory::make(info.getObservationDataSetInfo().getDataSourceInfo().getType()));
161  return impl->getDataSet(info, dt, tr, e, sr, travType);
162 }
163 
164 std::auto_ptr<te::st::TrajectoryDataSet>
168 {
169  std::auto_ptr<STDataLoaderImpl> impl(STDataLoaderImplFactory::make(info.getObservationDataSetInfo().getDataSourceInfo().getType()));
170  return impl->getDataSet(info, geom, sr, dt, tr, travType);
171 }
172 
173 
175  std::vector<te::st::TimeSeriesDataSetInfo>& output)
176 {
177  std::auto_ptr<STDataLoaderImpl> impl(STDataLoaderImplFactory::make(input.getObservationDataSetInfo().getDataSourceInfo().getType()));
178  return impl->getInfo(input, output);
179 }
180 
181 std::auto_ptr<te::st::TimeSeriesDataSet>
183 {
184  std::auto_ptr<STDataLoaderImpl> impl(STDataLoaderImplFactory::make(info.getObservationDataSetInfo().getDataSourceInfo().getType()));
185  return impl->getDataSet(info, travType);
186 }
187 
188 std::auto_ptr<te::st::TimeSeriesDataSet>
191  te::common::TraverseType travType)
192 {
193  std::auto_ptr<STDataLoaderImpl> impl(STDataLoaderImplFactory::make(info.getObservationDataSetInfo().getDataSourceInfo().getType()));
194  return impl->getDataSet(info, dt, r, travType);
195 }
196 
197 std::auto_ptr<te::st::TimeSeriesDataSet>
200  te::common::TraverseType travType)
201 {
202  std::auto_ptr<STDataLoaderImpl> impl(STDataLoaderImplFactory::make(info.getObservationDataSetInfo().getDataSourceInfo().getType()));
203  return impl->getDataSet(info, e, r, travType);
204 }
205 
206 std::auto_ptr<te::st::TimeSeriesDataSet>
209  te::common::TraverseType travType)
210 {
211  std::auto_ptr<STDataLoaderImpl> impl(STDataLoaderImplFactory::make(info.getObservationDataSetInfo().getDataSourceInfo().getType()));
212  return impl->getDataSet(info, geom, r, travType);
213 }
214 
215 std::auto_ptr<te::st::TimeSeriesDataSet>
217  const te::dt::DateTime& dt,
219  const te::gm::Envelope& e,
221  te::common::TraverseType travType)
222 {
223  std::auto_ptr<STDataLoaderImpl> impl(STDataLoaderImplFactory::make(info.getObservationDataSetInfo().getDataSourceInfo().getType()));
224  return impl->getDataSet(info, dt, tr, e, sr, travType);
225 }
226 
227 std::auto_ptr<te::st::TimeSeriesDataSet>
231  te::common::TraverseType travType)
232 {
233  std::auto_ptr<STDataLoaderImpl> impl(STDataLoaderImplFactory::make(info.getObservationDataSetInfo().getDataSourceInfo().getType()));
234  return impl->getDataSet(info, geom, sr, dt, tr, travType);
235 }
236 
237 std::auto_ptr<te::st::CoverageSeries>
240 {
241  te::st::PointCoverageSeriesDataSetInfo::const_iterator it = info.begin();
242  std::auto_ptr<te::st::CoverageSeries> result(new CoverageSeries());
243  while(it!=info.end())
244  {
245  std::auto_ptr<PointCoverage> cv(getCoverage(*it, interp));
246  result->add(static_cast<te::dt::DateTime*>(cv->getTime()->clone()), cv.release());
247  ++it;
248  }
249 
250  return result;
251 }
252 
253 std::auto_ptr<te::st::CoverageSeries>
255 {
256  te::st::RasterCoverageSeriesDataSetInfo::const_iterator it = info.begin();
257  std::auto_ptr<te::st::CoverageSeries> result(new CoverageSeries());
258  while(it!=info.end())
259  {
260  std::auto_ptr<RasterCoverage> cv(getCoverage(*it));
261  result->add(static_cast<te::dt::DateTime*>(cv->getTime()->clone()), cv.release());
262  ++it;
263  }
264  return result;
265 }
266 
267 std::auto_ptr<te::st::RasterCoverage>
269 {
270  std::auto_ptr<te::da::DataSet> dset(te::da::GetDataSet(info.getObservationDataSetInfo().getDataSetName(),
272  if(!dset.get())
273  throw Exception("The DataSet was not loaded correctly!");
274 
275  std::auto_ptr<te::st::RasterCoverage> result(new RasterCoverage());
276  while(dset->moveNext())
277  {
278  //por enquanto nao estou considerando tempo em duas propriedades, so pego a primeira
279  std::auto_ptr<te::dt::DateTime> dt;
280  if(info.getObservationDataSetInfo().getTime()!=0)
281  dt.reset(dynamic_cast<te::dt::DateTime*>(info.getObservationDataSetInfo().getTime()->clone()));
282  else
283  dt = dset->getDateTime(info.getObservationDataSetInfo().getBeginTimePropName());
284 
285  std::auto_ptr<te::rst::Raster> raster(dset->getRaster(info.getRasterPropName()));
286  result->set(raster.release(), dt.release());
287  }
288  return result;
289 }
290 
291 std::auto_ptr<te::st::PointCoverage>
294 {
295  std::auto_ptr<te::da::DataSet> dset(te::da::GetDataSet(info.getObservationDataSetInfo().getDataSetName(),
297  if(!dset.get())
298  throw Exception("The DataSet was not loaded correctly!");
299 
300  std::vector<std::string> vPropDS = info.getValuePropNames(); //The indexes of the observed properties in the DataSet
301  std::vector<int> ptypes;
302  std::vector<std::string> pnames;
303 
304  for(unsigned int i=0; i<vPropDS.size(); ++i)
305  {
306  std::size_t idx = te::da::GetPropertyPos(dset.get(), vPropDS[i]);
307  ptypes.push_back(dset->getPropertyDataType(idx));
308  pnames.push_back(vPropDS[i]);
309  }
310 
311  //Get the property that has date and time associated to each observation
312  //TO DO: Ainda temos que implementar quando for periodo em duas properties!!!!
313  //TO DO: No caso acima, temos que gerar um periodo e passar para o PointCoverage como uma unica property!
314  std::string tpDS = "";
315  int tpCV = -1;
316  const std::string& tPropName = info.getObservationDataSetInfo().getBeginTimePropName();
317  if(!tPropName.empty())
318  {
319  tpDS = tPropName; //name of the date and time property in the DataSet
320  std::size_t idx = te::da::GetPropertyPos(dset.get(), tPropName);
321  ptypes.push_back(dset->getPropertyDataType(idx));
322  pnames.push_back(tpDS);
323  vPropDS.push_back(tpDS);
324  tpCV = ptypes.size()-1; //index of the date and time property in the Coverage
325  }
326 
327  std::auto_ptr<te::dt::DateTime> dt(dynamic_cast<te::dt::DateTime*>(info.getObservationDataSetInfo().getTime()->clone()));
328 
329  std::auto_ptr<te::st::PointCoverage> result(new PointCoverage(interp, 0, dt.release(), vPropDS.size(), ptypes, pnames, tpCV));
330 
331  while(dset->moveNext())
332  {
333  //get the point
334  std::auto_ptr<te::gm::Geometry> geom(dset->getGeometry(info.getObservationDataSetInfo().getGeomPropName()));
335 
336  //get the observed values. If there is the date and time property, it will be loaded here!!!
337  boost::ptr_vector<te::dt::AbstractData> values;
338  for(unsigned int i=0; i<vPropDS.size(); ++i)
339  values.push_back(dset->getValue(vPropDS[i]));
340 
341  result->add(*static_cast<te::gm::Point*>(geom.release()), values); //values.release() ?????
342  }
343  return result;
344 }
345 
346 std::auto_ptr<te::dt::DateTimePeriod>
348 {
349  std::auto_ptr<STDataLoaderImpl> impl(STDataLoaderImplFactory::make(info.getDataSourceInfo().getType()));
350  return impl->getTemporalExtent(info);
351 }
352 
353 std::auto_ptr<te::dt::DateTimePeriod>
355 {
356  std::auto_ptr<STDataLoaderImpl> impl(STDataLoaderImplFactory::make(info.getObservationDataSetInfo().getDataSourceInfo().getType()));
357  return impl->getTemporalExtent(info);
358 }
359 
360 std::auto_ptr<te::dt::DateTimePeriod>
362 {
363  std::auto_ptr<STDataLoaderImpl> impl(STDataLoaderImplFactory::make(info.getObservationDataSetInfo().getDataSourceInfo().getType()));
364  return impl->getTemporalExtent(info);
365 }
366 
369 {
370  std::auto_ptr<STDataLoaderImpl> impl(STDataLoaderImplFactory::make(info.getDataSourceInfo().getType()));
371  return impl->getSpatialExtent(info);
372 }
373 
376 {
377  std::auto_ptr<STDataLoaderImpl> impl(STDataLoaderImplFactory::make(info.getObservationDataSetInfo().getDataSourceInfo().getType()));
378  return impl->getSpatialExtent(info);
379 }
380 
382 {
384  return;
387 }
388 
390 {
392  if(p.get()!=0)
393  p->close();
394 }
395 
397 {
398 }
399 
400 
401 
402 
403 
404 
static void getInfo(const TrajectoryDataSetInfo &input, std::vector< TrajectoryDataSetInfo > &output)
It returns the information about all trajectories that exist in a single DataSet. ...
static std::auto_ptr< RasterCoverage > getCoverage(const RasterCoverageDataSetInfo &info)
It returns a raster coverage.
static const std::string sm_STMemoryDataSourceId
The global id of the st memory data source.
Definition: Globals.h:51
std::string getBeginTimePropName() const
It returns the name of the DataSet property that contains the phenomenon beginning time...
A concrete class to represent a point coverage.
Definition: PointCoverage.h:70
static te::gm::Envelope getSpatialExtent(const ObservationDataSetInfo &info)
It returns the temporal extent of the data set with observations of a coverage series.
const te::dt::DateTime * getTime() const
It returns the phenomenon time.
boost::shared_ptr< DataSource > DataSourcePtr
Definition: DataSource.h:1435
A class that contains infos about a DataSet that contains observations.
const ObservationDataSetInfo & getObservationDataSetInfo() const
It returns information about the DataSet that contains the coverage observations. ...
std::string getGeomPropName() const
It returns the name of the property that is a geometry property.
const std::string & getRasterPropName() const
It returns the property index that contains the raster of the coverage.
This file contains an abstract class responsible for loading spatiotemporal data from data sources...
TemporalRelation
Temporal relations between date and time (Source: Allen, 1991).
Definition: Enums.h:140
TEDATAACCESSEXPORT std::size_t GetPropertyPos(const DataSet *dataset, const std::string &name)
Definition: Utils.cpp:500
An abstract class for interpolation function or interpolator that estimate values at non-observaved l...
const ObservationDataSetInfo & getObservationDataSetInfo() const
It returns information about the DataSet that contains the time series observations.
SpatialRelation
Spatial relations between geometric objects.
Definition: Enums.h:122
std::vector< RasterCoverageDataSetInfo > RasterCoverageSeriesDataSetInfo
A class that contains infos about a DataSource and DataSet that contains observations of a point cove...
std::vector< PointCoverageDataSetInfo > PointCoverageSeriesDataSetInfo
const ObservationDataSetInfo & getObservationDataSetInfo() const
It returns information about the DataSet that contains the coverage observations. ...
This file contains a class that contains a set of static methods to load spatiotemporal data from dat...
const ObservationDataSetInfo & getObservationDataSetInfo() const
It returns information about the DataSet that contains the trajectory observations.
virtual ~STDataLoader()
Virtual destructor.
TraverseType
A dataset can be traversed in two ways:
Definition: Enums.h:53
static void initialize()
It returns the spatial extent of the observations of a coverage series.
STDataLoader()
Protected constructor.
static DataSourceManager & getInstance()
It returns a reference to the singleton instance.
An Envelope defines a 2D rectangular region.
Definition: Envelope.h:51
TEDATAACCESSEXPORT DataSet * GetDataSet(const std::string &name, const std::string &datasourceId)
Definition: Utils.cpp:213
const te::da::DataSourceInfo & getDataSourceInfo() const
It returns the information about the DataSource.
static std::auto_ptr< CoverageSeries > getCoverageSeries(const PointCoverageSeriesDataSetInfo &info, AbstractPointCoverageInterp *interp)
It returns a point coverage series.
Geometry is the root class of the geometries hierarchy, it follows OGC and ISO standards.
Definition: Geometry.h:73
A concrete class to represent a raster coverage.
A class that contains infos about a DataSet that contains observations of one or more trajectories...
const std::string & getId() const
This is the abstract factory for STDataLoaderImpl.
A class to represent a coverage series.
static std::auto_ptr< te::dt::DateTimePeriod > getTemporalExtent(const ObservationDataSetInfo &info)
It returns the temporal extent of the data set with observations.
A class that contains infos about a DataSet that contains observations of one or more time series...
static bool sm_STDataLoaderInitialized
Indictes if the st data loader support was initialized.
Definition: STDataLoader.h:816
A class that contains infos about a DataSource and DataSet that contains observations of a raster cov...
const std::string & getType() const
std::string getDataSetName() const
It returns the DataSet name.
static 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.
virtual AbstractData * clone() const =0
It returns a clone of this object.
const std::vector< std::string > & getValuePropNames() const
It returns the property names that contains the values of the coverage.
static void finalize()
It finalize the STDataLoader.