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 
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 std::unique_ptr<te::map::LayerSchema> te::st::TimeSeriesDataSetLayer::getSchema() const
74 {
75  assert(!m_info->getObservationDataSetInfo().getDataSetName().empty());
76 
77  te::da::DataSourcePtr ds = te::da::GetDataSource(m_info->getObservationDataSetInfo().getDataSourceInfo().getId(), true);
78 
79  return ds->getDataSetType(m_info->getObservationDataSetInfo().getDataSetName());
80 }
81 
83 {
84  return 0;
85  //return te::st::STDataLoader::getDataSet(*m_info.get())->getTemporalExtent();
86 }
87 
88 // -----------------------------------------------------------------------------------------------------------------------
89 
90 std::unique_ptr<te::da::DataSet> te::st::TimeSeriesDataSetLayer::getData(
91  te::common::TraverseType travType,
92  const te::common::AccessPolicy /*accessPolicy*/) const
93 {
94  std::unique_ptr<te::st::TimeSeriesDataSet> tds = te::st::TimeSeriesDataSetLayer::getTimeSeriesDataset(travType);
95  std::unique_ptr<te::da::DataSet> result = tds->release();
96  return result;
97 }
98 
99 std::unique_ptr<te::da::DataSet> te::st::TimeSeriesDataSetLayer::getData(
100  const std::string& /*propertyName*/, const te::gm::Envelope* e,
102  const te::common::AccessPolicy /*accessPolicy*/) const
103 {
104  std::unique_ptr<te::st::TimeSeriesDataSet> tsds = te::st::TimeSeriesDataSetLayer::getTimeSeriesDataset(*e, r, travType);
105  std::unique_ptr<te::da::DataSet> result = tsds->release();
106  return result;
107 }
108 
109 std::unique_ptr<te::da::DataSet> te::st::TimeSeriesDataSetLayer::getData(
110  const std::string& /*propertyName*/, const te::gm::Geometry* g,
112  const te::common::AccessPolicy /*accessPolicy*/) const
113 {
114  std::unique_ptr<te::st::TimeSeriesDataSet> tsds = te::st::TimeSeriesDataSetLayer::getTimeSeriesDataset(*g, r, travType);
115  std::unique_ptr<te::da::DataSet> result = tsds->release();
116  return result;
117 }
118 
119 std::unique_ptr<te::da::DataSet> te::st::TimeSeriesDataSetLayer::getData(
120  te::da::Expression* /*restriction*/, te::common::TraverseType /*travType*/,
121  const te::common::AccessPolicy /*accessPolicy*/) const
122 {
123  std::unique_ptr<te::da::DataSet> result;
124  return result;
125 }
126 
127 std::unique_ptr<te::da::DataSet> te::st::TimeSeriesDataSetLayer::getData(
128  const te::da::ObjectIdSet* /*oids*/, te::common::TraverseType /*travType*/,
129  const te::common::AccessPolicy /*accessPolicy*/) const
130 {
131  std::unique_ptr<te::da::DataSet> result;
132  return result;
133 }
134 
135 std::unique_ptr<te::st::TimeSeriesDataSet> te::st::TimeSeriesDataSetLayer::getTimeSeriesDataset(te::common::TraverseType travType) const
136 {
137  return te::st::STDataLoader::getDataSet(*m_info.get(), travType);
138 }
139 
140 std::unique_ptr<te::st::TimeSeriesDataSet> te::st::TimeSeriesDataSetLayer::getTimeSeriesDataset(const te::gm::Envelope& e,
142  te::common::TraverseType travType) const
143 {
144  return te::st::STDataLoader::getDataSet(*m_info.get(), e, r, travType);
145 }
146 
147 std::unique_ptr<te::st::TimeSeriesDataSet> te::st::TimeSeriesDataSetLayer::getTimeSeriesDataset(const te::gm::Geometry& g,
149  te::common::TraverseType travType) const
150 {
151  return te::st::STDataLoader::getDataSet(*m_info.get(), g, r, travType);
152 }
153 
154 std::unique_ptr<te::da::DataSet> te::st::TimeSeriesDataSetLayer::getData(
156  te::common::TraverseType travType,
157  te::common::AccessPolicy /*rwRole*/) const
158 {
159  std::unique_ptr<te::st::TimeSeriesDataSet> tds = te::st::TimeSeriesDataSetLayer::getTimeSeriesDataset(dt, r, travType);
160  std::unique_ptr<te::da::DataSet> result = tds->release();
161  return result;
162 }
163 
164 std::unique_ptr<te::da::DataSet> te::st::TimeSeriesDataSetLayer::getData(
167  te::common::TraverseType travType,
168  te::common::AccessPolicy /*rwRole*/) const
169 {
170  std::unique_ptr<te::st::TimeSeriesDataSet> tds = te::st::TimeSeriesDataSetLayer::getTimeSeriesDataset(dt, tr, e, sr, travType);
171  std::unique_ptr<te::da::DataSet> result = tds->release();
172  return result;
173 }
174 
175 std::unique_ptr<te::da::DataSet> te::st::TimeSeriesDataSetLayer::getData(
178  te::common::TraverseType travType,
179  te::common::AccessPolicy /*rwRole*/) const
180 {
181  std::unique_ptr<te::st::TimeSeriesDataSet> tds = te::st::TimeSeriesDataSetLayer::getTimeSeriesDataset(dt, tr, g, sr, travType);
182  std::unique_ptr<te::da::DataSet> result = tds->release();
183  return result;
184 }
185 
187  te::common::TraverseType travType) const
188 {
189  return te::st::STDataLoader::getDataSet(*m_info.get(), dt, r, travType);
190 }
191 
192 std::unique_ptr<te::st::TimeSeriesDataSet>
194  const te::dt::DateTime& /*dt*/, te::dt::TemporalRelation /*tr*/,
195  const te::gm::Envelope& /*e*/, te::gm::SpatialRelation /*sr*/,
196  te::common::TraverseType /*travType*/) const
197 {
198  std::unique_ptr<te::st::TimeSeriesDataSet> result;
199  return result;
200  //return te::st::STDataLoader::getDataSet(*m_info.get(), dt, tr, e, sr, travType);
201 }
202 
203 std::unique_ptr<te::st::TimeSeriesDataSet>
205  const te::dt::DateTime& /*dt*/, te::dt::TemporalRelation /*tr*/,
206  const te::gm::Geometry& /*g*/, te::gm::SpatialRelation /*sr*/,
207  te::common::TraverseType /*travType*/) const
208 {
209  std::unique_ptr<te::st::TimeSeriesDataSet> result;
210  return result;
211  //return te::st::STDataLoader::getDataSet(*m_info.get(), dt, tr, g, sr, travType);
212 }
213 
215 {
216  if(m_info->getObservationDataSetInfo().getDataSourceInfo().getId().empty())
217  return false;
218 
220  try
221  {
222  ds = te::da::GetDataSource(m_info->getObservationDataSetInfo().getDataSourceInfo().getId(), true);
223  }
224  catch(...)
225  {
226  return false;
227  }
228 
229  if(ds.get() == 0 || !ds->isValid() || !ds->isOpened())
230  return false;
231 
232  return true;
233 }
234 
235 void te::st::TimeSeriesDataSetLayer::draw(te::map::Canvas* canvas, const te::gm::Envelope& bbox, int srid, const double& scale, bool* cancel)
236 {
237  if(m_rendererType.empty())
238  throw te::map::Exception((boost::format(TE_TR("Could not draw the data set layer %1%. The renderer type is empty!")) % getTitle()).str());
239 
240  // Try get the defined renderer
241  std::unique_ptr<te::map::AbstractRenderer> renderer(te::map::RendererFactory::make(m_rendererType));
242  if(renderer.get() == 0)
243  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());
244 
245  renderer->draw(this, canvas, bbox, srid, scale, cancel);
246 }
247 
248 const std::string& te::st::TimeSeriesDataSetLayer::getType() const
249 {
250  return sm_type;
251 }
252 
254 {
255  return m_info->getObservationDataSetInfo().getDataSourceInfo().getId();
256 }
257 
259 {
260  return m_rendererType;
261 }
262 
264 {
265  m_rendererType = t;
266 }
267 
269 {
270  if (m_layers.empty())
271  return false;
272  else
273  return true;
274 }
TEDATAACCESSEXPORT DataSourcePtr GetDataSource(const std::string &datasourceId, const bool opened=true)
Search for a data source with the informed id in the DataSourceManager.
boost::ptr_vector< TimeSeriesDataSetLayer > m_layers
const std::string & getDataSourceId() const
void draw(te::map::Canvas *canvas, const te::gm::Envelope &bbox, int srid, const double &scale, bool *cancel)
It draws the layer geographic objects in the given canvas using the informed SRS. ...
boost::shared_ptr< DataSource > DataSourcePtr
virtual const std::string & getTitle() const
It returns the layer title.
~TimeSeriesDataSetLayer()
Destructor.
std::string m_rendererType
A pointer to the internal renderer used to paint this layer.
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).
SpatialRelation
Spatial relations between geometric objects.
static te::dt::Date ds(2010, 01, 01)
const std::string & getRendererType() const
#define TE_TR(message)
It marks a string in order to get translated.
Definition: Translator.h:242
std::unique_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.
This is an abstract class that models a query expression.
A layer with a reference to an TimeSeriesDataSet.
AccessPolicy
Supported data access policies (can be used as bitfield).
TraverseType
A dataset can be traversed in two ways:
A layer with reference to a dataset that contains spatiotemporal data.
An Envelope defines a 2D rectangular region.
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
static te::dt::TimeDuration dt(20, 30, 50, 11)
std::unique_ptr< TimeSeriesDataSetInfo > m_info
, A container the holds any child layers.
static std::unique_ptr< ObservationDataSet > getDataSet(const ObservationDataSetInfo &info, te::common::TraverseType travType=te::common::FORWARDONLY)
It returns a ObservationDataSet, that is, a DataSet that contains observations.
std::unique_ptr< te::st::TimeSeriesDataSet > getTimeSeriesDataset(te::common::TraverseType travType=te::common::FORWARDONLY) const
Geometry is the root class of the geometries hierarchy, it follows OGC and ISO standards.
static AbstractRenderer * make(const std::string &factoryKey)
It creates an object with the appropriated factory.
A canvas is an abstraction of a drawing area.
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.
AbstractLayer(AbstractLayer *parent=0)
It initializes a new layer.
te::dt::DateTimePeriod * getTemporalExtent() const
It returns the layer temporal extent.
std::unique_ptr< LayerSchema > getSchema() const
It returns the layer schema.
bool hasChilds()
Checks if the layer has any childs.