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;
65 
67 
68  /*!
69  \class AbstractLayer
70 
71  \brief This is the base class for layers.
72 
73  \ingroup map
74 
75  \sa TreeItem, DataSetLayer, QueryLayer, FolderLayer, RasterLayer
76  */
78  {
79  public:
80 
81  /*!
82  \brief It initializes a new layer.
83 
84  \param parent The parent layer (NULL if it has no parent).
85  */
86  AbstractLayer(AbstractLayer* parent = 0);
87 
88  /*!
89  \brief It initializes a new layer.
90 
91  \param id The layer id.
92  \param parent The parent layer (NULL if it has no parent).
93  */
94  AbstractLayer(const std::string& id, AbstractLayer* parent = 0);
95 
96  /*!
97  \brief It initializes a new layer.
98 
99  \param id The layer id.
100  \param title The title is a brief description about the layer.
101  \param parent The parent layer (NULL if it has no parent).
102  */
103  AbstractLayer(const std::string& id, const std::string& title, AbstractLayer* parent = 0);
104 
105  /*! \brief Virtual destructor. */
106  virtual ~AbstractLayer();
107 
108  /*!
109  \brief It returns a clone of the object.
110 
111  \return A clone of the object.
112  */
113  virtual AbstractLayer* clone() = 0;
114 
115  /*!
116  \brief It returns the layer id.
117 
118  \return The layer id.
119  */
120  virtual const std::string& getId() const;
121 
122  /*!
123  \brief It sets the layer id.
124 
125  \param id The layer id.
126  */
127  virtual void setId(const std::string& id);
128 
129  /*!
130  \brief It returns the layer title.
131 
132  \return The layer title.
133  */
134  virtual const std::string& getTitle() const;
135 
136  /*!
137  \brief It sets the layer title.
138 
139  \param title The layer title.
140  */
141  virtual void setTitle(const std::string& title);
142 
143  /*!
144  \brief It returns a list with the descendants of this layer.
145 
146  \return A list containing the descendants of this layer.
147  */
148  std::vector<te::map::AbstractLayer*> getDescendants();
149 
150  /*!
151  \brief It returns a list with the ancestors of this layer.
152 
153  \return A list containing the ancestors of this layer.
154  */
155  std::vector<te::map::AbstractLayer*> getAncestors();
156 
157  /*!
158  \brief It returns the layer visibility.
159 
160  This information can be used, for instance, to know if the layer must be drawn.
161 
162  \return The layer visibility.
163  */
164  virtual Visibility getVisibility() const;
165 
166  /*!
167  \brief It sets the layer visibility.
168 
169  This information can be used, for instance, to know if the layer must be drawn.
170 
171  \param v The layer visibility.
172  */
173  virtual void setVisibility(Visibility v);
174 
175  /*!
176  \brief It gets the flag that indicates if the layer visibility has changed.
177 
178  \return If true, the layer visibility has changed.
179  */
180  bool hasVisibilityChanged();
181 
182  /*!
183  \brief It sets that the status of the layer visibility is to be changed or not..
184 
185  \param visChanged If true, the status of the layer visibility is to be changed; otherwise, it returns false.
186  */
187  void setVisibilityAsChanged(bool visChanged);
188 
189  /*!
190  \brief It updates the visibility of the ancestors of this layer, if any.
191  */
192  void updateVisibilityOfAncestors();
193 
194  /*!
195  \brief It updates the visibility of this layer.
196  */
197  virtual void updateVisibility();
198 
199  /*!
200  \brief It returns the Layer extent (or minimum bounding box).
201 
202  \return The Layer extent (or minimum bounding box) with coordinates in the same SRS as the layer.
203  */
204  virtual const te::gm::Envelope& getExtent() const;
205 
206  /*!
207  \brief It sets the Layer extent (or minimum bounding box).
208 
209  \param mbr The Layer extent (or minimum bounding box).
210 
211  \pre The mbr coordinates must be in the same SRS as the layer.
212  */
213  virtual void setExtent(const te::gm::Envelope& mbr);
214 
215  /*!
216  \brief It returns the Spatial Reference System ID associated to the Layer.
217 
218  \return The Spatial Reference System ID associated to the Layer.
219  */
220  virtual int getSRID() const;
221 
222  /*!
223  \brief It sets the Spatial Reference System ID associated to the Layer.
224 
225  \param srid The Spatial Reference System ID to be associated to the Layer.
226  */
227  virtual void setSRID(int srid);
228 
229  /*!
230  \brief It adds the given oids to the selected group of this Layer.
231 
232  \param oids The oids that will be added.
233 
234  \note The layer will take the ownership of the given pointer.
235  */
236  virtual void select(te::da::ObjectIdSet* oids);
237 
238  /*!
239  \brief It returns the selected group of this Layer.
240 
241  \return The selected group of this Layer.
242 
243  \note The caller will NOT take the ownership of the given pointer.
244  */
245  virtual const te::da::ObjectIdSet* getSelected() const;
246 
247  /*!
248  \brief It removes the given oids from the selected group of this Layer.
249 
250  \param oids The oids that will be removed.
251 
252  \note The layer will NOT take the ownership of the given pointer.
253  */
254  virtual void deselect(const te::da::ObjectIdSet* oids);
255 
256  /*!
257  \brief It clears the selected group of this Layer.
258  */
259  virtual void clearSelected();
260 
261  /*!
262  \brief It returns the Style associated to the layer.
263 
264  \return The Style associated to the layer.
265 
266  \note The caller will NOT take the ownership of the given pointer.
267  */
268  virtual te::se::Style* getStyle() const;
269 
270  /*!
271  \brief It sets the Style associated to the layer.
272 
273  \param style The Style associated to the layer.
274 
275  \note The layer will take the ownership of the given pointer.
276  */
277  virtual void setStyle(te::se::Style* style);
278 
279  /*!
280  \brief It returns the selection Style associated to the layer.
281 
282  \return The Style associated to the layer.
283 
284  \note The caller will NOT take the ownership of the given pointer.
285  */
286  virtual te::se::Style* getSelectionStyle() const;
287 
288  /*!
289  \brief It sets the selection Style associated to the layer.
290 
291  \param style The Style associated to the layer.
292 
293  \note The layer will take the ownership of the given pointer.
294  */
295  virtual void setSelectionStyle(te::se::Style* style);
296 
297  /*!
298  \brief It returns the Grouping associated to the Layer.
299 
300  \return The Grouping associated to the Layer.
301 
302  \note The caller will NOT take the ownership of the given pointer.
303  */
304  virtual te::map::Grouping* getGrouping() const;
305 
306  /*!
307  \brief It sets the Grouping associated to the Layer.
308 
309  \param grouping The Grouping to be associated to the Layer.
310 
311  \note The layer will take the ownership of the given pointer.
312  */
313  virtual void setGrouping(te::map::Grouping* grouping);
314 
315  /*!
316  \brief It returns the Chart associated to the Layer.
317 
318  \return The Chart associated to the Layer.
319 
320  \note The caller will NOT take the ownership of the given pointer.
321  */
322  virtual te::map::Chart* getChart() const;
323 
324  /*!
325  \brief It sets the Chart associated to the Layer.
326 
327  \param chart The Chart to be associated to the Layer.
328 
329  \note The layer will take the ownership of the given pointer.
330  */
331  virtual void setChart(te::map::Chart* chart);
332 
333  /*!
334  \brief It returns the raster contrast associated to the Layer.
335 
336  \return The raster contrast associated to the Layer.
337 
338  \note The caller will NOT take the ownership of the given pointer.
339  */
340  virtual te::map::RasterContrast* getRasterContrast() const;
341 
342  /*!
343  \brief It sets the raster contrast associated to the Layer.
344 
345  \param chart The raster contrast to be associated to the Layer.
346 
347  \note The layer will take the ownership of the given pointer.
348  */
349  virtual void setRasterContrast(te::map::RasterContrast* contrast);
350 
351  /*!
352  \brief
353 
354  \return
355  */
356  virtual const std::string& getGeomPropertyName() const;
357 
358  /*!
359  \brief
360 
361  \param name
362  */
363  virtual void setGeomPropertytName(const std::string& name);
364 
365  /*!
366  \brief It returns the layer schema.
367 
368  \return The Layer schema.
369 
370  \note The caller will take the ownership of the returned layer schema.
371  */
372  virtual std::unique_ptr<LayerSchema> getSchema() const = 0;
373 
374  /*!
375  \brief It gets the dataset identified by the layer name.
376 
377  \param travType The traverse type associated to the returned dataset.
378  \param accessPolicy Access policy.
379 
380  \return The caller of this method will take the ownership of the returned dataset.
381 
382  \exception Exception It can throws an exception if:
383  <ul>
384  <li>something goes wrong during the data retrieval</li>
385  <li>if the data source driver doesn't support the traversal type</li>
386  <li>if the data source driver doesn't support the access policy</li>
387  </ul>
388 
389  \note Not thread-safe!
390  */
391  virtual std::unique_ptr<te::da::DataSet> getData(te::common::TraverseType travType = te::common::FORWARDONLY,
392  const te::common::AccessPolicy accessPolicy = te::common::RAccess) const = 0;
393 
394  /*!
395  \brief It gets the dataset identified by the layer name using a spatial filter over the specified property.
396 
397  \param propertyName The name of the spatial property used to apply the spatial filter.
398  \param e A rectangle to be used as a spatial filter when retrieving datasets.
399  \param r The spatial relation to be used during the filter.
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 Transactor will not take the ownership of the given envelope.
413 
414  \note The envelope coordinates should be in the same coordinate system as the dataset.
415 
416  \note Not thread-safe!
417  */
418  virtual std::unique_ptr<te::da::DataSet> getData(const std::string& propertyName,
419  const te::gm::Envelope* e,
422  const te::common::AccessPolicy accessPolicy = te::common::RAccess) const = 0;
423 
424  /*!
425  \brief It gets the dataset identified by the layer name using a spatial filter over the given geometric property.
426 
427  \param propertyName The name of the spatial property used to apply the spatial filter.
428  \param g A geometry to be used as a spatial filter when retrieving datasets.
429  \param r The spatial relation to be used during the filter.
430  \param travType The traverse type associated to the returned dataset.
431  \param accessPolicy Access policy.
432 
433  \return The caller of this method will take the ownership of the returned DataSet.
434 
435  \exception Exception It can throws an exception if:
436  <ul>
437  <li>something goes wrong during data retrieval</li>
438  <li>if the data source driver doesn't support the traversal type</li>
439  <li>if the data source driver doesn't support the access policy</li>
440  </ul>
441 
442  \note Transactor will not take the ownership of the given geometry.
443 
444  \note The geometry coordinates should be in the same coordinate system as the dataset.
445 
446  \note Not thread-safe!
447  */
448  virtual std::unique_ptr<te::da::DataSet> getData(const std::string& propertyName,
449  const te::gm::Geometry* g,
452  const te::common::AccessPolicy accessPolicy = te::common::RAccess) const = 0;
453 
454  /*!
455  \brief It gets the dataset identified by the layer name using the given restriction.
456 
457  \param restriction The restriction expression that will be used.
458  \param travType The traverse type associated to the returned dataset.
459  \param accessPolicy Access policy.
460 
461  \return The caller of this method will take the ownership of the returned DataSet.
462 
463  \exception Exception It can throws an exception if:
464  <ul>
465  <li>something goes wrong during data retrieval</li>
466  <li>if the data source driver doesn't support the traversal type</li>
467  <li>if the data source driver doesn't support the access policy</li>
468  </ul>
469 
470  \note Not thread-safe!
471  */
472  virtual std::unique_ptr<te::da::DataSet> getData(te::da::Expression* restriction,
474  const te::common::AccessPolicy accessPolicy = te::common::RAccess) const = 0;
475 
476  /*!
477  \brief It gets the dataset from the given set of objects identification.
478 
479  \param oids The set of object ids.
480  \param travType The traverse type associated to the returned dataset.
481  \param accessPolicy Access policy.
482 
483  \return The caller of this method will take the ownership of the returned dataset.
484 
485  \exception Exception It can throws an exception if:
486  <ul>
487  <li>something goes wrong during the data retrieval</li>
488  <li>if the data source driver doesn't support the traversal type</li>
489  <li>if the data source driver doesn't support the access policy</li>
490  </ul>
491 
492  \note Not thread-safe!
493  */
494  virtual std::unique_ptr<te::da::DataSet> getData(const te::da::ObjectIdSet* oids,
496  const te::common::AccessPolicy accessPolicy = te::common::RAccess) const = 0;
497 
498  /*!
499  \brief It returns the layer type.
500 
501  \return The layer type.
502  */
503  virtual const std::string& getType() const = 0;
504 
505  /*!
506  \brief It returns true if the layer can be used for instance to draw, otherwise, it returns false.
507 
508  This method can be used to check if the data referenced by the layer is available (accessible), or not.
509 
510  \return True, if the layer is valid, otherwise, it returns false.
511  */
512  virtual bool isValid() const = 0;
513 
514  /*!
515  \brief It draws the layer geographic objects in the given canvas using the informed SRS.
516 
517  The informed bounding box can be used to constraint the layer objects to be drawn.
518 
519  The bbox coordinates must be in the same Spatial Reference System given by srid.
520 
521  \param canvas The canvas were the layer objects will be drawn.
522  \param bbox The interest area to render the map.
523  \param srid The SRS to be used to draw the layer objects.
524  \param scale The current scale of display.
525  */
526  virtual void draw(Canvas* canvas, const te::gm::Envelope& bbox, int srid, const double& scale, bool* cancel) = 0;
527 
528  /*!
529  \brief It returns the composition mode.
530 
531  Composition modes are used to specify how the pixels in one image, the source, are merged with the pixel in another image, the destination.
532 
533  \return The composition mode enum.
534  */
535  te::map::CompositionMode getCompositionMode() const;
536 
537  /*!
538  \brief It sets the composition mode.
539 
540  Composition modes are used to specify how the pixels in one image, the source, are merged with the pixel in another image, the destination.
541 
542  \param mode The composition mode enum.
543  */
544  void setCompositionMode(te::map::CompositionMode mode);
545 
546  /*!
547  \brief It returns the encoding type.
548 
549  Char enconding is used to inform to data source how to load string information from data.
550 
551  \return The encoding type.
552  */
553  te::core::EncodingType getEncoding() const;
554 
555  /*!
556  \brief It set the encoding type.
557 
558  Char enconding is used to inform to data source how to load string information from data.
559 
560  \param The encoding type.
561  */
562  void setEncoding(te::core::EncodingType et);
563 
564  /*!
565  \brief Its indicate that the layer schema is out of date.
566  */
567  virtual void setOutOfDate();
568 
569  /*!
570  \brief
571 
572  \return
573  */
574  const std::string& getDataSetName() const;
575 
576  /*!
577  \brief
578 
579  \param name
580  */
581  void setDataSetName(const std::string& name);
582 
583  /*!
584  \brief
585 
586  \return
587  */
588  virtual const std::string& getDataSourceId() const;
589 
590  /*!
591  \brief
592 
593  \param id
594  */
595  virtual void setDataSourceId(const std::string& id);
596 
597  protected:
598 
599  std::string m_id; //!< Layer id.
600  std::string m_title; //!< A brief description of this Layer that can be used by applications to show a text identifying this layer.
601  mutable te::gm::Envelope m_mbr; //!< The layer bounding box.
602  int m_srid; //!< The identifier of the layer spatial reference system.
603  Visibility m_visibility; //!< It indicates the layer visibility.
604  bool m_visibilityChanged; //!< It indicates if the layer visibility has changed.
605  te::da::ObjectIdSet* m_selected; //!< The selected group of the layer.
606  te::se::Style* m_style; //!< The style to be applied to the geographic objects in the layer.
607  te::se::Style* m_selectionStyle; //!< The selection style to be applied to the geographic objects in the layer.
608  te::map::Grouping* m_grouping; //!< The grouping information.
609  te::map::Chart* m_chart; //!< The chart information.
610  te::map::RasterContrast* m_contrast; //!< The contrast information to be applied to a raster object in the layer.
611  std::string m_geomPropertyName; //!< The name of the referenced geometry property.
612  te::map::CompositionMode m_compositionMode; //!< The composition mode used to merged the canvas.
613  std::string m_datasetName; //!< The dataset name where we will retrieve the layer objects.
614  std::string m_datasourceId; //!< DataSource id.
615  te::core::EncodingType m_encoding; //!< The char encoding of the layer;
616  };
617 
618  typedef boost::intrusive_ptr<AbstractLayer> AbstractLayerPtr;
619 
620  } // end namespace map
621 } // end namespace te
622 
623 #endif // __TERRALIB_MAPTOOLS_INTERNAL_ABSTRACTLAYER_H
624 
te::map::RasterContrast * m_contrast
The contrast information to be applied to a raster object in the layer.
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:77
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&#39;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:57
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
TerraLib.
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:64
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:75
This class contains the parameters needed to apply dynamic contrast over a raster.
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.