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 selection Style associated to the layer.
273 
274  \return The Style associated to the layer.
275 
276  \note The caller will NOT take the ownership of the given pointer.
277  */
278  virtual te::se::Style* getSelectionStyle() const;
279 
280  /*!
281  \brief It sets the selection Style associated to the layer.
282 
283  \param style The Style associated to the layer.
284 
285  \note The layer will take the ownership of the given pointer.
286  */
287  virtual void setSelectionStyle(te::se::Style* style);
288 
289  /*!
290  \brief It returns the Grouping associated to the Layer.
291 
292  \return The Grouping associated to the Layer.
293 
294  \note The caller will NOT take the ownership of the given pointer.
295  */
296  virtual te::map::Grouping* getGrouping() const;
297 
298  /*!
299  \brief It sets the Grouping associated to the Layer.
300 
301  \param grouping The Grouping to be associated to the Layer.
302 
303  \note The layer will take the ownership of the given pointer.
304  */
305  virtual void setGrouping(te::map::Grouping* grouping);
306 
307  /*!
308  \brief It returns the Chart associated to the Layer.
309 
310  \return The Chart associated to the Layer.
311 
312  \note The caller will NOT take the ownership of the given pointer.
313  */
314  virtual te::map::Chart* getChart() const;
315 
316  /*!
317  \brief It sets the Chart associated to the Layer.
318 
319  \param chart The Chart to be associated to the Layer.
320 
321  \note The layer will take the ownership of the given pointer.
322  */
323  virtual void setChart(te::map::Chart* chart);
324 
325  /*!
326  \brief
327 
328  \return
329  */
330  virtual const std::string& getGeomPropertyName() const;
331 
332  /*!
333  \brief
334 
335  \param name
336  */
337  virtual void setGeomPropertytName(const std::string& name);
338 
339  /*!
340  \brief It returns the layer schema.
341 
342  \return The Layer schema.
343 
344  \note The caller will take the ownership of the returned layer schema.
345  */
346  virtual std::auto_ptr<LayerSchema> getSchema() const = 0;
347 
348  /*!
349  \brief It gets the dataset identified by the layer name.
350 
351  \param travType The traverse type associated to the returned dataset.
352  \param accessPolicy Access policy.
353 
354  \return The caller of this method will take the ownership of the returned dataset.
355 
356  \exception Exception It can throws an exception if:
357  <ul>
358  <li>something goes wrong during the data retrieval</li>
359  <li>if the data source driver doesn't support the traversal type</li>
360  <li>if the data source driver doesn't support the access policy</li>
361  </ul>
362 
363  \note Not thread-safe!
364  */
365  virtual std::auto_ptr<te::da::DataSet> getData(te::common::TraverseType travType = te::common::FORWARDONLY,
366  const te::common::AccessPolicy accessPolicy = te::common::RAccess) const = 0;
367 
368  /*!
369  \brief It gets the dataset identified by the layer name using a spatial filter over the specified property.
370 
371  \param propertyName The name of the spatial property used to apply the spatial filter.
372  \param e A rectangle to be used as a spatial filter when retrieving datasets.
373  \param r The spatial relation to be used during the filter.
374  \param travType The traverse type associated to the returned dataset.
375  \param accessPolicy Access policy.
376 
377  \return The caller of this method will take the ownership of the returned DataSet.
378 
379  \exception Exception It can throws an exception if:
380  <ul>
381  <li>something goes wrong during data retrieval</li>
382  <li>if the data source driver doesn't support the traversal type</li>
383  <li>if the data source driver doesn't support the access policy</li>
384  </ul>
385 
386  \note Transactor will not take the ownership of the given envelope.
387 
388  \note The envelope coordinates should be in the same coordinate system as the dataset.
389 
390  \note Not thread-safe!
391  */
392  virtual std::auto_ptr<te::da::DataSet> getData(const std::string& propertyName,
393  const te::gm::Envelope* e,
396  const te::common::AccessPolicy accessPolicy = te::common::RAccess) const = 0;
397 
398  /*!
399  \brief It gets the dataset identified by the layer name using a spatial filter over the given geometric property.
400 
401  \param propertyName The name of the spatial property used to apply the spatial filter.
402  \param g A geometry to be used as a spatial filter when retrieving datasets.
403  \param r The spatial relation to be used during the filter.
404  \param travType The traverse type associated to the returned dataset.
405  \param accessPolicy Access policy.
406 
407  \return The caller of this method will take the ownership of the returned DataSet.
408 
409  \exception Exception It can throws an exception if:
410  <ul>
411  <li>something goes wrong during data retrieval</li>
412  <li>if the data source driver doesn't support the traversal type</li>
413  <li>if the data source driver doesn't support the access policy</li>
414  </ul>
415 
416  \note Transactor will not take the ownership of the given geometry.
417 
418  \note The geometry coordinates should be in the same coordinate system as the dataset.
419 
420  \note Not thread-safe!
421  */
422  virtual std::auto_ptr<te::da::DataSet> getData(const std::string& propertyName,
423  const te::gm::Geometry* g,
426  const te::common::AccessPolicy accessPolicy = te::common::RAccess) const = 0;
427 
428  /*!
429  \brief It gets the dataset identified by the layer name using the given restriction.
430 
431  \param restriction The restriction expression that will be used.
432  \param travType The traverse type associated to the returned dataset.
433  \param accessPolicy Access policy.
434 
435  \return The caller of this method will take the ownership of the returned DataSet.
436 
437  \exception Exception It can throws an exception if:
438  <ul>
439  <li>something goes wrong during data retrieval</li>
440  <li>if the data source driver doesn't support the traversal type</li>
441  <li>if the data source driver doesn't support the access policy</li>
442  </ul>
443 
444  \note Not thread-safe!
445  */
446  virtual std::auto_ptr<te::da::DataSet> getData(te::da::Expression* restriction,
448  const te::common::AccessPolicy accessPolicy = te::common::RAccess) const = 0;
449 
450  /*!
451  \brief It gets the dataset from the given set of objects identification.
452 
453  \param oids The set of object ids.
454  \param travType The traverse type associated to the returned dataset.
455  \param accessPolicy Access policy.
456 
457  \return The caller of this method will take the ownership of the returned dataset.
458 
459  \exception Exception It can throws an exception if:
460  <ul>
461  <li>something goes wrong during the data retrieval</li>
462  <li>if the data source driver doesn't support the traversal type</li>
463  <li>if the data source driver doesn't support the access policy</li>
464  </ul>
465 
466  \note Not thread-safe!
467  */
468  virtual std::auto_ptr<te::da::DataSet> getData(const te::da::ObjectIdSet* oids,
470  const te::common::AccessPolicy accessPolicy = te::common::RAccess) const = 0;
471 
472  /*!
473  \brief It returns the layer type.
474 
475  \return The layer type.
476  */
477  virtual const std::string& getType() const = 0;
478 
479  /*!
480  \brief It returns true if the layer can be used for instance to draw, otherwise, it returns false.
481 
482  This method can be used to check if the data referenced by the layer is available (accessible), or not.
483 
484  \return True, if the layer is valid, otherwise, it returns false.
485  */
486  virtual bool isValid() const = 0;
487 
488  /*!
489  \brief It draws the layer geographic objects in the given canvas using the informed SRS.
490 
491  The informed bounding box can be used to constraint the layer objects to be drawn.
492 
493  The bbox coordinates must be in the same Spatial Reference System given by srid.
494 
495  \param canvas The canvas were the layer objects will be drawn.
496  \param bbox The interest area to render the map.
497  \param srid The SRS to be used to draw the layer objects.
498  \param scale The current scale of display.
499  */
500  virtual void draw(Canvas* canvas, const te::gm::Envelope& bbox, int srid, const double& scale, bool* cancel) = 0;
501 
502  /*!
503  \brief It returns the composition mode.
504 
505  Composition modes are used to specify how the pixels in one image, the source, are merged with the pixel in another image, the destination.
506 
507  \return The composition mode enum.
508  */
509  te::map::CompositionMode getCompositionMode() const;
510 
511  /*!
512  \brief It sets the composition mode.
513 
514  Composition modes are used to specify how the pixels in one image, the source, are merged with the pixel in another image, the destination.
515 
516  \param mode The composition mode enum.
517  */
518  void setCompositionMode(te::map::CompositionMode mode);
519 
520  /*!
521  \brief It returns the encoding type.
522 
523  Char enconding is used to inform to data source how to load string information from data.
524 
525  \return The encoding type.
526  */
527  te::core::EncodingType getEncoding() const;
528 
529  /*!
530  \brief It set the encoding type.
531 
532  Char enconding is used to inform to data source how to load string information from data.
533 
534  \param The encoding type.
535  */
536  void setEncoding(te::core::EncodingType et);
537 
538  /*!
539  \brief Its indicate that the layer schema is out of date.
540  */
541  virtual void setOutOfDate();
542 
543  /*!
544  \brief
545 
546  \return
547  */
548  const std::string& getDataSetName() const;
549 
550  /*!
551  \brief
552 
553  \param name
554  */
555  void setDataSetName(const std::string& name);
556 
557  /*!
558  \brief
559 
560  \return
561  */
562  virtual const std::string& getDataSourceId() const;
563 
564  /*!
565  \brief
566 
567  \param id
568  */
569  virtual void setDataSourceId(const std::string& id);
570 
571  protected:
572 
573  std::string m_id; //!< Layer id.
574  std::string m_title; //!< A brief description of this Layer that can be used by applications to show a text identifying this layer.
575  te::gm::Envelope m_mbr; //!< The layer bounding box.
576  int m_srid; //!< The identifier of the layer spatial reference system.
577  Visibility m_visibility; //!< It indicates the layer visibility.
578  bool m_visibilityChanged; //!< It indicates if the layer visibility has changed.
579  te::da::ObjectIdSet* m_selected; //!< The selected group of the layer.
580  te::se::Style* m_style; //!< The style to be applied to the geographic objects in the layer.
581  te::se::Style* m_selectionStyle; //!< The selection style to be applied to the geographic objects in the layer.
582  te::map::Grouping* m_grouping; //!< The grouping information.
583  te::map::Chart* m_chart; //!< The chart information.
584  std::string m_geomPropertyName; //!< The name of the referenced geometry property.
585  te::map::CompositionMode m_compositionMode; //!< The composition mode used to merged the canvas.
586  std::string m_datasetName; //!< The dataset name where we will retrieve the layer objects.
587  std::string m_datasourceId; //!< DataSource id.
588  te::core::EncodingType m_encoding; //!< The char encoding of the layer;
589  };
590 
591  typedef boost::intrusive_ptr<AbstractLayer> AbstractLayerPtr;
592 
593  } // end namespace map
594 } // end namespace te
595 
596 #endif // __TERRALIB_MAPTOOLS_INTERNAL_ABSTRACTLAYER_H
597 
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.
EncodingType
Supported character encodings.
Definition: CharEncoding.h:50
CompositionMode
The composition mode used to render the canvas.
Definition: Enums.h:175
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
te::se::Style * m_selectionStyle
The selection style to be applied to the geographic objects in the layer.
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:74
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:139
boost::intrusive_ptr< AbstractLayer > AbstractLayerPtr
Visibility m_visibility
It indicates the layer visibility.
te::core::EncodingType m_encoding
The char encoding of the layer;.
bool m_visibilityChanged
It indicates if the layer visibility has changed.