All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
TrajectoryDataSetLayer.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/TrajectoryDataSetLayer.cpp
22 
23  \brief A layer with a reference to an TrajectoryDataSet.
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/trajectory/TrajectoryDataSetInfo.h"
42 #include "../core/trajectory/TrajectoryDataSet.h"
43 #include "../loader/STDataLoader.h"
44 #include "TrajectoryDataSetLayer.h"
45 
46 // Boost
47 #include <boost/format.hpp>
48 
49 const std::string te::st::TrajectoryDataSetLayer::sm_type("TRAJECTORYDATASETLAYER");
50 
52  : AbstractSTDataSetLayer(parent),
53  m_info(info)
54 {
55 }
56 
57 te::st::TrajectoryDataSetLayer::TrajectoryDataSetLayer(const std::string& id, AbstractLayer* parent, TrajectoryDataSetInfo* 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::TrajectoryDataSetLayer::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::TrajectoryDataSetLayer::getData(te::common::TraverseType travType,
90  const te::common::AccessPolicy accessPolicy) const
91 {
92  std::auto_ptr<te::st::TrajectoryDataSet> tds = te::st::TrajectoryDataSetLayer::getTrajectoryDataset(travType);
93  std::auto_ptr<te::da::DataSet> result = tds->release();
94  return result;
95 }
96 
97 std::auto_ptr<te::da::DataSet> te::st::TrajectoryDataSetLayer::getData(const std::string& propertyName,
98  const te::gm::Envelope* e,
100  te::common::TraverseType travType,
101  const te::common::AccessPolicy accessPolicy) const
102 {
103  std::auto_ptr<te::st::TrajectoryDataSet> tds = te::st::TrajectoryDataSetLayer::getTrajectoryDataset(*e, r, travType);
104  std::auto_ptr<te::da::DataSet> result = tds->release();
105  return result;
106 }
107 
108 std::auto_ptr<te::da::DataSet> te::st::TrajectoryDataSetLayer::getData(const std::string& propertyName,
109  const te::gm::Geometry* g,
111  te::common::TraverseType travType,
112  const te::common::AccessPolicy accessPolicy) const
113 {
114  std::auto_ptr<te::st::TrajectoryDataSet> tds = te::st::TrajectoryDataSetLayer::getTrajectoryDataset(*g, r, travType);
115  std::auto_ptr<te::da::DataSet> result = tds->release();
116  return result;
117 }
118 
119 std::auto_ptr<te::st::TrajectoryDataSet> te::st::TrajectoryDataSetLayer::getTrajectoryDataset(te::common::TraverseType travType) const
120 {
121  return te::st::STDataLoader::getDataSet(*m_info.get(), travType);
122 }
123 
124 std::auto_ptr<te::st::TrajectoryDataSet> te::st::TrajectoryDataSetLayer::getTrajectoryDataset(const te::gm::Envelope& e,
126  te::common::TraverseType travType) const
127 {
128  return te::st::STDataLoader::getDataSet(*m_info.get(), e, r, travType);
129 }
130 
131 std::auto_ptr<te::st::TrajectoryDataSet> te::st::TrajectoryDataSetLayer::getTrajectoryDataset(const te::gm::Geometry& g,
133  te::common::TraverseType travType) const
134 {
135  return te::st::STDataLoader::getDataSet(*m_info.get(), g, r, travType);
136 }
137 
139  te::common::TraverseType travType,
140  te::common::AccessPolicy rwRole) const
141 {
142  std::auto_ptr<te::st::TrajectoryDataSet> tds = te::st::TrajectoryDataSetLayer::getTrajectoryDataset(dt, r, travType);
143  std::auto_ptr<te::da::DataSet> result = tds->release();
144  return result;
145 }
146 
149  te::common::TraverseType travType,
150  te::common::AccessPolicy rwRole) const
151 {
152  std::auto_ptr<te::st::TrajectoryDataSet> tds = te::st::TrajectoryDataSetLayer::getTrajectoryDataset(dt, tr, e, sr, travType);
153  std::auto_ptr<te::da::DataSet> result = tds->release();
154  return result;
155 }
156 
159  te::common::TraverseType travType,
160  te::common::AccessPolicy rwRole) const
161 {
162  std::auto_ptr<te::st::TrajectoryDataSet> tds = te::st::TrajectoryDataSetLayer::getTrajectoryDataset(dt, tr, g, sr, travType);
163  std::auto_ptr<te::da::DataSet> result = tds->release();
164  return result;
165 }
166 
168  te::common::TraverseType travType) const
169 {
170  return te::st::STDataLoader::getDataSet(*m_info.get(), dt, r, travType);
171 }
172 
173 std::auto_ptr<te::st::TrajectoryDataSet>
176  te::common::TraverseType travType) const
177 {
178  return te::st::STDataLoader::getDataSet(*m_info.get(), dt, tr, e, sr, travType);
179 }
180 
183  te::common::TraverseType travType) const
184 {
185  return te::st::STDataLoader::getDataSet(*m_info.get(), g, sr, dt, tr, travType);
186 }
187 
189 {
190  if(m_info->getDataSourceInfo().getId().empty())
191  return false;
192 
194  try
195  {
196  ds = te::da::GetDataSource(m_info->getDataSourceInfo().getId(), true);
197  }
198  catch(...)
199  {
200  return false;
201  }
202 
203  if(ds.get() == 0 || !ds->isValid() || !ds->isOpened())
204  return false;
205 
206  return true;
207 }
208 
210 {
211  if(m_rendererType.empty())
212  throw te::map::Exception((boost::format(TR_MAP("Could not draw the data set layer %1%. The renderer type is empty!")) % getTitle()).str());
213 
214  // Try get the defined renderer
215  std::auto_ptr<te::map::AbstractRenderer> renderer(te::map::RendererFactory::make(m_rendererType));
216  if(renderer.get() == 0)
217  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());
218 
219  renderer->draw(this, canvas, bbox, srid);
220 }
221 
222 const std::string& te::st::TrajectoryDataSetLayer::getType() const
223 {
224  return sm_type;
225 }
226 
228 {
229  return m_rendererType;
230 }
231 
233 {
234  m_rendererType = t;
235 }
236 
238 {
239  if (m_layers.empty())
240  return false;
241  else
242  return true;
243 }
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
const std::string & getType() const
It returns the layer type: DATASET_LAYER.
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. ...
boost::shared_ptr< DataSource > DataSourcePtr
Definition: DataSource.h:1435
TrajectoryDataSetLayer(AbstractLayer *parent, TrajectoryDataSetInfo *info)
It initializes a new layer.
TemporalRelation
Temporal relations between date and time (Source: Allen, 1991).
Definition: Enums.h:76
SpatialRelation
Spatial relations between geometric objects.
Definition: Enums.h:122
std::auto_ptr< te::st::TrajectoryDataSet > getTrajectoryDataset(te::common::TraverseType travType=te::common::FORWARDONLY) const
std::auto_ptr< LayerSchema > getSchema() const
It returns the layer schema.
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
bool isValid() const
It returns true if the layer can be used for instance to draw, otherwise, it returns false...
static const std::string sm_type
A static data member used in the implementation of getType method.
void setRendererType(const std::string &t)
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.
bool hasChilds()
Checks if the layer has any childs.
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.
te::dt::DateTimePeriod * getTemporalExtent() const
It returns the layer temporal extent.
A class that contains infos about a DataSet that contains observations of one or more trajectories...
A canvas is an abstraction of a drawing area.
Definition: Canvas.h:91
An abstract class to represent a period of date and time.
const std::string & getRendererType() const
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.
A layer with a reference to an TrajectoryDataSet.