All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
TimeSeriesDataSetLayer.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 terralib/st/maptools/TimeSeriesDataSetLayer.cpp
22 
23  \brief A layer with a reference to an TimeSeriesDataSet.
24 */
25 
26 // TerraLib
27 #include "../../dataaccess/query/DataSetName.h"
28 #include "../../dataaccess/query/Field.h"
29 #include "../../dataaccess/query/Fields.h"
30 #include "../../dataaccess/query/From.h"
31 #include "../../dataaccess/query/FromItem.h"
32 #include "../../dataaccess/query/Select.h"
33 #include "../../dataaccess/query/SpatialQueryProcessor.h"
34 #include "../../dataaccess/query/Where.h"
35 #include "../../dataaccess/utils/Utils.h"
36 #include "../../datatype/DateTime.h"
37 #include "../../datatype/DateTimePeriod.h"
38 #include "../../maptools/Exception.h"
39 #include "../../maptools/RendererFactory.h"
40 #include "../core/observation/ObservationDataSet.h"
41 #include "../core/timeseries/TimeSeriesDataSetInfo.h"
42 #include "../core/timeseries/TimeSeriesDataSet.h"
43 #include "../loader/STDataLoader.h"
44 #include "TimeSeriesDataSetLayer.h"
45 
46 // Boost
47 #include <boost/format.hpp>
48 
49 const std::string te::st::TimeSeriesDataSetLayer::sm_type("TIMESERIESDATASETLAYER");
50 
52  : AbstractSTDataSetLayer(parent),
53  m_info(info)
54 {
55 }
56 
57 te::st::TimeSeriesDataSetLayer::TimeSeriesDataSetLayer(const std::string& id, AbstractLayer* parent, TimeSeriesDataSetInfo* info)
58  : AbstractSTDataSetLayer(id, parent),
59  m_info(info)
60 {
61 }
62 
64  const std::string& title, AbstractLayer* parent,
66  : AbstractSTDataSetLayer(id, title, parent),
67  m_info(info)
68 {
69 }
70 
72 {
73 }
74 
75 std::auto_ptr<te::map::LayerSchema> te::st::TimeSeriesDataSetLayer::getSchema() const
76 {
77  assert(!m_info->getObservationDataSetInfo().getDataSetName().empty());
78 
79  te::da::DataSourcePtr ds = te::da::GetDataSource(m_info->getObservationDataSetInfo().getDataSourceInfo().getId(), true);
80 
81  return ds->getDataSetType(m_info->getObservationDataSetInfo().getDataSetName());
82 }
83 
85 {
86  return 0;
87  //return te::st::STDataLoader::getDataSet(*m_info.get())->getTemporalExtent();
88 }
89 
90 // -----------------------------------------------------------------------------------------------------------------------
91 
92 std::auto_ptr<te::da::DataSet> te::st::TimeSeriesDataSetLayer::getData(te::common::TraverseType travType,
93  const te::common::AccessPolicy accessPolicy) const
94 {
95  std::auto_ptr<te::st::TimeSeriesDataSet> tds = te::st::TimeSeriesDataSetLayer::getTimeSeriesDataset(travType);
96  std::auto_ptr<te::da::DataSet> result = tds->release();
97  return result;
98 }
99 
100 std::auto_ptr<te::da::DataSet> te::st::TimeSeriesDataSetLayer::getData(const std::string& propertyName,
101  const te::gm::Envelope* e,
103  te::common::TraverseType travType,
104  const te::common::AccessPolicy accessPolicy) const
105 {
106  std::auto_ptr<te::st::TimeSeriesDataSet> tsds = te::st::TimeSeriesDataSetLayer::getTimeSeriesDataset(*e, r, travType);
107  std::auto_ptr<te::da::DataSet> result = tsds->release();
108  return result;
109 }
110 
111 std::auto_ptr<te::da::DataSet> te::st::TimeSeriesDataSetLayer::getData(const std::string& propertyName,
112  const te::gm::Geometry* g,
114  te::common::TraverseType travType,
115  const te::common::AccessPolicy accessPolicy) const
116 {
117  std::auto_ptr<te::st::TimeSeriesDataSet> tsds = te::st::TimeSeriesDataSetLayer::getTimeSeriesDataset(*g, r, travType);
118  std::auto_ptr<te::da::DataSet> result = tsds->release();
119  return result;
120 }
121 
122 std::auto_ptr<te::da::DataSet> te::st::TimeSeriesDataSetLayer::getData(te::da::Expression* restriction,
123  te::common::TraverseType travType,
124  const te::common::AccessPolicy accessPolicy) const
125 {
126  std::auto_ptr<te::da::DataSet> result;
127  return result;
128 }
129 
130 std::auto_ptr<te::da::DataSet> te::st::TimeSeriesDataSetLayer::getData(const te::da::ObjectIdSet* oids,
131  te::common::TraverseType travType,
132  const te::common::AccessPolicy accessPolicy) const
133 {
134  std::auto_ptr<te::da::DataSet> result;
135  return result;
136 }
137 
138 std::auto_ptr<te::st::TimeSeriesDataSet> te::st::TimeSeriesDataSetLayer::getTimeSeriesDataset(te::common::TraverseType travType) const
139 {
140  return te::st::STDataLoader::getDataSet(*m_info.get(), travType);
141 }
142 
143 std::auto_ptr<te::st::TimeSeriesDataSet> te::st::TimeSeriesDataSetLayer::getTimeSeriesDataset(const te::gm::Envelope& e,
145  te::common::TraverseType travType) const
146 {
147  return te::st::STDataLoader::getDataSet(*m_info.get(), e, r, travType);
148 }
149 
150 std::auto_ptr<te::st::TimeSeriesDataSet> te::st::TimeSeriesDataSetLayer::getTimeSeriesDataset(const te::gm::Geometry& g,
152  te::common::TraverseType travType) const
153 {
154  return te::st::STDataLoader::getDataSet(*m_info.get(), g, r, travType);
155 }
156 
158  te::common::TraverseType travType,
159  te::common::AccessPolicy rwRole) const
160 {
161  std::auto_ptr<te::st::TimeSeriesDataSet> tds = te::st::TimeSeriesDataSetLayer::getTimeSeriesDataset(dt, r, travType);
162  std::auto_ptr<te::da::DataSet> result = tds->release();
163  return result;
164 }
165 
166 
169  te::common::TraverseType travType,
170  te::common::AccessPolicy rwRole) const
171 {
172  std::auto_ptr<te::st::TimeSeriesDataSet> tds = te::st::TimeSeriesDataSetLayer::getTimeSeriesDataset(dt, tr, e, sr, travType);
173  std::auto_ptr<te::da::DataSet> result = tds->release();
174  return result;
175 }
176 
179  te::common::TraverseType travType,
180  te::common::AccessPolicy rwRole) const
181 {
182  std::auto_ptr<te::st::TimeSeriesDataSet> tds = te::st::TimeSeriesDataSetLayer::getTimeSeriesDataset(dt, tr, g, sr, travType);
183  std::auto_ptr<te::da::DataSet> result = tds->release();
184  return result;
185 }
186 
188  te::common::TraverseType travType) const
189 {
190  return te::st::STDataLoader::getDataSet(*m_info.get(), dt, r, travType);
191 }
192 
193 std::auto_ptr<te::st::TimeSeriesDataSet>
196  te::common::TraverseType travType) const
197 {
198  std::auto_ptr<te::st::TimeSeriesDataSet> result;
199  return result;
200  //return te::st::STDataLoader::getDataSet(*m_info.get(), dt, tr, e, sr, travType);
201 }
202 
205  te::common::TraverseType travType) const
206 {
207  std::auto_ptr<te::st::TimeSeriesDataSet> result;
208  return result;
209  //return te::st::STDataLoader::getDataSet(*m_info.get(), dt, tr, g, sr, travType);
210 }
211 
213 {
214  if(m_info->getObservationDataSetInfo().getDataSourceInfo().getId().empty())
215  return false;
216 
218  try
219  {
220  ds = te::da::GetDataSource(m_info->getObservationDataSetInfo().getDataSourceInfo().getId(), true);
221  }
222  catch(...)
223  {
224  return false;
225  }
226 
227  if(ds.get() == 0 || !ds->isValid() || !ds->isOpened())
228  return false;
229 
230  return true;
231 }
232 
234 {
235  if(m_rendererType.empty())
236  throw te::map::Exception((boost::format(TE_TR("Could not draw the data set layer %1%. The renderer type is empty!")) % getTitle()).str());
237 
238  // Try get the defined renderer
239  std::auto_ptr<te::map::AbstractRenderer> renderer(te::map::RendererFactory::make(m_rendererType));
240  if(renderer.get() == 0)
241  throw te::map::Exception((boost::format(TE_TR("Could not draw the data set layer %1%. The renderer %2% could not be created!")) % getTitle() % m_rendererType).str());
242 
243  renderer->draw(this, canvas, bbox, srid);
244 }
245 
246 const std::string& te::st::TimeSeriesDataSetLayer::getType() const
247 {
248  return sm_type;
249 }
250 
252 {
253  return m_info->getObservationDataSetInfo().getDataSourceInfo().getId();
254 }
255 
257 {
258  return m_rendererType;
259 }
260 
262 {
263  m_rendererType = t;
264 }
265 
267 {
268  if (m_layers.empty())
269  return false;
270  else
271  return true;
272 }
TEDATAACCESSEXPORT DataSourcePtr GetDataSource(const std::string &datasourceId, const bool opened=true)
Search for a data source with the informed id in the DataSourceManager.
Definition: Utils.cpp:262
const std::string & getDataSourceId() const
boost::shared_ptr< DataSource > DataSourcePtr
Definition: DataSource.h:1435
const std::string & getType() const
It returns the layer type: TIMESERIESDATASETLAYER.
bool isValid() const
It returns true if the layer can be used for instance to draw, otherwise, it returns false...
TemporalRelation
Temporal relations between date and time (Source: Allen, 1991).
Definition: Enums.h:140
SpatialRelation
Spatial relations between geometric objects.
Definition: Enums.h:122
const std::string & getRendererType() const
#define TE_TR(message)
It marks a string in order to get translated.
Definition: Translator.h:347
This is an abstract class that models a query expression.
Definition: Expression.h:47
A layer with a reference to an TimeSeriesDataSet.
AccessPolicy
Supported data access policies (can be used as bitfield).
Definition: Enums.h:40
TraverseType
A dataset can be traversed in two ways:
Definition: Enums.h:53
A layer with reference to a dataset that contains spatiotemporal data.
An Envelope defines a 2D rectangular region.
Definition: Envelope.h:51
void setRendererType(const std::string &t)
This class represents a set of unique ids created in the same context. i.e. from the same data set...
Definition: ObjectIdSet.h:55
Geometry is the root class of the geometries hierarchy, it follows OGC and ISO standards.
Definition: Geometry.h:73
static AbstractRenderer * make(const std::string &factoryKey)
It creates an object with the appropriated factory.
std::auto_ptr< te::st::TimeSeriesDataSet > getTimeSeriesDataset(te::common::TraverseType travType=te::common::FORWARDONLY) const
void draw(te::map::Canvas *canvas, const te::gm::Envelope &bbox, int srid)
It draws the layer geographic objects in the given canvas using the informed SRS. ...
A canvas is an abstraction of a drawing area.
Definition: Canvas.h:91
A class that contains infos about a DataSet that contains observations of one or more time series...
An abstract class to represent a period of date and time.
TimeSeriesDataSetLayer(AbstractLayer *parent, TimeSeriesDataSetInfo *info)
It initializes a new layer.
static const std::string sm_type
A static data member used in the implementation of getType method.
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.
te::dt::DateTimePeriod * getTemporalExtent() const
It returns the layer temporal extent.
std::auto_ptr< te::da::DataSet > getData(te::common::TraverseType travType=te::common::FORWARDONLY, const te::common::AccessPolicy accessPolicy=te::common::RAccess) const
It gets the dataset identified by the layer name.
std::auto_ptr< LayerSchema > getSchema() const
It returns the layer schema.
bool hasChilds()
Checks if the layer has any childs.