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