All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
TimeSeriesDataSet.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 TimeSeriesDataSet.cpp
22 
23  \brief This file contains a class to represent a time series data set.
24 */
25 
26 // TerraLib
27 #include "../../../dataaccess/dataset/DataSet.h"
28 #include "../../../datatype/DateTime.h"
29 #include "../../../datatype/DateTimePeriod.h"
30 #include "../../../datatype/DateTimeInstant.h"
31 #include "../../../datatype/SimpleData.h"
32 #include "../../../geometry/Geometry.h"
33 #include "../../../geometry/Utils.h"
34 
35 //ST
36 #include "TimeSeriesDataSet.h"
37 #include "TimeSeries.h"
38 #include "../observation/ObservationDataSet.h"
39 #include "../observation/ObservationDataSetType.h"
40 
41 
42 te::st::TimeSeriesDataSet::TimeSeriesDataSet( te::da::DataSet* ds, int tPropIdx, int vPropIdx, int gPropIdx,
43  int idPropIdx, const std::string& id)
44 : m_obsDs(new ObservationDataSet(ds, tPropIdx, vPropIdx, gPropIdx)),
45  m_type(tPropIdx, vPropIdx, gPropIdx, idPropIdx, id),
46  m_id(id)
47 {
48 }
49 
50 te::st::TimeSeriesDataSet::TimeSeriesDataSet(te::da::DataSet* ds, int tPropIdx, int vPropIdx, int gPropIdx,
51  int idPropIdx, const std::string& id, te::dt::DateTimePeriod* text)
52 : m_obsDs(new ObservationDataSet(ds, tPropIdx, vPropIdx, gPropIdx, text)),
53  m_type(tPropIdx, vPropIdx, gPropIdx, idPropIdx, id),
54  m_id(id)
55 {
56 }
57 
58 te::st::TimeSeriesDataSet::TimeSeriesDataSet(te::da::DataSet* ds, const std::vector<int>& tPropIdxs,
59  const std::vector<int>& vPropIdxs,
60  int gPropIdx, int idPropIdx, const std::string& id)
61 : m_obsDs(new ObservationDataSet(ds, tPropIdxs, vPropIdxs, gPropIdx)),
62  m_type(tPropIdxs, vPropIdxs, gPropIdx, idPropIdx, id),
63  m_id(id)
64 {
65 }
66 
67 te::st::TimeSeriesDataSet::TimeSeriesDataSet(te::da::DataSet* ds, const std::vector<int>& tPropIdxs,
68  const std::vector<int>& vPropIdxs, int gPropIdx, int idPropIdx,
69  const std::string& id, te::dt::DateTimePeriod* text)
70 : m_obsDs(new ObservationDataSet(ds, tPropIdxs, vPropIdxs, gPropIdx, text)),
71  m_type(tPropIdxs, vPropIdxs, gPropIdx, idPropIdx, id),
72  m_id(id)
73 {
74 }
75 
78 : m_obsDs(new ObservationDataSet(ds, type.getType(), text)),
79  m_type(type),
80  m_id(type.getId())
81 {
82 
83 }
84 
86  const TimeSeriesDataSetType& type, const std::string& id)
87  : m_obsDs(obs),
88  m_type(type),
89  m_id(id)
90 {
91 }
92 
94 {
95  return m_obsDs.get();
96 }
97 
99 {
100  return m_type;
101 }
102 
104 {
105  return m_id;
106 }
107 
108 void te::st::TimeSeriesDataSet::setId(const std::string& id)
109 {
110  m_id = id;
111 }
112 
114 {
115  return m_obsDs->getData()->size();
116 }
117 
119 {
120  return m_obsDs->moveNext();
121 }
122 
124 {
125  return m_obsDs->movePrevious();
126 }
127 
129 {
130  return m_obsDs->moveFirst();
131 }
132 
134 {
135  return m_obsDs->moveBeforeFirst();
136 }
137 
139 {
140  return m_obsDs->moveLast();
141 }
142 
144 {
145  return m_obsDs->isAtBegin();
146 }
147 
149 {
150  return m_obsDs->isBeforeBegin();
151 }
152 
154 {
155  return m_obsDs->isAtEnd();
156 }
157 
159 {
160  return m_obsDs->isAfterEnd();
161 }
162 
163 std::auto_ptr<te::dt::DateTime> te::st::TimeSeriesDataSet::getTime() const
164 {
165  //TO DO: arrumar pro caso quando for period dividido em duas colunas
166  int phTimePropIdx = m_type.getBeginTimePropIdx();
167  return std::auto_ptr<te::dt::DateTime>(m_obsDs->getData()->getDateTime(phTimePropIdx));
168 }
169 
170 std::auto_ptr<te::dt::AbstractData> te::st::TimeSeriesDataSet::getValue(std::size_t idx) const
171 {
172  return std::auto_ptr<te::dt::AbstractData>(m_obsDs->getData()->getValue(idx));
173 }
174 
175 std::auto_ptr<te::dt::AbstractData>te::st::TimeSeriesDataSet::getValue() const
176 {
177  return std::auto_ptr<te::dt::AbstractData>(m_obsDs->getData()->getValue(m_type.getValuePropIdx()[0]));
178 }
179 
180 double te::st::TimeSeriesDataSet::getDouble(std::size_t idx) const
181 {
182  return m_obsDs->getData()->getDouble(idx);
183 }
184 
186 {
187  return m_obsDs->getData()->getDouble(m_type.getValuePropIdx()[0]);
188 }
189 
190 int te::st::TimeSeriesDataSet::getInt(std::size_t idx) const
191 {
192  return m_obsDs->getData()->getInt32(idx);
193 }
194 
196 {
197  return m_obsDs->getData()->getInt32(m_type.getValuePropIdx()[0]);
198 }
199 
200 std::auto_ptr<te::gm::Geometry> te::st::TimeSeriesDataSet::getGeometry() const
201 {
202  return std::auto_ptr<te::gm::Geometry>(m_obsDs->getData()->getGeometry(m_type.getGeomPropIdx()));
203 }
204 
206 {
207  return m_obsDs->getTemporalExtent();
208 }
209 
211 {
212  return std::auto_ptr<te::st::TimeSeries>(getTimeSeries(m_type.getValuePropIdx()[0],interp));
213 }
214 
215 std::auto_ptr<te::st::TimeSeries> te::st::TimeSeriesDataSet::getTimeSeries(int idx, te::st::AbstractTimeSeriesInterp* interp)
216 {
217  std::auto_ptr<te::st::TimeSeries> result(new TimeSeries(interp,m_id));
218  te::da::DataSet* ds = m_obsDs->getData();
219 
220  if(ds->moveNext())
221  {
222  //Get the time series location if there is one
223  if(m_type.getGeomPropIdx()>-1)
224  {
225  std::auto_ptr<te::gm::Geometry> geom(ds->getGeometry(m_type.getGeomPropIdx()));
226  result->setLocation(geom.release());
227  }
228 
229  //Get time and value of time series
230  std::auto_ptr<te::dt::DateTime> time(ds->getDateTime(m_type.getBeginTimePropIdx()));
231  std::auto_ptr<te::dt::AbstractData> value(ds->getValue(idx));
232  result->add(time.release(), value.release());
233  }
234 
235  while(ds->moveNext())
236  {
237  //Get time and value of time series
238  std::auto_ptr<te::dt::DateTime> time(ds->getDateTime(m_type.getBeginTimePropIdx()));
239  std::auto_ptr<te::dt::AbstractData> value(ds->getValue(idx));
240  result->add(time.release(), value.release());
241  }
242  return result;
243 }
244 
246  std::vector<te::st::TimeSeries*>& result)
247 {
248  std::size_t sz = m_type.getValuePropIdx().size();
249  for(unsigned int i = 0; i<sz; ++i)
250  {
251  TimeSeries* ts = new TimeSeries(interp,m_id);
252  result.push_back(ts);
253  }
254 
255  te::da::DataSet* ds = m_obsDs->getData();
256 
257  if(ds->moveNext())
258  {
259  for(unsigned int i = 0; i<sz; ++i)
260  {
261  //Get the time series location if there is one
262  if(m_type.getGeomPropIdx()>-1)
263  {
264  std::auto_ptr<te::gm::Geometry> geom(ds->getGeometry(m_type.getGeomPropIdx()));
265  result[i]->setLocation(geom.release());
266  }
267 
268  //Get time and value of time series
269  std::auto_ptr<te::dt::DateTime> time(ds->getDateTime(m_type.getBeginTimePropIdx()));
270  std::auto_ptr<te::dt::AbstractData> value(ds->getValue(m_type.getValuePropIdx()[i]));
271  result[i]->add(time.release(), value.release());
272  }
273  }
274 
275  while(ds->moveNext())
276  {
277  for(unsigned int i = 0; i<sz; ++i)
278  {
279  //Get time and value of time series
280  std::auto_ptr<te::dt::DateTime> time(ds->getDateTime(m_type.getBeginTimePropIdx()));
281  std::auto_ptr<te::dt::AbstractData> value(ds->getValue(m_type.getValuePropIdx()[i]));
282  result[i]->add(time.release(), value.release());
283  }
284  }
285  return;
286 }
287 
288 std::auto_ptr<te::da::DataSet> te::st::TimeSeriesDataSet::release()
289 {
290  std::auto_ptr<te::da::DataSet> result(m_obsDs->release());
291  return result;
292 }
293 
295 {
296 }
297 
298 
299 
300 
TimeSeriesDataSet(te::da::DataSet *ds, int tPropIdx, int vPropIdx, int gPropIdx, int idPropIdx, const std::string &id)
Constructor.
virtual std::auto_ptr< te::dt::DateTime > getDateTime(std::size_t i) const =0
Method for retrieving a date and time attribute value.
std::auto_ptr< TimeSeries > getTimeSeries(te::st::AbstractTimeSeriesInterp *interp)
It returns the time series from the DataSet.
std::size_t size() const
It returns the size of the time series observation set.
A class to represent a DataSet that contains observations.
ObservationDataSet * getObservationSet() const
It returns the data set that contains the time series observations.
int getInt() const
It returns the observed value as double pointed by the internal cursor.
double getDouble() const
It returns the observed value as double pointed by the internal cursor.
A class that contains complemental information about a DataSet that holds observations of a time seri...
This file contains a class to represent a time series data set.
const TimeSeriesDataSetType & getType() const
It returns a reference to the internal time series data set type.
std::auto_ptr< te::da::DataSet > release()
It releases all internal pointers, returning its internal DataSet and invalidating itself...
This file contains a class to represent a time series.
void setId(const std::string &id)
It sets the identifier associated to the time series.
virtual bool moveNext()=0
It moves the internal pointer to the next item of the collection.
std::auto_ptr< te::gm::Geometry > getGeometry() const
It returns the geometry pointed by the internal cursor.
void getTimeSeriesSet(te::st::AbstractTimeSeriesInterp *interp, std::vector< te::st::TimeSeries * > &result)
It returns all time series from the DataSet.
std::auto_ptr< te::dt::DateTime > getTime() const
virtual std::auto_ptr< te::gm::Geometry > getGeometry(std::size_t i) const =0
Method for retrieving a geometric attribute value.
A dataset is the unit of information manipulated by the data access module of TerraLib.
Definition: DataSet.h:112
virtual ~TimeSeriesDataSet()
It returns the trajectory geometry property.
An abstract class for an interpolation function or interpolator that estimate a value at non-observav...
An abstract class to represent a period of date and time.
A class to represent time series.
Definition: TimeSeries.h:66
std::auto_ptr< te::dt::AbstractData > getValue() const
It returns the observed value pointed by the internal cursor.
te::dt::DateTimePeriod * getTemporalExtent() const
It returns the temporal extent of the time series observations.
std::string getId() const
It returns the identifier associated to the time series.
virtual std::auto_ptr< te::dt::AbstractData > getValue(std::size_t i) const
Method for retrieving any other type of data value stored in the data source.
Definition: DataSet.cpp:151