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) 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 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.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.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.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.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.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.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.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.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.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.getDataSourceInfo().getType()));
194  return impl->getDataSet(info, dt, r, travType);
195 }
196 
197 std::auto_ptr<te::st::CoverageSeries>
200 {
201  te::st::PointCoverageSeriesDataSetInfo::const_iterator it = info.begin();
202  std::auto_ptr<te::st::CoverageSeries> result(new CoverageSeries());
203  while(it!=info.end())
204  {
205  std::auto_ptr<PointCoverage> cv(getCoverage(*it, interp));
206  result->add(static_cast<te::dt::DateTime*>(cv->getTime()->clone()), cv.release());
207  ++it;
208  }
209 
210  return result;
211 }
212 
213 std::auto_ptr<te::st::CoverageSeries>
215 {
216  te::st::RasterCoverageSeriesDataSetInfo::const_iterator it = info.begin();
217  std::auto_ptr<te::st::CoverageSeries> result(new CoverageSeries());
218  while(it!=info.end())
219  {
220  std::auto_ptr<RasterCoverage> cv(getCoverage(*it));
221  result->add(static_cast<te::dt::DateTime*>(cv->getTime()->clone()), cv.release());
222  ++it;
223  }
224  return result;
225 }
226 
227 std::auto_ptr<te::st::RasterCoverage>
229 {
230  std::auto_ptr<te::da::DataSet> dset(te::da::GetDataSet(info.getObservationDataSetInfo().getDataSetName(),
231  info.getDataSourceInfo().getId()));
232  if(!dset.get())
233  throw Exception("The DataSet was not loaded correctly!");
234 
235  std::auto_ptr<te::st::RasterCoverage> result(new RasterCoverage());
236  while(dset->moveNext())
237  {
238  //por enquanto nao estou considerando tempo em duas propriedades, so pego a primeira
239  std::auto_ptr<te::dt::DateTime> dt = info.getTime();
240  if(dt.get()==0)
241  dt = dset->getDateTime(info.getTimePropIdxs()[0]);
242  std::auto_ptr<te::rst::Raster> raster(dset->getRaster(info.getRasterPropIdx()));
243  result->set(raster.release(), dt.release());
244  }
245  return result;
246 }
247 
248 std::auto_ptr<te::st::PointCoverage>
251 {
252  std::auto_ptr<te::da::DataSet> dset(te::da::GetDataSet(info.getObservationDataSetInfo().getDataSetName(),
253  info.getDataSourceInfo().getId()));
254  if(!dset.get())
255  throw Exception("The DataSet was not loaded correctly!");
256 
257  std::vector<int> vPropDS = info.getValuePropIdxs(); //The indexes of the observed properties in the DataSet
258  std::vector<int> ptypes;
259  std::vector<std::string> pnames;
260 
261  for(unsigned int i=0; i<vPropDS.size(); ++i)
262  {
263  ptypes.push_back(dset->getPropertyDataType(vPropDS[i]));
264  pnames.push_back(dset->getPropertyName(vPropDS[i]));
265  }
266 
267  //Get the property that has date and time associated to each observation
268  //TO DO: Ainda temos que implementar quando for periodo em duas properties!!!!
269  //TO DO: No caso acima, temos que gerar um periodo e passar para o PointCoverage como uma unica property!
270  int tpDS = -1;
271  int tpCV = -1;
272  const std::vector<int>& tProps = info.getTimePropIdxs();
273  if(tProps.size()>0 && tProps[0]>=0)
274  {
275  tpDS = tProps[0]; //index of the date and time property in the DataSet
276  ptypes.push_back(dset->getPropertyDataType(tpDS));
277  pnames.push_back(dset->getPropertyName(tpDS));
278  vPropDS.push_back(tpDS);
279  tpCV = ptypes.size()-1; //index of the date and time property in the Coverage
280  }
281 
282  std::auto_ptr<te::dt::DateTime> dt = info.getTime();
283  std::auto_ptr<te::st::PointCoverage> result(new PointCoverage(interp, 0, dt.get(), vPropDS.size(), ptypes, pnames, tpCV));
284 
285  while(dset->moveNext())
286  {
287  //get the point
288  std::auto_ptr<te::gm::Geometry> geom(dset->getGeometry(info.getPointPropIdx()));
289 
290  //get the observed values. If there is the date and time property, it will be loaded here!!!
291  boost::ptr_vector<te::dt::AbstractData> values;
292  for(unsigned int i=0; i<vPropDS.size(); ++i)
293  values.push_back(dset->getValue(vPropDS[i]));
294 
295  result->add(*static_cast<te::gm::Point*>(geom.release()), values); //values.release() ?????
296  }
297  return result;
298 }
299 
300 std::auto_ptr<te::dt::DateTimePeriod>
302 {
303  std::auto_ptr<STDataLoaderImpl> impl(STDataLoaderImplFactory::make(info.getDataSourceInfo().getType()));
304  return impl->getTemporalExtent(info);
305 }
306 
307 std::auto_ptr<te::dt::DateTimePeriod>
309 {
310  std::auto_ptr<STDataLoaderImpl> impl(STDataLoaderImplFactory::make(info.getDataSourceInfo().getType()));
311  return impl->getTemporalExtent(info);
312 }
313 
314 std::auto_ptr<te::dt::DateTimePeriod>
316 {
317  std::auto_ptr<STDataLoaderImpl> impl(STDataLoaderImplFactory::make(info.getDataSourceInfo().getType()));
318  return impl->getTemporalExtent(info);
319 }
320 
323 {
324  std::auto_ptr<STDataLoaderImpl> impl(STDataLoaderImplFactory::make(info.getDataSourceInfo().getType()));
325  return impl->getSpatialExtent(info);
326 }
327 
330 {
331  std::auto_ptr<STDataLoaderImpl> impl(STDataLoaderImplFactory::make(info.getDataSourceInfo().getType()));
332  return impl->getSpatialExtent(info);
333 }
334 
336 {
338  return;
341 }
342 
344 {
346  if(p.get()!=0)
347  p->close();
348 }
349 
351 {
352 }
353 
354 
355 
356 
357 
358 
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
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.
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. ...
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:76
An abstract class for interpolation function or interpolator that estimate values at non-observaved l...
int getPointPropIdx() const
It returns the property index that contains the points of the coverage.
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
std::auto_ptr< te::dt::DateTime > getTime() const
It returns the date and time associated to the raster coverage, when this information is not in the D...
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 te::da::DataSourceInfo & getDataSourceInfo() const
It returns information about the DataSource from which the DataSet comes.
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.
std::auto_ptr< te::dt::DateTime > getTime() const
It returns the date and time associated to the entire point coverage.
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
const te::da::DataSourceInfo & getDataSourceInfo() const
It returns information about the DataSource from which the DataSet comes.
const te::da::DataSourceInfo & getDataSourceInfo() const
It returns information about the DataSource from which the DataSet comes.
TEDATAACCESSEXPORT DataSet * GetDataSet(const std::string &name, const std::string &datasourceId)
Definition: Utils.cpp:210
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.
const std::vector< int > & getTimePropIdxs() const
It returns the indexes of the DataSet properties that contains the times associated to the coverage...
const std::vector< int > & getValuePropIdxs() const
It returns the property indexes that contains the values of the 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.
const std::vector< int > & getTimePropIdxs() const
It returns the indexes of the DataSet properties that contains the times associated to the coverage...
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:721
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.
const te::da::DataSourceInfo & getDataSourceInfo() const
It returns information about the DataSource from which the DataSet comes.
int getRasterPropIdx() const
It returns the property index that contains the raster of the coverage.
static void finalize()
It finalize the STDataLoader.