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) 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 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 #include <set>
42 
44  const std::vector<std::string>& propNames)
45 : m_obsDs(new ObservationDataSet(ds, type)),
46  m_vlPropNames(propNames),
47  m_id("")
48 {
49 }
50 
52  const std::vector<std::string>& propNames, const std::string& id)
53 : m_obsDs(new ObservationDataSet(ds, type)),
54  m_vlPropNames(propNames),
55  m_id(id)
56 {
57 }
58 
59 te::st::TimeSeriesDataSet::TimeSeriesDataSet( ObservationDataSet* obs, const std::vector<std::string>& propNames,
60  const std::string& id)
61  : m_obsDs(obs),
62  m_vlPropNames(propNames),
63  m_id(id)
64 {
65 }
66 
68 {
69  return m_obsDs.get();
70 }
71 
72 const std::vector<std::string>& te::st::TimeSeriesDataSet::getValuePropNames() const
73 {
74  return m_vlPropNames;
75 }
76 
77 void te::st::TimeSeriesDataSet::setValuePropNames(const std::vector<std::string>& n)
78 {
79  m_vlPropNames = n;
80 }
81 
83 {
84  return m_id;
85 }
86 
87 void te::st::TimeSeriesDataSet::setId(const std::string& id)
88 {
89  m_id = id;
90 }
91 
93 {
94  return m_obsDs->getData()->size();
95 }
96 
98 {
99  return m_obsDs->moveNext();
100 }
101 
103 {
104  return m_obsDs->movePrevious();
105 }
106 
108 {
109  return m_obsDs->moveFirst();
110 }
111 
113 {
114  return m_obsDs->moveBeforeFirst();
115 }
116 
118 {
119  return m_obsDs->moveLast();
120 }
121 
123 {
124  return m_obsDs->isAtBegin();
125 }
126 
128 {
129  return m_obsDs->isBeforeBegin();
130 }
131 
133 {
134  return m_obsDs->isAtEnd();
135 }
136 
138 {
139  return m_obsDs->isAfterEnd();
140 }
141 
142 std::auto_ptr<te::dt::DateTime> te::st::TimeSeriesDataSet::getTime() const
143 {
144  //TO DO: arrumar pro caso quando for period dividido em duas colunas
145  std::string phTimePropName = m_obsDs->getType().getBeginTimePropName();
146  return std::auto_ptr<te::dt::DateTime>(m_obsDs->getData()->getDateTime(phTimePropName));
147 }
148 
149 std::auto_ptr<te::dt::AbstractData> te::st::TimeSeriesDataSet::getValue(std::size_t idx) const
150 {
151  return std::auto_ptr<te::dt::AbstractData>(m_obsDs->getData()->getValue(idx));
152 }
153 
154 std::auto_ptr<te::dt::AbstractData> te::st::TimeSeriesDataSet::getValue() const
155 {
156  return std::auto_ptr<te::dt::AbstractData>(m_obsDs->getData()->getValue(m_vlPropNames[0]));
157 }
158 
159 double te::st::TimeSeriesDataSet::getDouble(std::size_t idx) const
160 {
161  return m_obsDs->getData()->getDouble(idx);
162 }
163 
165 {
166  return m_obsDs->getData()->getDouble(m_vlPropNames[0]);
167 }
168 
169 int te::st::TimeSeriesDataSet::getInt(std::size_t idx) const
170 {
171  return m_obsDs->getData()->getInt32(idx);
172 }
173 
175 {
176  return m_obsDs->getData()->getInt32(m_vlPropNames[0]);
177 }
178 
179 std::auto_ptr<te::gm::Geometry> te::st::TimeSeriesDataSet::getGeometry() const
180 {
181  if(m_obsDs->getType().hasGeomProp())
182  return std::auto_ptr<te::gm::Geometry>(m_obsDs->getData()->getGeometry(m_obsDs->getType().getGeomPropName()));
183  else if (m_obsDs->getType().hasGeometry())
184  return std::auto_ptr<te::gm::Geometry>(dynamic_cast<te::gm::Geometry*>(m_obsDs->getType().getGeometry()->clone()));
185  return std::auto_ptr<te::gm::Geometry>();
186 }
187 
189 {
190  return m_obsDs->getType().getTemporalExtent();
191 }
192 
194 {
195  return std::auto_ptr<te::st::TimeSeries>(getTimeSeries(m_vlPropNames[0],interp));
196 }
197 
198 std::auto_ptr<te::st::TimeSeries>
200 {
201  std::auto_ptr<te::st::TimeSeries> result(new TimeSeries(interp,m_id));
202  te::da::DataSet* ds = m_obsDs->getData();
203 
204  if(ds->moveNext())
205  {
206  //Get the time series location if there is one
207  std::auto_ptr<te::gm::Geometry> geom = getGeometry();
208  if(geom.get()!=0)
209  result->setLocation(geom.release());
210 
211  //Get time and value of time series
212  std::auto_ptr<te::dt::DateTime> time(ds->getDateTime(m_obsDs->getType().getBeginTimePropName()));
213  std::auto_ptr<te::dt::AbstractData> value(ds->getValue(propN));
214  result->add(time.release(), value.release());
215 
216  //Acquiring the timeSeries identification
217  std::auto_ptr<te::dt::AbstractData> tsid(ds->getValue(propN));
218  result->setId(tsid->toString());
219  }
220 
221  while(ds->moveNext())
222  {
223  //Get time and value of time series
224  std::auto_ptr<te::dt::DateTime> time(ds->getDateTime(m_obsDs->getType().getBeginTimePropName()));
225  std::auto_ptr<te::dt::AbstractData> value(ds->getValue(propN));
226  result->add(time.release(), value.release());
227  }
228  return result;
229 }
230 
232  const std::string& vPropName,
233  std::vector<te::st::TimeSeries*>& result)
234 {
235  te::da::DataSet* ds = m_obsDs->getData();
236  std::set<std::string> seriesIds;
237  size_t count = 0;
238 
239  while(ds->moveNext())
240  {
241  //Acquiring the timeSeries identification
242  std::auto_ptr<te::dt::AbstractData> tsid(ds->getValue(vPropName));
243 
244  if(seriesIds.insert(tsid->toString()).second)
245  {
246  TimeSeries* ts = new TimeSeries(interp,tsid->toString());
247  result.push_back(ts);
248 
249  //Get the time series location if there is one
250  std::auto_ptr<te::gm::Geometry> geom = getGeometry();
251  if(geom.get()!=0)
252  result[count]->setLocation(geom.release());
253 
254  count++;
255  }
256  else
257  {
258  std::auto_ptr<te::dt::DateTime> time(ds->getDateTime(m_obsDs->getType().getBeginTimePropName()));
259  std::auto_ptr<te::dt::AbstractData> value(ds->getValue(m_vlPropNames[0]));
260  result[count-1]->add(time.release(), value.release());
261  }
262  }
263  return;
264 }
265 
266 std::auto_ptr<te::da::DataSet> te::st::TimeSeriesDataSet::release()
267 {
268  std::auto_ptr<te::da::DataSet> result(m_obsDs->release());
269  return result;
270 }
271 
273 {
274 }
275 
276 
277 
278 
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.
This file contains a class to represent a time series data set.
const te::dt::DateTimePeriod * getTemporalExtent() const
It returns the temporal extent of the time series observations.
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 setValuePropNames(const std::vector< std::string > &n)
It sets the names of the DataSet properties that contains the values associated to the 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.
TimeSeriesDataSet(te::da::DataSet *ds, const ObservationDataSetType &type, const std::vector< std::string > &propNames)
Constructor.
std::auto_ptr< te::gm::Geometry > getGeometry() const
It returns the geometry pointed by the internal cursor.
std::auto_ptr< te::dt::DateTime > getTime() const
It returns the time pointed by the internal cursor.
void getTimeSeriesSet(te::st::AbstractTimeSeriesInterp *interp, const std::string &vPropName, std::vector< te::st::TimeSeries * > &result)
It returns all time series from the DataSet.
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
const std::vector< std::string > & getValuePropNames() const
It returns the indexes of the DataSet properties that contains the values associated to the time seri...
A class that contains complemental DataSetType information about a DataSet that holds observations...
std::auto_ptr< te::dt::AbstractData > getValue() const
It returns the observed value pointed by the internal cursor.
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