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 std::unique_ptr<te::st::ObservationDataSet>
57  te::common::TraverseType travType)
58 {
59  std::unique_ptr<STDataLoaderImpl> impl(STDataLoaderImplFactory::make(info.getDataSourceInfo().getType(), info.getDataSourceInfo().getConnInfoAsString()));
60  return impl->getDataSet(info, travType);
61 }
62 
63 std::unique_ptr<te::st::ObservationDataSet>
66 {
67  std::unique_ptr<STDataLoaderImpl> impl(STDataLoaderImplFactory::make(info.getDataSourceInfo().getType(), info.getDataSourceInfo().getConnInfoAsString()));
68  return impl->getDataSet(info, e, r, travType);
69 }
70 
71 std::unique_ptr<te::st::ObservationDataSet>
74 {
75  std::unique_ptr<STDataLoaderImpl> impl(STDataLoaderImplFactory::make(info.getDataSourceInfo().getType(), info.getDataSourceInfo().getConnInfoAsString()));
76  return impl->getDataSet(info, geom, r, travType);
77 }
78 
79 std::unique_ptr<te::st::ObservationDataSet>
82  te::common::TraverseType travType)
83 {
84  std::unique_ptr<STDataLoaderImpl> impl(STDataLoaderImplFactory::make(info.getDataSourceInfo().getType(), info.getDataSourceInfo().getConnInfoAsString()));
85  return impl->getDataSet(info, dt, r, travType);
86 }
87 
88 std::unique_ptr<te::st::ObservationDataSet>
90  const te::dt::DateTime& dt,
92  const te::gm::Envelope& e,
94  te::common::TraverseType travType)
95 {
96  std::unique_ptr<STDataLoaderImpl> impl(STDataLoaderImplFactory::make(info.getDataSourceInfo().getType(), info.getDataSourceInfo().getConnInfoAsString()));
97  return impl->getDataSet(info, dt, tr, e, sr, travType);
98 }
99 
100 std::unique_ptr<te::st::ObservationDataSet>
104  te::common::TraverseType travType)
105 {
106  std::unique_ptr<STDataLoaderImpl> impl(STDataLoaderImplFactory::make(info.getDataSourceInfo().getType(), info.getDataSourceInfo().getConnInfoAsString()));
107  return impl->getDataSet(info, geom, sr, dt, tr, travType);
108 }
109 
111  std::vector<te::st::TrajectoryDataSetInfo>& output)
112 {
113  std::unique_ptr<STDataLoaderImpl> impl(STDataLoaderImplFactory::make(input.getObservationDataSetInfo().getDataSourceInfo().getType(), input.getObservationDataSetInfo().getDataSourceInfo().getConnInfoAsString()));
114  return impl->getInfo(input, output);
115 }
116 
117 std::unique_ptr<te::st::TrajectoryDataSet>
119 {
120  std::unique_ptr<STDataLoaderImpl> impl(STDataLoaderImplFactory::make(info.getObservationDataSetInfo().getDataSourceInfo().getType(), info.getObservationDataSetInfo().getDataSourceInfo().getConnInfoAsString()));
121  return impl->getDataSet(info, travType);
122 }
123 
124 std::unique_ptr<te::st::TrajectoryDataSet> te::st::STDataLoader::getDataSet(
125  const TrajectoryDataSetInfo& info, const te::gm::Geometry& /*geom*/,
127 {
128  std::unique_ptr<STDataLoaderImpl> impl(STDataLoaderImplFactory::make(info.getObservationDataSetInfo().getDataSourceInfo().getType(), info.getObservationDataSetInfo().getDataSourceInfo().getConnInfoAsString()));
129  return impl->getDataSet(info, travType);
130 }
131 
132 std::unique_ptr<te::st::TrajectoryDataSet>
134  te::common::TraverseType travType)
135 {
136  std::unique_ptr<STDataLoaderImpl> impl(STDataLoaderImplFactory::make(info.getObservationDataSetInfo().getDataSourceInfo().getType(), info.getObservationDataSetInfo().getDataSourceInfo().getConnInfoAsString()));
137  return impl->getDataSet(info, e, r, travType);
138 }
139 
140 std::unique_ptr<te::st::TrajectoryDataSet>
143  te::common::TraverseType travType)
144 {
145  std::unique_ptr<STDataLoaderImpl> impl(STDataLoaderImplFactory::make(info.getObservationDataSetInfo().getDataSourceInfo().getType(), info.getObservationDataSetInfo().getDataSourceInfo().getConnInfoAsString()));
146  return impl->getDataSet(info, dt, r, travType);
147 }
148 
149 std::unique_ptr<te::st::TrajectoryDataSet>
151  const te::dt::DateTime& dt,
153  const te::gm::Envelope& e,
155  te::common::TraverseType travType)
156 {
157  std::unique_ptr<STDataLoaderImpl> impl(STDataLoaderImplFactory::make(info.getObservationDataSetInfo().getDataSourceInfo().getType(), info.getObservationDataSetInfo().getDataSourceInfo().getConnInfoAsString()));
158  return impl->getDataSet(info, dt, tr, e, sr, travType);
159 }
160 
161 std::unique_ptr<te::st::TrajectoryDataSet>
165 {
166  std::unique_ptr<STDataLoaderImpl> impl(STDataLoaderImplFactory::make(info.getObservationDataSetInfo().getDataSourceInfo().getType(), info.getObservationDataSetInfo().getDataSourceInfo().getConnInfoAsString()));
167  return impl->getDataSet(info, geom, sr, dt, tr, travType);
168 }
169 
170 
172  std::vector<te::st::TimeSeriesDataSetInfo>& output)
173 {
174  std::unique_ptr<STDataLoaderImpl> impl(STDataLoaderImplFactory::make(input.getObservationDataSetInfo().getDataSourceInfo().getType(), input.getObservationDataSetInfo().getDataSourceInfo().getConnInfoAsString()));
175  return impl->getInfo(input, output);
176 }
177 
178 std::unique_ptr<te::st::TimeSeriesDataSet>
180 {
181  std::unique_ptr<STDataLoaderImpl> impl(STDataLoaderImplFactory::make(info.getObservationDataSetInfo().getDataSourceInfo().getType(), info.getObservationDataSetInfo().getDataSourceInfo().getConnInfoAsString()));
182  return impl->getDataSet(info, travType);
183 }
184 
185 std::unique_ptr<te::st::TimeSeriesDataSet>
188  te::common::TraverseType travType)
189 {
190  std::unique_ptr<STDataLoaderImpl> impl(STDataLoaderImplFactory::make(info.getObservationDataSetInfo().getDataSourceInfo().getType(), info.getObservationDataSetInfo().getDataSourceInfo().getConnInfoAsString()));
191  return impl->getDataSet(info, dt, r, travType);
192 }
193 
194 std::unique_ptr<te::st::TimeSeriesDataSet>
197  te::common::TraverseType travType)
198 {
199  std::unique_ptr<STDataLoaderImpl> impl(STDataLoaderImplFactory::make(info.getObservationDataSetInfo().getDataSourceInfo().getType(), info.getObservationDataSetInfo().getDataSourceInfo().getConnInfoAsString()));
200  return impl->getDataSet(info, e, r, travType);
201 }
202 
203 std::unique_ptr<te::st::TimeSeriesDataSet>
206  te::common::TraverseType travType)
207 {
208  std::unique_ptr<STDataLoaderImpl> impl(STDataLoaderImplFactory::make(info.getObservationDataSetInfo().getDataSourceInfo().getType(), info.getObservationDataSetInfo().getDataSourceInfo().getConnInfoAsString()));
209  return impl->getDataSet(info, geom, r, travType);
210 }
211 
212 std::unique_ptr<te::st::TimeSeriesDataSet>
214  const te::dt::DateTime& dt,
216  const te::gm::Envelope& e,
218  te::common::TraverseType travType)
219 {
220  std::unique_ptr<STDataLoaderImpl> impl(STDataLoaderImplFactory::make(info.getObservationDataSetInfo().getDataSourceInfo().getType(), info.getObservationDataSetInfo().getDataSourceInfo().getConnInfoAsString()));
221  return impl->getDataSet(info, dt, tr, e, sr, travType);
222 }
223 
224 std::unique_ptr<te::st::TimeSeriesDataSet>
228  te::common::TraverseType travType)
229 {
230  std::unique_ptr<STDataLoaderImpl> impl(STDataLoaderImplFactory::make(info.getObservationDataSetInfo().getDataSourceInfo().getType(), info.getObservationDataSetInfo().getDataSourceInfo().getConnInfoAsString()));
231  return impl->getDataSet(info, geom, sr, dt, tr, travType);
232 }
233 
234 std::unique_ptr<te::st::CoverageSeries>
237 {
238  te::st::PointCoverageSeriesDataSetInfo::const_iterator it = info.begin();
239  std::unique_ptr<te::st::CoverageSeries> result(new CoverageSeries());
240  while(it!=info.end())
241  {
242  std::unique_ptr<PointCoverage> cv(getCoverage(*it, interp));
243  result->add(static_cast<te::dt::DateTime*>(cv->getTime()->clone()), cv.release());
244  ++it;
245  }
246 
247  return result;
248 }
249 
250 std::unique_ptr<te::st::CoverageSeries>
252 {
253  te::st::RasterCoverageSeriesDataSetInfo::const_iterator it = info.begin();
254  std::unique_ptr<te::st::CoverageSeries> result(new CoverageSeries());
255  while(it!=info.end())
256  {
257  std::unique_ptr<RasterCoverage> cv(getCoverage(*it));
258  result->add(static_cast<te::dt::DateTime*>(cv->getTime()->clone()), cv.release());
259  ++it;
260  }
261  return result;
262 }
263 
264 std::unique_ptr<te::st::RasterCoverage>
266 {
267  std::unique_ptr<te::da::DataSet> dset(te::da::GetDataSet(info.getObservationDataSetInfo().getDataSetName(),
269  if(!dset.get())
270  throw Exception("The DataSet was not loaded correctly!");
271 
272  std::unique_ptr<te::st::RasterCoverage> result(new RasterCoverage());
273  while(dset->moveNext())
274  {
275  //por enquanto nao estou considerando tempo em duas propriedades, so pego a primeira
276  std::unique_ptr<te::dt::DateTime> dt;
277  if(info.getObservationDataSetInfo().getTime()!=nullptr)
278  dt.reset(dynamic_cast<te::dt::DateTime*>(info.getObservationDataSetInfo().getTime()->clone()));
279  else
280  dt = dset->getDateTime(info.getObservationDataSetInfo().getBeginTimePropName());
281 
282  std::unique_ptr<te::rst::Raster> raster(dset->getRaster(info.getRasterPropName()));
283  result->set(raster.release(), dt.release());
284  }
285  return result;
286 }
287 
288 std::unique_ptr<te::st::PointCoverage>
291 {
292  std::unique_ptr<te::da::DataSet> dset(te::da::GetDataSet(info.getObservationDataSetInfo().getDataSetName(),
294  if(!dset.get())
295  throw Exception("The DataSet was not loaded correctly!");
296 
297  std::vector<std::string> vPropDS = info.getValuePropNames(); //The indexes of the observed properties in the DataSet
298  std::vector<int> ptypes;
299  std::vector<std::string> pnames;
300 
301  for(unsigned int i=0; i<vPropDS.size(); ++i)
302  {
303  std::size_t idx = te::da::GetPropertyPos(dset.get(), vPropDS[i]);
304  ptypes.push_back(dset->getPropertyDataType(idx));
305  pnames.push_back(vPropDS[i]);
306  }
307 
308  //Get the property that has date and time associated to each observation
309  //TO DO: Ainda temos que implementar quando for periodo em duas properties!!!!
310  //TO DO: No caso acima, temos que gerar um periodo e passar para o PointCoverage como uma unica property!
311  std::string tpDS;
312  int tpCV = -1;
313  const std::string& tPropName = info.getObservationDataSetInfo().getBeginTimePropName();
314  if(!tPropName.empty())
315  {
316  tpDS = tPropName; //name of the date and time property in the DataSet
317  std::size_t idx = te::da::GetPropertyPos(dset.get(), tPropName);
318  ptypes.push_back(dset->getPropertyDataType(idx));
319  pnames.push_back(tpDS);
320  vPropDS.push_back(tpDS);
321  tpCV = static_cast<unsigned int>(ptypes.size() - 1); //index of the date and time property in the Coverage
322  }
323 
324  std::unique_ptr<te::dt::DateTime> dt(dynamic_cast<te::dt::DateTime*>(info.getObservationDataSetInfo().getTime()->clone()));
325 
326  std::unique_ptr<te::st::PointCoverage> result(new PointCoverage(interp, nullptr, dt.release(), static_cast<int>(vPropDS.size()), ptypes, pnames, tpCV));
327 
328  while(dset->moveNext())
329  {
330  //get the point
331  std::unique_ptr<te::gm::Geometry> geom(dset->getGeometry(info.getObservationDataSetInfo().getGeomPropName()));
332 
333  //get the observed values. If there is the date and time property, it will be loaded here!!!
334  boost::ptr_vector<te::dt::AbstractData> values;
335  for(unsigned int i=0; i<vPropDS.size(); ++i)
336  values.push_back(dset->getValue(vPropDS[i]).release());
337 
338  result->add(*static_cast<te::gm::Point*>(geom.release()), values); //values.release() ?????
339  }
340  return result;
341 }
342 
343 std::unique_ptr<te::dt::DateTimePeriod>
345 {
346  std::unique_ptr<STDataLoaderImpl> impl(STDataLoaderImplFactory::make(info.getDataSourceInfo().getType(), info.getDataSourceInfo().getConnInfoAsString()));
347  return impl->getTemporalExtent(info);
348 }
349 
350 std::unique_ptr<te::dt::DateTimePeriod>
352 {
353  std::unique_ptr<STDataLoaderImpl> impl(STDataLoaderImplFactory::make(info.getObservationDataSetInfo().getDataSourceInfo().getType(), info.getObservationDataSetInfo().getDataSourceInfo().getConnInfoAsString()));
354  return impl->getTemporalExtent(info);
355 }
356 
357 std::unique_ptr<te::dt::DateTimePeriod>
359 {
360  std::unique_ptr<STDataLoaderImpl> impl(STDataLoaderImplFactory::make(info.getObservationDataSetInfo().getDataSourceInfo().getType(), info.getObservationDataSetInfo().getDataSourceInfo().getConnInfoAsString()));
361  return impl->getTemporalExtent(info);
362 }
363 
366 {
367  std::unique_ptr<STDataLoaderImpl> impl(STDataLoaderImplFactory::make(info.getDataSourceInfo().getType(), info.getDataSourceInfo().getConnInfoAsString()));
368  return impl->getSpatialExtent(info);
369 }
370 
373 {
374  std::unique_ptr<STDataLoaderImpl> impl(STDataLoaderImplFactory::make(info.getObservationDataSetInfo().getDataSourceInfo().getType(), info.getObservationDataSetInfo().getDataSourceInfo().getConnInfoAsString()));
375  return impl->getSpatialExtent(info);
376 }
377 
379 {
381  return;
384 }
385 
387 {
389  if(p.get()!=nullptr)
390  p->close();
391 }
392 
static void getInfo(const TrajectoryDataSetInfo &input, std::vector< TrajectoryDataSetInfo > &output)
It returns the information about all trajectories that exist in a single DataSet. ...
static const std::string sm_STMemoryDataSourceId
The global id of the st memory data source.
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 std::unique_ptr< CoverageSeries > getCoverageSeries(const PointCoverageSeriesDataSetInfo &info, AbstractPointCoverageInterp *interp)
It returns a point coverage series.
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
A class that contains infos about a DataSet that contains observations.
Base exception class for plugin module.
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).
TEDATAACCESSEXPORT std::size_t GetPropertyPos(const DataSet *dataset, const std::string &name)
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.
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.
static std::unique_ptr< RasterCoverage > getCoverage(const RasterCoverageDataSetInfo &info)
It returns a raster coverage.
virtual ~STDataLoader()
Virtual destructor.
TraverseType
A dataset can be traversed in two ways:
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.
static te::dt::TimeDuration dt(20, 30, 50, 11)
TEDATAACCESSEXPORT DataSet * GetDataSet(const std::string &name, const std::string &datasourceId)
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.
const te::da::DataSourceInfo & getDataSourceInfo() const
It returns the information about the DataSource.
te::gm::Polygon * p
virtual AbstractData * clone() const =0
It returns a clone of this object.
Geometry is the root class of the geometries hierarchy, it follows OGC and ISO standards.
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.
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
const std::string getConnInfoAsString() const
std::string getDataSetName() const
It returns the DataSet name.
static std::unique_ptr< te::dt::DateTimePeriod > getTemporalExtent(const ObservationDataSetInfo &info)
It returns the temporal extent of the data set with observations.
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.