All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator 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 {
53 }
54 
55 std::auto_ptr<te::st::ObservationDataSet>
57  te::common::TraverseType travType)
58 {
59  std::auto_ptr<STDataLoaderImpl> impl(STDataLoaderImplFactory::make(info.getDataSourceInfo().getType()));
60  return impl->getDataSet(info, travType);
61 }
62 
63 std::auto_ptr<te::st::ObservationDataSet>
66 {
67  std::auto_ptr<STDataLoaderImpl> impl(STDataLoaderImplFactory::make(info.getDataSourceInfo().getType()));
68  return impl->getDataSet(info, e, r, travType);
69 }
70 
71 std::auto_ptr<te::st::ObservationDataSet>
74 {
75  std::auto_ptr<STDataLoaderImpl> impl(STDataLoaderImplFactory::make(info.getDataSourceInfo().getType()));
76  return impl->getDataSet(info, geom, r, travType);
77 }
78 
79 std::auto_ptr<te::st::ObservationDataSet>
82  te::common::TraverseType travType)
83 {
84  std::auto_ptr<STDataLoaderImpl> impl(STDataLoaderImplFactory::make(info.getDataSourceInfo().getType()));
85  return impl->getDataSet(info, dt, r, travType);
86 }
87 
88 std::auto_ptr<te::st::ObservationDataSet>
92  te::common::TraverseType travType)
93 {
94  std::auto_ptr<STDataLoaderImpl> impl(STDataLoaderImplFactory::make(info.getDataSourceInfo().getType()));
95  return impl->getDataSet(info, geom, sr, dt, tr, travType);
96 }
97 
99  std::vector<te::st::TrajectoryDataSetInfo>& output)
100 {
101  std::auto_ptr<STDataLoaderImpl> impl(STDataLoaderImplFactory::make(input.getDataSourceInfo().getType()));
102  return impl->getInfo(input, output);
103 }
104 
105 std::auto_ptr<te::st::TrajectoryDataSet>
107 {
108  std::auto_ptr<STDataLoaderImpl> impl(STDataLoaderImplFactory::make(info.getDataSourceInfo().getType()));
109  return impl->getDataSet(info, travType);
110 }
111 
112 std::auto_ptr<te::st::TrajectoryDataSet>
115  te::common::TraverseType travType)
116 {
117  std::auto_ptr<STDataLoaderImpl> impl(STDataLoaderImplFactory::make(info.getDataSourceInfo().getType()));
118  return impl->getDataSet(info, travType);
119 }
120 
121 std::auto_ptr<te::st::TrajectoryDataSet>
123  te::common::TraverseType travType)
124 {
125  std::auto_ptr<STDataLoaderImpl> impl(STDataLoaderImplFactory::make(info.getDataSourceInfo().getType()));
126  return impl->getDataSet(info, e, r, travType);
127 }
128 
129 
130 std::auto_ptr<te::st::TrajectoryDataSet>
133  te::common::TraverseType travType)
134 {
135  std::auto_ptr<STDataLoaderImpl> impl(STDataLoaderImplFactory::make(info.getDataSourceInfo().getType()));
136  return impl->getDataSet(info, dt, r, travType);
137 }
138 
139 std::auto_ptr<te::st::TrajectoryDataSet>
143 {
144  std::auto_ptr<STDataLoaderImpl> impl(STDataLoaderImplFactory::make(info.getDataSourceInfo().getType()));
145  return impl->getDataSet(info, geom, sr, dt, tr, travType);
146 }
147 
148 
150  std::vector<te::st::TimeSeriesDataSetInfo>& output)
151 {
152  std::auto_ptr<STDataLoaderImpl> impl(STDataLoaderImplFactory::make(input.getDataSourceInfo().getType()));
153  return impl->getInfo(input, output);
154 }
155 
156 std::auto_ptr<te::st::TimeSeriesDataSet>
158 {
159  std::auto_ptr<STDataLoaderImpl> impl(STDataLoaderImplFactory::make(info.getDataSourceInfo().getType()));
160  return impl->getDataSet(info, travType);
161 }
162 
163 std::auto_ptr<te::st::TimeSeriesDataSet>
166  te::common::TraverseType travType)
167 {
168  std::auto_ptr<STDataLoaderImpl> impl(STDataLoaderImplFactory::make(info.getDataSourceInfo().getType()));
169  return impl->getDataSet(info, dt, r, travType);
170 }
171 
172 std::auto_ptr<te::st::CoverageSeries>
175 {
176  te::st::PointCoverageSeriesDataSetInfo::const_iterator it = info.begin();
177  std::auto_ptr<te::st::CoverageSeries> result(new CoverageSeries());
178  while(it!=info.end())
179  {
180  std::auto_ptr<PointCoverage> cv(getCoverage(*it, interp));
181  result->add(static_cast<te::dt::DateTime*>(cv->getTime()->clone()), cv.release());
182  ++it;
183  }
184 
185  return result;
186 }
187 
188 std::auto_ptr<te::st::CoverageSeries>
190 {
191  te::st::RasterCoverageSeriesDataSetInfo::const_iterator it = info.begin();
192  std::auto_ptr<te::st::CoverageSeries> result(new CoverageSeries());
193  while(it!=info.end())
194  {
195  std::auto_ptr<RasterCoverage> cv(getCoverage(*it));
196  result->add(static_cast<te::dt::DateTime*>(cv->getTime()->clone()), cv.release());
197  ++it;
198  }
199  return result;
200 }
201 
202 std::auto_ptr<te::st::RasterCoverage>
204 {
205  std::auto_ptr<te::da::DataSet> dset(te::da::GetDataSet(info.getObservationDataSetInfo().getDataSetName(),
206  info.getDataSourceInfo().getId()));
207  if(!dset.get())
208  throw Exception("The DataSet was not loaded correctly!");
209 
210  std::auto_ptr<te::st::RasterCoverage> result(new RasterCoverage());
211  while(dset->moveNext())
212  {
213  //por enquanto nao estou considerando tempo em duas propriedades, so pego a primeira
214  std::auto_ptr<te::dt::DateTime> dt = info.getTime();
215  if(dt.get()==0)
216  dt = dset->getDateTime(info.getTimePropIdxs()[0]);
217  std::auto_ptr<te::rst::Raster> raster(dset->getRaster(info.getRasterPropIdx()));
218  result->set(raster.release(), dt.release());
219  }
220  return result;
221 }
222 
223 std::auto_ptr<te::st::PointCoverage>
226 {
227  std::auto_ptr<te::da::DataSet> dset(te::da::GetDataSet(info.getObservationDataSetInfo().getDataSetName(),
228  info.getDataSourceInfo().getId()));
229  if(!dset.get())
230  throw Exception("The DataSet was not loaded correctly!");
231 
232  std::vector<int> vPropDS = info.getValuePropIdxs(); //The indexes of the observed properties in the DataSet
233  std::vector<int> ptypes;
234  std::vector<std::string> pnames;
235 
236  for(unsigned int i=0; i<vPropDS.size(); ++i)
237  {
238  ptypes.push_back(dset->getPropertyDataType(vPropDS[i]));
239  pnames.push_back(dset->getPropertyName(vPropDS[i]));
240  }
241 
242  //Get the property that has date and time associated to each observation
243  //TO DO: Ainda temos que implementar quando for periodo em duas properties!!!!
244  //TO DO: No caso acima, temos que gerar um periodo e passar para o PointCoverage como uma unica property!
245  int tpDS = -1;
246  int tpCV = -1;
247  const std::vector<int>& tProps = info.getTimePropIdxs();
248  if(tProps.size()>0 && tProps[0]>=0)
249  {
250  tpDS = tProps[0]; //index of the date and time property in the DataSet
251  ptypes.push_back(dset->getPropertyDataType(tpDS));
252  pnames.push_back(dset->getPropertyName(tpDS));
253  vPropDS.push_back(tpDS);
254  tpCV = ptypes.size()-1; //index of the date and time property in the Coverage
255  }
256 
257  std::auto_ptr<te::dt::DateTime> dt = info.getTime();
258  std::auto_ptr<te::st::PointCoverage> result(new PointCoverage(interp, 0, dt.get(), vPropDS.size(), ptypes, pnames, tpCV));
259 
260  while(dset->moveNext())
261  {
262  //get the point
263  std::auto_ptr<te::gm::Geometry> geom(dset->getGeometry(info.getPointPropIdx()));
264 
265  //get the observed values. If there is the date and time property, it will be loaded here!!!
266  boost::ptr_vector<te::dt::AbstractData> values;
267  for(unsigned int i=0; i<vPropDS.size(); ++i)
268  values.push_back(dset->getValue(vPropDS[i]));
269 
270  result->add(*static_cast<te::gm::Point*>(geom.release()), values); //values.release() ?????
271  }
272  return result;
273 }
274 
275 std::auto_ptr<te::dt::DateTimePeriod>
277 {
278  std::auto_ptr<STDataLoaderImpl> impl(STDataLoaderImplFactory::make(info.getDataSourceInfo().getType()));
279  return impl->getTemporalExtent(info);
280 }
281 
282 std::auto_ptr<te::dt::DateTimePeriod>
284 {
285  std::auto_ptr<STDataLoaderImpl> impl(STDataLoaderImplFactory::make(info.getDataSourceInfo().getType()));
286  return impl->getTemporalExtent(info);
287 }
288 
289 std::auto_ptr<te::dt::DateTimePeriod>
291 {
292  std::auto_ptr<STDataLoaderImpl> impl(STDataLoaderImplFactory::make(info.getDataSourceInfo().getType()));
293  return impl->getTemporalExtent(info);
294 }
295 
298 {
299  std::auto_ptr<STDataLoaderImpl> impl(STDataLoaderImplFactory::make(info.getDataSourceInfo().getType()));
300  return impl->getSpatialExtent(info);
301 }
302 
305 {
306  std::auto_ptr<STDataLoaderImpl> impl(STDataLoaderImplFactory::make(info.getDataSourceInfo().getType()));
307  return impl->getSpatialExtent(info);
308 }
309 
311 {
313 }
314 
316 {
318  if(p.get()!=0)
319  p->close();
320 }
321 
323 {
324 }
325 
326 
327 
328 
329 
330 
const te::da::DataSourceInfo & getDataSourceInfo() const
It returns the information about the DataSource.
std::vector< RasterCoverageDataSetInfo > RasterCoverageSeriesDataSetInfo
const std::vector< int > & getTimePropIdxs() const
It returns the indexes of the DataSet properties that contains the times associated to the coverage...
const ObservationDataSetInfo & getObservationDataSetInfo() const
It returns information about the DataSet that contains the coverage observations. ...
A class that contains infos about a DataSet that contains observations of one or more time series...
const std::string & getId() const
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 > & getValuePropIdxs() const
It returns the property indexes that contains the values of the coverage.
int getPointPropIdx() const
It returns the property index that contains the points of the coverage.
int getRasterPropIdx() const
It returns the property index that contains the raster of the coverage.
A class that contains infos about a DataSet that contains observations.
An abstract class for interpolation function or interpolator that estimate values at non-observaved l...
std::string getDataSetName() const
It returns the DataSet name.
A concrete class to represent a point coverage.
Definition: PointCoverage.h:69
TEDATAACCESSEXPORT DataSet * GetDataSet(const std::string &name, const std::string &datasourceId)
Definition: Utils.cpp:209
A concrete class to represent a raster coverage.
static std::auto_ptr< RasterCoverage > getCoverage(const RasterCoverageDataSetInfo &info)
It returns a raster coverage.
std::vector< PointCoverageDataSetInfo > PointCoverageSeriesDataSetInfo
static const std::string sm_STMemoryDataSourceId
The global id of the st memory data source.
Definition: Globals.h:51
virtual ~STDataLoader()
Virtual destructor.
SpatialRelation
Spatial relations between geometric objects.
Definition: Enums.h:122
This file contains an abstract class responsible for loading spatiotemporal data from data sources...
static void finalize()
It finalize the STDataLoader.
static te::gm::Envelope getSpatialExtent(const ObservationDataSetInfo &info)
It returns the temporal extent of the data set with 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.
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...
static std::auto_ptr< CoverageSeries > getCoverageSeries(const PointCoverageSeriesDataSetInfo &info, AbstractPointCoverageInterp *interp)
It returns a point coverage series.
STDataLoader()
Protected constructor.
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...
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.
boost::shared_ptr< DataSource > DataSourcePtr
Definition: DataSource.h:1395
const std::string & getType() const
TraverseType
A dataset can be traversed in two ways:
Definition: Enums.h:53
const te::da::DataSourceInfo & getDataSourceInfo() const
It returns information about the DataSource from which the DataSet comes.
const std::vector< int > & getTimePropIdxs() const
It returns the indexes of the DataSet properties that contains the times associated to the coverage...
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.
This is the abstract factory for STDataLoaderImpl.
This file contains a class that contains a set of static methods to load spatiotemporal data from dat...
static void getInfo(const TrajectoryDataSetInfo &input, std::vector< TrajectoryDataSetInfo > &output)
It returns the information about all trajectories that exist in a single DataSet. ...
A class that contains infos about a DataSource and DataSet that contains observations of a point cove...
A class to represent a coverage series.
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.
An Envelope defines a 2D rectangular region.
Definition: Envelope.h:51
static void initialize()
It returns the spatial extent of the observations of a coverage series.
const ObservationDataSetInfo & getObservationDataSetInfo() const
It returns information about the DataSet that contains the coverage observations. ...
A class that contains infos about a DataSource and DataSet that contains observations of a raster cov...