All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
AbstractLayer.h
Go to the documentation of this file.
1 /* Copyright (C) 2008-20013 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/maptools/AbstractLayer.h
22 
23  \brief This is the base class for Layers.
24 */
25 
26 #ifndef __TERRALIB_MAPTOOLS_INTERNAL_ABSTRACTLAYER_H
27 #define __TERRALIB_MAPTOOLS_INTERNAL_ABSTRACTLAYER_H
28 
29 // TerraLib
30 #include "../common/Enums.h"
31 #include "../common/TreeItem.h"
32 #include "../dataaccess/dataset/DataSet.h"
33 #include "../dataaccess/dataset/DataSetType.h"
34 #include "../geometry/Enums.h"
35 #include "../geometry/Envelope.h"
36 #include "Config.h"
37 #include "Enums.h"
38 
39 // STL
40 #include <memory>
41 #include <string>
42 
43 namespace te
44 {
45 // Forward declaration
46  namespace dt { class Property; }
47 
48  namespace da
49  {
50  class Expression;
51  class ObjectIdSet;
52  }
53 
54  namespace gm { class Geometry; }
55 
56  namespace se { class Style; }
57 
58  namespace map
59  {
60 // Forward declaration
61  class Canvas;
62  class Chart;
63  class Grouping;
64 
66 
67  /*!
68  \class AbstractLayer
69 
70  \brief This is the base class for layers.
71 
72  \ingroup map
73 
74  \sa TreeItem, DataSetLayer, QueryLayer, FolderLayer, RasterLayer
75  */
77  {
78  public:
79 
80  /*!
81  \brief It initializes a new layer.
82 
83  \param parent The parent layer (NULL if it has no parent).
84  */
85  AbstractLayer(AbstractLayer* parent = 0);
86 
87  /*!
88  \brief It initializes a new layer.
89 
90  \param id The layer id.
91  \param parent The parent layer (NULL if it has no parent).
92  */
93  AbstractLayer(const std::string& id, AbstractLayer* parent = 0);
94 
95  /*!
96  \brief It initializes a new layer.
97 
98  \param id The layer id.
99  \param title The title is a brief description about the layer.
100  \param parent The parent layer (NULL if it has no parent).
101  */
102  AbstractLayer(const std::string& id, const std::string& title, AbstractLayer* parent = 0);
103 
104  /*! \brief Virtual destructor. */
105  virtual ~AbstractLayer();
106 
107  /*!
108  \brief It returns the layer id.
109 
110  \return The layer id.
111  */
112  virtual const std::string& getId() const;
113 
114  /*!
115  \brief It sets the layer id.
116 
117  \param id The layer id.
118  */
119  virtual void setId(const std::string& id);
120 
121  /*!
122  \brief It returns the layer title.
123 
124  \return The layer title.
125  */
126  virtual const std::string& getTitle() const;
127 
128  /*!
129  \brief It sets the layer title.
130 
131  \param title The layer title.
132  */
133  virtual void setTitle(const std::string& title);
134 
135  /*!
136  \brief It returns a list with the descendants of this layer.
137 
138  \return A list containing the descendants of this layer.
139  */
140  std::vector<te::map::AbstractLayer*> getDescendants();
141 
142  /*!
143  \brief It returns a list with the ancestors of this layer.
144 
145  \return A list containing the ancestors of this layer.
146  */
147  std::vector<te::map::AbstractLayer*> getAncestors();
148 
149  /*!
150  \brief It returns the layer visibility.
151 
152  This information can be used, for instance, to know if the layer must be drawn.
153 
154  \return The layer visibility.
155  */
156  virtual Visibility getVisibility() const;
157 
158  /*!
159  \brief It sets the layer visibility.
160 
161  This information can be used, for instance, to know if the layer must be drawn.
162 
163  \param v The layer visibility.
164  */
165  virtual void setVisibility(Visibility v);
166 
167  /*!
168  \brief It gets the flag that indicates if the layer visibility has changed.
169 
170  \return If true, the layer visibility has changed.
171  */
172  bool hasVisibilityChanged();
173 
174  /*!
175  \brief It sets that the status of the layer visibility is to be changed or not..
176 
177  \param visChanged If true, the status of the layer visibility is to be changed; otherwise, it returns false.
178  */
179  void setVisibilityAsChanged(bool visChanged);
180 
181  /*!
182  \brief It updates the visibility of the ancestors of this layer, if any.
183  */
184  void updateVisibilityOfAncestors();
185 
186  /*!
187  \brief It updates the visibility of this layer.
188  */
189  virtual void updateVisibility();
190 
191  /*!
192  \brief It returns the Layer extent (or minimum bounding box).
193 
194  \return The Layer extent (or minimum bounding box) with coordinates in the same SRS as the layer.
195  */
196  virtual const te::gm::Envelope& getExtent() const;
197 
198  /*!
199  \brief It sets the Layer extent (or minimum bounding box).
200 
201  \param mbr The Layer extent (or minimum bounding box).
202 
203  \pre The mbr coordinates must be in the same SRS as the layer.
204  */
205  virtual void setExtent(const te::gm::Envelope& mbr);
206 
207  /*!
208  \brief It returns the Spatial Reference System ID associated to the Layer.
209 
210  \return The Spatial Reference System ID associated to the Layer.
211  */
212  virtual int getSRID() const;
213 
214  /*!
215  \brief It sets the Spatial Reference System ID associated to the Layer.
216 
217  \param srid The Spatial Reference System ID to be associated to the Layer.
218  */
219  virtual void setSRID(int srid);
220 
221  /*!
222  \brief It adds the given oids to the selected group of this Layer.
223 
224  \param oids The oids that will be added.
225 
226  \note The layer will take the ownership of the given pointer.
227  */
228  virtual void select(te::da::ObjectIdSet* oids);
229 
230  /*!
231  \brief It returns the selected group of this Layer.
232 
233  \retrun The selected group of this Layer.
234 
235  \note The caller will NOT take the ownership of the given pointer.
236  */
237  virtual const te::da::ObjectIdSet* getSelected() const;
238 
239  /*!
240  \brief It removes the given oids from the selected group of this Layer.
241 
242  \param oids The oids that will be removed.
243 
244  \note The layer will NOT take the ownership of the given pointer.
245  */
246  virtual void deselect(const te::da::ObjectIdSet* oids);
247 
248  /*!
249  \brief It clears the selected group of this Layer.
250  */
251  virtual void clearSelected();
252 
253  /*!
254  \brief It returns the Style associated to the layer.
255 
256  \return The Style associated to the layer.
257 
258  \note The caller will NOT take the ownership of the given pointer.
259  */
260  virtual te::se::Style* getStyle() const;
261 
262  /*!
263  \brief It sets the Style associated to the layer.
264 
265  \param style The Style associated to the layer.
266 
267  \note The layer will take the ownership of the given pointer.
268  */
269  virtual void setStyle(te::se::Style* style);
270 
271  /*!
272  \brief It returns the Grouping associated to the Layer.
273 
274  \return The Grouping associated to the Layer.
275 
276  \note The caller will NOT take the ownership of the given pointer.
277  */
278  virtual te::map::Grouping* getGrouping() const;
279 
280  /*!
281  \brief It sets the Grouping associated to the Layer.
282 
283  \param grouping The Grouping to be associated to the Layer.
284 
285  \note The layer will take the ownership of the given pointer.
286  */
287  virtual void setGrouping(te::map::Grouping* grouping);
288 
289  /*!
290  \brief It returns the Chart associated to the Layer.
291 
292  \return The Chart associated to the Layer.
293 
294  \note The caller will NOT take the ownership of the given pointer.
295  */
296  virtual te::map::Chart* getChart() const;
297 
298  /*!
299  \brief It sets the Chart associated to the Layer.
300 
301  \param chart The Chart to be associated to the Layer.
302 
303  \note The layer will take the ownership of the given pointer.
304  */
305  virtual void setChart(te::map::Chart* chart);
306 
307  /*!
308  \brief It returns the layer schema.
309 
310  \return The Layer schema.
311 
312  \note The caller will take the ownership of the returned layer schema.
313  */
314  virtual std::auto_ptr<LayerSchema> getSchema() const = 0;
315 
316  /*!
317  \brief It gets the dataset identified by the layer name.
318 
319  \param travType The traverse type associated to the returned dataset.
320  \param accessPolicy Access policy.
321 
322  \return The caller of this method will take the ownership of the returned dataset.
323 
324  \exception Exception It can throws an exception if:
325  <ul>
326  <li>something goes wrong during the data retrieval</li>
327  <li>if the data source driver doesn't support the traversal type</li>
328  <li>if the data source driver doesn't support the access policy</li>
329  </ul>
330 
331  \note Not thread-safe!
332  */
333  virtual std::auto_ptr<te::da::DataSet> getData(te::common::TraverseType travType = te::common::FORWARDONLY,
334  const te::common::AccessPolicy accessPolicy = te::common::RAccess) const = 0;
335 
336  /*!
337  \brief It gets the dataset identified by the layer name using a spatial filter over the specified property.
338 
339  \param propertyName The name of the spatial property used to apply the spatial filter.
340  \param e A rectangle to be used as a spatial filter when retrieving datasets.
341  \param r The spatial relation to be used during the filter.
342  \param travType The traverse type associated to the returned dataset.
343  \param accessPolicy Access policy.
344 
345  \return The caller of this method will take the ownership of the returned DataSet.
346 
347  \exception Exception It can throws an exception if:
348  <ul>
349  <li>something goes wrong during data retrieval</li>
350  <li>if the data source driver doesn't support the traversal type</li>
351  <li>if the data source driver doesn't support the access policy</li>
352  </ul>
353 
354  \note Transactor will not take the ownership of the given envelope.
355 
356  \note The envelope coordinates should be in the same coordinate system as the dataset.
357 
358  \note Not thread-safe!
359  */
360  virtual std::auto_ptr<te::da::DataSet> getData(const std::string& propertyName,
361  const te::gm::Envelope* e,
364  const te::common::AccessPolicy accessPolicy = te::common::RAccess) const = 0;
365 
366  /*!
367  \brief It gets the dataset identified by the layer name using a spatial filter over the given geometric property.
368 
369  \param propertyName The name of the spatial property used to apply the spatial filter.
370  \param g A geometry to be used as a spatial filter when retrieving datasets.
371  \param r The spatial relation to be used during the filter.
372  \param travType The traverse type associated to the returned dataset.
373  \param accessPolicy Access policy.
374 
375  \return The caller of this method will take the ownership of the returned DataSet.
376 
377  \exception Exception It can throws an exception if:
378  <ul>
379  <li>something goes wrong during data retrieval</li>
380  <li>if the data source driver doesn't support the traversal type</li>
381  <li>if the data source driver doesn't support the access policy</li>
382  </ul>
383 
384  \note Transactor will not take the ownership of the given geometry.
385 
386  \note The geometry coordinates should be in the same coordinate system as the dataset.
387 
388  \note Not thread-safe!
389  */
390  virtual std::auto_ptr<te::da::DataSet> getData(const std::string& propertyName,
391  const te::gm::Geometry* g,
394  const te::common::AccessPolicy accessPolicy = te::common::RAccess) const = 0;
395 
396  /*!
397  \brief It gets the dataset identified by the layer name using the given restriction.
398 
399  \param restriction The restriction expression that will be used.
400  \param travType The traverse type associated to the returned dataset.
401  \param accessPolicy Access policy.
402 
403  \return The caller of this method will take the ownership of the returned DataSet.
404 
405  \exception Exception It can throws an exception if:
406  <ul>
407  <li>something goes wrong during data retrieval</li>
408  <li>if the data source driver doesn't support the traversal type</li>
409  <li>if the data source driver doesn't support the access policy</li>
410  </ul>
411 
412  \note Not thread-safe!
413  */
414  virtual std::auto_ptr<te::da::DataSet> getData(te::da::Expression* restriction,
416  const te::common::AccessPolicy accessPolicy = te::common::RAccess) const = 0;
417 
418  /*!
419  \brief It gets the dataset from the given set of objects identification.
420 
421  \param oids The set of object ids.
422  \param travType The traverse type associated to the returned dataset.
423  \param accessPolicy Access policy.
424 
425  \return The caller of this method will take the ownership of the returned dataset.
426 
427  \exception Exception It can throws an exception if:
428  <ul>
429  <li>something goes wrong during the data retrieval</li>
430  <li>if the data source driver doesn't support the traversal type</li>
431  <li>if the data source driver doesn't support the access policy</li>
432  </ul>
433 
434  \note Not thread-safe!
435  */
436  virtual std::auto_ptr<te::da::DataSet> getData(const te::da::ObjectIdSet* oids,
438  const te::common::AccessPolicy accessPolicy = te::common::RAccess) const = 0;
439 
440  /*!
441  \brief It returns the layer type.
442 
443  \return The layer type.
444  */
445  virtual const std::string& getType() const = 0;
446 
447  /*!
448  \brief It returns true if the layer can be used for instance to draw, otherwise, it returns false.
449 
450  This method can be used to check if the data referenced by the layer is available (accessible), or not.
451 
452  \return True, if the layer is valid, otherwise, it returns false.
453  */
454  virtual bool isValid() const = 0;
455 
456  /*!
457  \brief It draws the layer geographic objects in the given canvas using the informed SRS.
458 
459  The informed bounding box can be used to constraint the layer objects to be drawn.
460 
461  The bbox coordinates must be in the same Spatial Reference System given by srid.
462 
463  \param canvas The canvas were the layer objects will be drawn.
464  \param bbox The interest area to render the map.
465  \param srid The SRS to be used to draw the layer objects.
466  */
467  virtual void draw(Canvas* canvas, const te::gm::Envelope& bbox, int srid) = 0;
468 
469  protected:
470 
471  std::string m_id; //!< Layer id.
472  std::string m_title; //!< A brief description of this Layer that can be used by applications to show a text identifying this layer.
473  te::gm::Envelope m_mbr; //!< The layer bounding box.
474  int m_srid; //!< The identifier of the layer spatial reference system.
475  Visibility m_visibility; //!< It indicates the layer visibility.
476  bool m_visibilityChanged; //!< It indicates if the layer visibility has changed.
477  te::da::ObjectIdSet* m_selected; //!< The selected group of the layer.
478  te::se::Style* m_style; //!< The style to be applied to the geographic objects in the layer.
479  te::map::Grouping* m_grouping; //!< The grouping information.
480  te::map::Chart* m_chart; //!< The chart information.
481  };
482 
483  typedef boost::intrusive_ptr<AbstractLayer> AbstractLayerPtr;
484 
485  } // end namespace map
486 } // end namespace te
487 
488 #endif // __TERRALIB_MAPTOOLS_INTERNAL_ABSTRACTLAYER_H
489 
te::map::Grouping * m_grouping
The grouping information.
This class represents a set of unique ids created in the same context. i.e. from the same data set...
Definition: ObjectIdSet.h:53
This class contains the parameters needed for grouping the values of a Property.
Definition: Grouping.h:59
This abstract class describes a basic item to be organized in a tree-oriented way.
Definition: TreeItem.h:62
This is the base class for layers.
Definition: AbstractLayer.h:76
A canvas is an abstraction of a drawing area.
Definition: Canvas.h:91
#define TEMAPEXPORT
You can use this macro in order to export/import classes and functions from this module.
Definition: Config.h:98
te::da::ObjectIdSet * m_selected
The selected group of the layer.
te::gm::Envelope m_mbr
The layer bounding box.
Visibility
Each layer can have three states of visibility.
Definition: Enums.h:138
int m_srid
The identifier of the layer spatial reference system.
std::string m_id
Layer id.
SpatialRelation
Spatial relations between geometric objects.
Definition: Enums.h:122
std::string m_title
A brief description of this Layer that can be used by applications to show a text identifying this la...
AccessPolicy
Supported data access policies (can be used as bitfield).
Definition: Enums.h:40
te::map::Chart * m_chart
The chart information.
te::se::Style * m_style
The style to be applied to the geographic objects in the layer.
Geometry is the root class of the geometries hierarchy, it follows OGC and ISO standards.
Definition: Geometry.h:73
General enumerations.
TraverseType
A dataset can be traversed in two ways:
Definition: Enums.h:53
Visibility m_visibility
It indicates the layer visibility.
The Style defines the styling that is to be applied to a geographic dataset (vector geometries or cov...
Definition: Style.h:65
A class that models the description of a dataset.
Definition: DataSetType.h:72
bool m_visibilityChanged
It indicates if the layer visibility has changed.
This is an abstract class that models a query expression.
Definition: Expression.h:47
This class represents the informations needed to build map charts.
Definition: Chart.h:51
boost::intrusive_ptr< AbstractLayer > AbstractLayerPtr
An Envelope defines a 2D rectangular region.
Definition: Envelope.h:51
te::da::DataSetType LayerSchema
Definition: AbstractLayer.h:63
A wdiget used to customize a chart&#39;s style parameters.