Layer.h
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 Layer.h
22 
23  \brief A Layer is a reference to a virtual dataset with/without geometric attributes.
24 */
25 
26 #ifndef __TERRALIB_GRAPH_INTERNAL_LAYER_H
27 #define __TERRALIB_GRAPH_INTERNAL_LAYER_H
28 
29 // TerraLib
30 #include "../../maptools/AbstractLayer.h"
31 #include "../Config.h"
32 
33 
34 // STL
35 #include <memory>
36 
37 namespace te
38 {
39  namespace gm { class Envelope; }
40 
41  namespace map
42  {
43  class Canvas;
44  }
45 
46  namespace se { class Style; }
47 
48  namespace graph
49  {
50 // Forward declarations
51  class AbstractGraph;
52  class LayerRenderer;
53 
54  /*!
55  \class Layer
56 
57  \brief A Layer is a reference to a virtual dataset with/without geometric attributes.
58 
59  A Layer is the result of a query in a given DataSource.
60 
61  \sa AbstractLayer
62  */
64  {
65  public:
66 
67  /*!
68  \brief It initializes a new Layer.
69 
70  \param id The layer id.
71  \param title The title is a brief description about the layer, that can be used by an application to show a meaninfull label to the user.
72  \param parent The parent Layer (or NULL if it has no parent).
73 
74  \note If parent is informed, it will take the ownership of the new layer.
75  */
76  Layer(const std::string& id, const std::string& title, AbstractLayer* parent = 0);
77 
78  /*! \brief Destructor. */
79  ~Layer();
80 
81  AbstractLayer* clone() { return nullptr; }
82 
83  /*!
84  \brief It returns the layer schema.
85 
86  \return The Layer schema.
87 
88  \note The caller will take the ownership of the returned layer schema.
89  */
90  virtual std::unique_ptr<te::da::DataSetType> getSchema() const;
91 
92  /*!
93  \brief It gets the dataset identified by the layer name.
94 
95  \param travType The traverse type associated to the returned dataset.
96  \param accessPolicy Access policy.
97 
98  \return The caller of this method will take the ownership of the returned dataset.
99 
100  \exception Exception It can throws an exception if:
101  <ul>
102  <li>something goes wrong during the data retrieval</li>
103  <li>if the data source driver doesn't support the traversal type</li>
104  <li>if the data source driver doesn't support the access policy</li>
105  </ul>
106 
107  \note Not thread-safe!
108  */
109  virtual std::unique_ptr<te::da::DataSet> getData(te::common::TraverseType travType = te::common::FORWARDONLY,
110  const te::common::AccessPolicy accessPolicy = te::common::RAccess) const;
111 
112  /*!
113  \brief It gets the dataset identified by the layer name using a spatial filter over the specified property.
114 
115  \param propertyName The name of the spatial property used to apply the spatial filter.
116  \param e A rectangle to be used as a spatial filter when retrieving datasets.
117  \param r The spatial relation to be used during the filter.
118  \param travType The traverse type associated to the returned dataset.
119  \param accessPolicy Access policy.
120 
121  \return The caller of this method will take the ownership of the returned DataSet.
122 
123  \exception Exception It can throws an exception if:
124  <ul>
125  <li>something goes wrong during data retrieval</li>
126  <li>if the data source driver doesn't support the traversal type</li>
127  <li>if the data source driver doesn't support the access policy</li>
128  </ul>
129 
130  \note Transactor will not take the ownership of the given envelope.
131 
132  \note The envelope coordinates should be in the same coordinate system as the dataset.
133 
134  \note Not thread-safe!
135  */
136  virtual std::unique_ptr<te::da::DataSet> getData(const std::string& propertyName,
137  const te::gm::Envelope* e,
140  const te::common::AccessPolicy accessPolicy = te::common::RAccess) const;
141 
142  /*!
143  \brief It gets the dataset identified by the layer name using a spatial filter over the given geometric property.
144 
145  \param propertyName The name of the spatial property used to apply the spatial filter.
146  \param g A geometry to be used as a spatial filter when retrieving datasets.
147  \param r The spatial relation to be used during the filter.
148  \param travType The traverse type associated to the returned dataset.
149  \param accessPolicy Access policy.
150 
151  \return The caller of this method will take the ownership of the returned DataSet.
152 
153  \exception Exception It can throws an exception if:
154  <ul>
155  <li>something goes wrong during data retrieval</li>
156  <li>if the data source driver doesn't support the traversal type</li>
157  <li>if the data source driver doesn't support the access policy</li>
158  </ul>
159 
160  \note Transactor will not take the ownership of the given geometry.
161 
162  \note The geometry coordinates should be in the same coordinate system as the dataset.
163 
164  \note Not thread-safe!
165  */
166  virtual std::unique_ptr<te::da::DataSet> getData(const std::string& propertyName,
167  const te::gm::Geometry* g,
170  const te::common::AccessPolicy accessPolicy = te::common::RAccess) const;
171 
172  /*!
173  \brief It gets the dataset identified by the layer name using the given restriction.
174 
175  \param restriction The restriction expression that will be used.
176  \param travType The traverse type associated to the returned dataset.
177  \param accessPolicy Access policy.
178 
179  \return The caller of this method will take the ownership of the returned DataSet.
180 
181  \exception Exception It can throws an exception if:
182  <ul>
183  <li>something goes wrong during data retrieval</li>
184  <li>if the data source driver doesn't support the traversal type</li>
185  <li>if the data source driver doesn't support the access policy</li>
186  </ul>
187 
188  \note Not thread-safe!
189  */
190  virtual std::unique_ptr<te::da::DataSet> getData(te::da::Expression* restriction,
192  const te::common::AccessPolicy accessPolicy = te::common::RAccess) const;
193 
194  /*!
195  \brief It gets the dataset from the given set of objects identification.
196 
197  \param oids The set of object ids.
198  \param travType The traverse type associated to the returned dataset.
199  \param accessPolicy Access policy.
200 
201  \return The caller of this method will take the ownership of the returned dataset.
202 
203  \exception Exception It can throws an exception if:
204  <ul>
205  <li>something goes wrong during the data retrieval</li>
206  <li>if the data source driver doesn't support the traversal type</li>
207  <li>if the data source driver doesn't support the access policy</li>
208  </ul>
209 
210  \note Not thread-safe!
211  */
212  virtual std::unique_ptr<te::da::DataSet> getData(const te::da::ObjectIdSet* oids,
214  const te::common::AccessPolicy accessPolicy = te::common::RAccess) const;
215 
216  /*!
217  \brief It returns the layer type.
218 
219  \return The layer type.
220  */
221  virtual const std::string& getType() const;
222 
223  /*!
224  \brief It returns true if the layer can be drawn, otherwise, it returns false.
225 
226  This method can be used to check if the data referenced by the layer is available (accessible), or not.
227 
228  \return True, if the layer can be drawn, otherwise, it returns false.
229  */
230  virtual bool isValid() const;
231 
232  /*!
233  \brief It draws the layer geographic objects in the given canvas using the informed SRS.
234 
235  The informed bounding box can be used to constraint the layer objects to be drawn.
236 
237  The bbox coordinates must be in the same Spatial Reference System given by srid.
238 
239  \param canvas The canvas were the layer objects will be drawn.
240  \param bbox The interest area to render the map.
241  \param srid The SRS to be used to draw the layer objects.
242  */
243  virtual void draw(te::map::Canvas* canvas, const te::gm::Envelope& bbox, int srid, const double& scale, bool* cancel);
244 
245  /*!
246  \brief It returns the graph associated to the layer.
247 
248  \return the graph associated to the layer.
249  */
251 
252  /*!
253  \brief It sets the graph associated to the layer.
254 
255  \param ds The graph associated to the layer.
256  */
258 
259  /*!
260  \brief It returns the renderer used to paint this layer.
261 
262  \return The renderer used to paint this layer.
263  */
265 
266  /*!
267  \brief It sets the renderer used to paint this layer.
268 
269  \param renderer The renderer to be used to paint this layer.
270 
271  \note The Layer will take the ownership of the given renderer.
272  */
273  void setRenderer(LayerRenderer* renderer);
274 
275  public:
276 
277  static const std::string sm_type; //!< A static data member used in the implementation of getType method.
278 
279  private:
280 
281  std::unique_ptr<LayerRenderer> m_renderer; //!< A pointer to the internal renderer used to paint this layer.
282  te::graph::AbstractGraph* m_graph; //!< The graph associated to this Layer.
283  };
284 
285  } // end namespace graph
286 } // end namespace te
287 
288 #endif // __TERRALIB_GRAPH_INTERNAL_LAYER_H
289 
te::gm::Envelope
An Envelope defines a 2D rectangular region.
Definition: Envelope.h:52
te::graph::Layer::clone
AbstractLayer * clone()
It returns a clone of the object.
Definition: Layer.h:81
te::graph::Layer::getRenderer
LayerRenderer * getRenderer() const
It returns the renderer used to paint this layer.
te
TerraLib.
Definition: AddressGeocodingOp.h:52
te::graph::Layer::getSchema
virtual std::unique_ptr< te::da::DataSetType > getSchema() const
It returns the layer schema.
te::graph::Layer::m_renderer
std::unique_ptr< LayerRenderer > m_renderer
A pointer to the internal renderer used to paint this layer.
Definition: Layer.h:281
te::graph::Layer::getData
virtual std::unique_ptr< te::da::DataSet > getData(const std::string &propertyName, const te::gm::Geometry *g, te::gm::SpatialRelation r, 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 using a spatial filter over the given geometric prop...
te::graph::Layer::getData
virtual std::unique_ptr< te::da::DataSet > getData(const std::string &propertyName, const te::gm::Envelope *e, te::gm::SpatialRelation r=te::gm::INTERSECTS, 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 using a spatial filter over the specified property.
te::common::RAccess
@ RAccess
Definition: Enums.h:43
te::graph::Layer::getData
virtual std::unique_ptr< te::da::DataSet > getData(const te::da::ObjectIdSet *oids, te::common::TraverseType travType=te::common::FORWARDONLY, const te::common::AccessPolicy accessPolicy=te::common::RAccess) const
It gets the dataset from the given set of objects identification.
te::common::TraverseType
TraverseType
A dataset can be traversed in two ways:
Definition: Enums.h:54
te::graph::Layer::~Layer
~Layer()
Destructor.
te::graph::Layer::setRenderer
void setRenderer(LayerRenderer *renderer)
It sets the renderer used to paint this layer.
te::graph::Layer::draw
virtual 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.
TEGRAPHEXPORT
#define TEGRAPHEXPORT
You can use this macro in order to export/import classes and functions from this module.
Definition: Config.h:178
te::graph::Layer
A Layer is a reference to a virtual dataset with/without geometric attributes.
Definition: Layer.h:64
te::graph::Layer::isValid
virtual bool isValid() const
It returns true if the layer can be drawn, otherwise, it returns false.
te::gm::SpatialRelation
SpatialRelation
Spatial relations between geometric objects.
Definition: Enums.h:128
te::da::Expression
This is an abstract class that models a query expression.
Definition: Expression.h:48
te::map::AbstractLayer
This is the base class for layers.
Definition: AbstractLayer.h:78
te::map::Canvas
A canvas is an abstraction of a drawing area.
Definition: Canvas.h:93
te::graph::Layer::m_graph
te::graph::AbstractGraph * m_graph
The graph associated to this Layer.
Definition: Layer.h:282
te::graph::Layer::sm_type
static const std::string sm_type
A static data member used in the implementation of getType method.
Definition: Layer.h:277
te::gm::INTERSECTS
@ INTERSECTS
Definition: Enums.h:130
te::graph::Layer::Layer
Layer(const std::string &id, const std::string &title, AbstractLayer *parent=0)
It initializes a new Layer.
te::graph::AbstractGraph
Abstract class used to define the main functions of graph struct. All graph implementations must used...
Definition: AbstractGraph.h:56
te::graph::LayerRenderer
It renders the objects associated to a Layer.
Definition: LayerRenderer.h:58
te::graph::Layer::getGraph
te::graph::AbstractGraph * getGraph() const
It returns the graph associated to the layer.
te::se::Style
The Style defines the styling that is to be applied to a geographic dataset (vector geometries or cov...
Definition: Style.h:66
te::graph::Layer::getData
virtual std::unique_ptr< te::da::DataSet > getData(te::da::Expression *restriction, 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 using the given restriction.
te::graph::Layer::getType
virtual const std::string & getType() const
It returns the layer type.
te::graph::Layer::setGraph
void setGraph(te::graph::AbstractGraph *ds)
It sets the graph associated to the layer.
te::gm::Geometry
Geometry is the root class of the geometries hierarchy, it follows OGC and ISO standards.
Definition: Geometry.h:78
te::common::AccessPolicy
AccessPolicy
Supported data access policies (can be used as bitfield).
Definition: Enums.h:41
te::da::ObjectIdSet
This class represents a set of unique ids created in the same context. i.e. from the same data set.
Definition: ObjectIdSet.h:56
te::graph::Layer::getData
virtual 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.
te::common::FORWARDONLY
@ FORWARDONLY
Definition: Enums.h:55