AbstractLayer.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 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
309 
310  \return
311  */
312  virtual const std::string& getGeomPropertyName() const;
313 
314  /*!
315  \brief
316 
317  \param name
318  */
319  virtual void setGeomPropertytName(const std::string& name);
320 
321  /*!
322  \brief It returns the layer schema.
323 
324  \return The Layer schema.
325 
326  \note The caller will take the ownership of the returned layer schema.
327  */
328  virtual std::auto_ptr<LayerSchema> getSchema() const = 0;
329 
330  /*!
331  \brief It gets the dataset identified by the layer name.
332 
333  \param travType The traverse type associated to the returned dataset.
334  \param accessPolicy Access policy.
335 
336  \return The caller of this method will take the ownership of the returned dataset.
337 
338  \exception Exception It can throws an exception if:
339  <ul>
340  <li>something goes wrong during the data retrieval</li>
341  <li>if the data source driver doesn't support the traversal type</li>
342  <li>if the data source driver doesn't support the access policy</li>
343  </ul>
344 
345  \note Not thread-safe!
346  */
347  virtual std::auto_ptr<te::da::DataSet> getData(te::common::TraverseType travType = te::common::FORWARDONLY,
348  const te::common::AccessPolicy accessPolicy = te::common::RAccess) const = 0;
349 
350  /*!
351  \brief It gets the dataset identified by the layer name using a spatial filter over the specified property.
352 
353  \param propertyName The name of the spatial property used to apply the spatial filter.
354  \param e A rectangle to be used as a spatial filter when retrieving datasets.
355  \param r The spatial relation to be used during the filter.
356  \param travType The traverse type associated to the returned dataset.
357  \param accessPolicy Access policy.
358 
359  \return The caller of this method will take the ownership of the returned DataSet.
360 
361  \exception Exception It can throws an exception if:
362  <ul>
363  <li>something goes wrong during data retrieval</li>
364  <li>if the data source driver doesn't support the traversal type</li>
365  <li>if the data source driver doesn't support the access policy</li>
366  </ul>
367 
368  \note Transactor will not take the ownership of the given envelope.
369 
370  \note The envelope coordinates should be in the same coordinate system as the dataset.
371 
372  \note Not thread-safe!
373  */
374  virtual std::auto_ptr<te::da::DataSet> getData(const std::string& propertyName,
375  const te::gm::Envelope* e,
378  const te::common::AccessPolicy accessPolicy = te::common::RAccess) const = 0;
379 
380  /*!
381  \brief It gets the dataset identified by the layer name using a spatial filter over the given geometric property.
382 
383  \param propertyName The name of the spatial property used to apply the spatial filter.
384  \param g A geometry to be used as a spatial filter when retrieving datasets.
385  \param r The spatial relation to be used during the filter.
386  \param travType The traverse type associated to the returned dataset.
387  \param accessPolicy Access policy.
388 
389  \return The caller of this method will take the ownership of the returned DataSet.
390 
391  \exception Exception It can throws an exception if:
392  <ul>
393  <li>something goes wrong during data retrieval</li>
394  <li>if the data source driver doesn't support the traversal type</li>
395  <li>if the data source driver doesn't support the access policy</li>
396  </ul>
397 
398  \note Transactor will not take the ownership of the given geometry.
399 
400  \note The geometry coordinates should be in the same coordinate system as the dataset.
401 
402  \note Not thread-safe!
403  */
404  virtual std::auto_ptr<te::da::DataSet> getData(const std::string& propertyName,
405  const te::gm::Geometry* g,
408  const te::common::AccessPolicy accessPolicy = te::common::RAccess) const = 0;
409 
410  /*!
411  \brief It gets the dataset identified by the layer name using the given restriction.
412 
413  \param restriction The restriction expression that will be used.
414  \param travType The traverse type associated to the returned dataset.
415  \param accessPolicy Access policy.
416 
417  \return The caller of this method will take the ownership of the returned DataSet.
418 
419  \exception Exception It can throws an exception if:
420  <ul>
421  <li>something goes wrong during data retrieval</li>
422  <li>if the data source driver doesn't support the traversal type</li>
423  <li>if the data source driver doesn't support the access policy</li>
424  </ul>
425 
426  \note Not thread-safe!
427  */
428  virtual std::auto_ptr<te::da::DataSet> getData(te::da::Expression* restriction,
430  const te::common::AccessPolicy accessPolicy = te::common::RAccess) const = 0;
431 
432  /*!
433  \brief It gets the dataset from the given set of objects identification.
434 
435  \param oids The set of object ids.
436  \param travType The traverse type associated to the returned dataset.
437  \param accessPolicy Access policy.
438 
439  \return The caller of this method will take the ownership of the returned dataset.
440 
441  \exception Exception It can throws an exception if:
442  <ul>
443  <li>something goes wrong during the data retrieval</li>
444  <li>if the data source driver doesn't support the traversal type</li>
445  <li>if the data source driver doesn't support the access policy</li>
446  </ul>
447 
448  \note Not thread-safe!
449  */
450  virtual std::auto_ptr<te::da::DataSet> getData(const te::da::ObjectIdSet* oids,
452  const te::common::AccessPolicy accessPolicy = te::common::RAccess) const = 0;
453 
454  /*!
455  \brief It returns the layer type.
456 
457  \return The layer type.
458  */
459  virtual const std::string& getType() const = 0;
460 
461  /*!
462  \brief It returns true if the layer can be used for instance to draw, otherwise, it returns false.
463 
464  This method can be used to check if the data referenced by the layer is available (accessible), or not.
465 
466  \return True, if the layer is valid, otherwise, it returns false.
467  */
468  virtual bool isValid() const = 0;
469 
470  /*!
471  \brief It draws the layer geographic objects in the given canvas using the informed SRS.
472 
473  The informed bounding box can be used to constraint the layer objects to be drawn.
474 
475  The bbox coordinates must be in the same Spatial Reference System given by srid.
476 
477  \param canvas The canvas were the layer objects will be drawn.
478  \param bbox The interest area to render the map.
479  \param srid The SRS to be used to draw the layer objects.
480  \param scale The current scale of display.
481  */
482  virtual void draw(Canvas* canvas, const te::gm::Envelope& bbox, int srid, const double& scale) = 0;
483 
484  /*!
485  \brief It returns the composition mode.
486 
487  Composition modes are used to specify how the pixels in one image, the source, are merged with the pixel in another image, the destination.
488 
489  \return The composition mode enum.
490  */
491  te::map::CompositionMode getCompositionMode() const;
492 
493  /*!
494  \brief It sets the composition mode.
495 
496  Composition modes are used to specify how the pixels in one image, the source, are merged with the pixel in another image, the destination.
497 
498  \param mode The composition mode enum.
499  */
500  void setCompositionMode(te::map::CompositionMode mode);
501 
502  /*!
503  \brief Its indicate that the layer schema is out of date.
504  */
505  virtual void setOutOfDate();
506 
507  /*!
508  \brief
509 
510  \return
511  */
512  const std::string& getDataSetName() const;
513 
514  /*!
515  \brief
516 
517  \param name
518  */
519  void setDataSetName(const std::string& name);
520 
521  /*!
522  \brief
523 
524  \return
525  */
526  virtual const std::string& getDataSourceId() const;
527 
528  /*!
529  \brief
530 
531  \param id
532  */
533  virtual void setDataSourceId(const std::string& id);
534 
535  protected:
536 
537  std::string m_id; //!< Layer id.
538  std::string m_title; //!< A brief description of this Layer that can be used by applications to show a text identifying this layer.
539  te::gm::Envelope m_mbr; //!< The layer bounding box.
540  int m_srid; //!< The identifier of the layer spatial reference system.
541  Visibility m_visibility; //!< It indicates the layer visibility.
542  bool m_visibilityChanged; //!< It indicates if the layer visibility has changed.
543  te::da::ObjectIdSet* m_selected; //!< The selected group of the layer.
544  te::se::Style* m_style; //!< The style to be applied to the geographic objects in the layer.
545  te::map::Grouping* m_grouping; //!< The grouping information.
546  te::map::Chart* m_chart; //!< The chart information.
547  std::string m_geomPropertyName; //!< The name of the referenced geometry property.
548  te::map::CompositionMode m_compositionMode; //!< The composition mode used to merged the canvas.
549  std::string m_datasetName; //!< The dataset name where we will retrieve the layer objects.
550  std::string m_datasourceId; //!< DataSource id;
551  };
552 
553  typedef boost::intrusive_ptr<AbstractLayer> AbstractLayerPtr;
554 
555  } // end namespace map
556 } // end namespace te
557 
558 #endif // __TERRALIB_MAPTOOLS_INTERNAL_ABSTRACTLAYER_H
559 
te::map::Grouping * m_grouping
The grouping information.
std::string m_datasetName
The dataset name where we will retrieve the layer objects.
te::map::Chart * m_chart
The chart information.
The Style defines the styling that is to be applied to a geographic dataset (vector geometries or cov...
Definition: Style.h:65
This is the base class for layers.
Definition: AbstractLayer.h:76
std::string m_id
Layer id.
This abstract class describes a basic item to be organized in a tree-oriented way.
Definition: TreeItem.h:62
A class that models the description of a dataset.
Definition: DataSetType.h:72
A wdiget used to customize a chart's style parameters.
te::da::ObjectIdSet * m_selected
The selected group of the layer.
SpatialRelation
Spatial relations between geometric objects.
Definition: Enums.h:127
std::string m_geomPropertyName
The name of the referenced geometry property.
This is an abstract class that models a query expression.
Definition: Expression.h:47
int m_srid
The identifier of the layer spatial reference system.
CompositionMode
The composition mode used to render the canvas.
Definition: Enums.h:174
AccessPolicy
Supported data access policies (can be used as bitfield).
Definition: Enums.h:40
This class contains the parameters needed for grouping the values of a Property.
Definition: Grouping.h:59
TraverseType
A dataset can be traversed in two ways:
Definition: Enums.h:53
te::map::CompositionMode m_compositionMode
The composition mode used to merged the canvas.
This class represents the informations needed to build map charts.
Definition: Chart.h:51
An Envelope defines a 2D rectangular region.
Definition: Envelope.h:51
This class represents a set of unique ids created in the same context. i.e. from the same data set...
Definition: ObjectIdSet.h:55
URI C++ Library.
General enumerations.
te::gm::Envelope m_mbr
The layer bounding box.
#define TEMAPEXPORT
You can use this macro in order to export/import classes and functions from this module.
Definition: Config.h:60
te::da::DataSetType LayerSchema
Definition: AbstractLayer.h:63
std::string m_title
A brief description of this Layer that can be used by applications to show a text identifying this la...
Geometry is the root class of the geometries hierarchy, it follows OGC and ISO standards.
Definition: Geometry.h:73
A canvas is an abstraction of a drawing area.
Definition: Canvas.h:92
std::string m_datasourceId
DataSource id;.
te::se::Style * m_style
The style to be applied to the geographic objects in the layer.
Visibility
Each layer can have three states of visibility.
Definition: Enums.h:138
boost::intrusive_ptr< AbstractLayer > AbstractLayerPtr
Visibility m_visibility
It indicates the layer visibility.
bool m_visibilityChanged
It indicates if the layer visibility has changed.