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) 2010-2014 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->getDataSourceInfo().getId(), true);
80 
81  return ds->getDataSetType(m_info->getObservationDataSetInfo().getDataSetName());
82 }
83 
85 {
86  return te::st::STDataLoader::getDataSet(*m_info.get())->getTemporalExtent();
87 }
88 
89 std::auto_ptr<te::da::DataSet> te::st::TimeSeriesDataSetLayer::getData(te::common::TraverseType travType,
90  const te::common::AccessPolicy accessPolicy) const
91 {
92  std::auto_ptr<te::st::TimeSeriesDataSet> tds = te::st::TimeSeriesDataSetLayer::getTimeSeriesDataset(travType);
93  std::auto_ptr<te::da::DataSet> result = tds->release();
94  return result;
95 }
96 
97 std::auto_ptr<te::st::TimeSeriesDataSet> te::st::TimeSeriesDataSetLayer::getTimeSeriesDataset(te::common::TraverseType travType) const
98 {
99  return te::st::STDataLoader::getDataSet(*m_info.get(), travType);
100 }
101 
103  te::common::TraverseType travType,
104  te::common::AccessPolicy rwRole) const
105 {
106  std::auto_ptr<te::st::TimeSeriesDataSet> tds = te::st::TimeSeriesDataSetLayer::getTimeSeriesDataset(dt, r, travType);
107  std::auto_ptr<te::da::DataSet> result = tds->release();
108  return result;
109 }
110 
112  te::common::TraverseType travType) const
113 {
114  return te::st::STDataLoader::getDataSet(*m_info.get(), dt, r, travType);
115 }
116 
118 {
119  if(m_info->getDataSourceInfo().getId().empty())
120  return false;
121 
123  try
124  {
125  ds = te::da::GetDataSource(m_info->getDataSourceInfo().getId(), true);
126  }
127  catch(...)
128  {
129  return false;
130  }
131 
132  if(ds.get() == 0 || !ds->isValid() || !ds->isOpened())
133  return false;
134 
135  return true;
136 }
137 
139 {
140  if(m_rendererType.empty())
141  throw te::map::Exception((boost::format(TR_MAP("Could not draw the data set layer %1%. The renderer type is empty!")) % getTitle()).str());
142 
143  // Try get the defined renderer
144  std::auto_ptr<te::map::AbstractRenderer> renderer(te::map::RendererFactory::make(m_rendererType));
145  if(renderer.get() == 0)
146  throw te::map::Exception((boost::format(TR_MAP("Could not draw the data set layer %1%. The renderer %2% could not be created!")) % getTitle() % m_rendererType).str());
147 
148  renderer->draw(this, canvas, bbox, srid);
149 }
150 
151 const std::string& te::st::TimeSeriesDataSetLayer::getType() const
152 {
153  return sm_type;
154 }
155 
157 {
158  return m_rendererType;
159 }
160 
162 {
163  m_rendererType = t;
164 }
165 
167 {
168  if (m_layers.empty())
169  return false;
170  else
171  return true;
172 }
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:259
boost::shared_ptr< DataSource > DataSourcePtr
Definition: DataSource.h:1435
const std::string & getType() const
It returns the layer type: DATASET_LAYER.
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:76
const std::string & getRendererType() const
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)
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.