All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
RasterLayerRenderer.cpp
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/RasterLayerRenderer.cpp
22 
23  \brief It renders the objects associated to a raster layer.
24 */
25 
26 // TerraLib
27 #include "../common/Translator.h"
28 #include "../geometry/Envelope.h"
29 #include "../raster/Raster.h"
30 #include "../se/CoverageStyle.h"
31 #include "../se/Utils.h"
32 #include "../srs/Config.h"
33 #include "Exception.h"
34 #include "RasterLayer.h"
35 #include "RasterLayerRenderer.h"
36 #include "Utils.h"
37 
38 // Boost
39 #include <boost/format.hpp>
40 #include <boost/lexical_cast.hpp>
41 
42 // STL
43 #include <cassert>
44 #include <memory>
45 
47 {
48 }
49 
51 {
52 }
53 
55  Canvas* canvas,
56  const te::gm::Envelope& bbox,
57  int srid)
58 {
59 // should I render this layer?
60  RasterLayer* rlayer = dynamic_cast<RasterLayer*>(layer);
61 
62  if(rlayer == 0)
63  throw Exception(TE_TR("Wrong type render type for this layer!"));
64 
65 // check if layer extent intersects the drawing area and so compute bounding box intersection
66  te::gm::Envelope reprojectedBBOX(bbox);
67 
68  if((rlayer->getSRID() != TE_UNKNOWN_SRS) && (srid != TE_UNKNOWN_SRS))
69  {
70  reprojectedBBOX.transform(srid, rlayer->getSRID());
71  }
72  else if(rlayer->getSRID() != srid)
73  {
74  throw Exception(TE_TR("The layer or map don't have a valid SRID!"));
75  }
76 
77  if(!reprojectedBBOX.intersects(rlayer->getExtent()))
78  return;
79 
80  te::gm::Envelope ibbox = reprojectedBBOX.intersection(rlayer->getExtent());
81 
82  std::auto_ptr<te::rst::Raster> raster(rlayer->getRaster());
83 
84 // get the associated layer style
85  te::se::Style* style = rlayer->getStyle();
86  if(style == 0)
87  {
88 // try create an appropriate style
89  style = te::se::CreateCoverageStyle(raster->getNumberOfBands());
90 
91  if(style == 0)
92  throw Exception((boost::format(TE_TR("Could not create a default coverage style to the layer %1%.")) % layer->getTitle()).str());
93 
94  rlayer->setStyle(style);
95  }
96 
97 // should I render this style?
98  te::se::CoverageStyle* cs = dynamic_cast<te::se::CoverageStyle*>(style);
99  if(cs == 0)
100  throw Exception(TE_TR("The layer style is not a Coverage Style!"));
101 
102  DrawRaster(raster.get(), canvas, ibbox, rlayer->getSRID(), bbox, srid, dynamic_cast<te::se::CoverageStyle*>(style));
103 }
A layer with reference to a raster.
bool intersects(const Envelope &rhs) const
It returns true if the envelopes "spatially intersects".
Definition: Envelope.h:493
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
virtual const te::gm::Envelope & getExtent() const
It returns the Layer extent (or minimum bounding box).
virtual const std::string & getTitle() const
It returns the layer title.
The CoverageStyle defines the styling that is to be applied to a subset of Coverage data...
Definition: CoverageStyle.h:45
TESEEXPORT Style * CreateCoverageStyle(const std::vector< te::rst::BandProperty * > &properties)
Try creates an appropriate coverage style based on given band properties.
Definition: Utils.cpp:299
te::rst::Raster * getRaster() const
#define TE_TR(message)
It marks a string in order to get translated.
Definition: Translator.h:347
void draw(AbstractLayer *layer, Canvas *canvas, const te::gm::Envelope &bbox, int srid)
It draws the layer geographic objects in the given canvas using the SRS informed. ...
An exception class for the MapTools module.
A layer with reference to a raster.
Definition: RasterLayer.h:52
An Envelope defines a 2D rectangular region.
Definition: Envelope.h:51
#define TE_UNKNOWN_SRS
A numeric value to represent a unknown SRS identification in TerraLib.
Definition: Config.h:44
virtual te::se::Style * getStyle() const
It returns the Style associated to the layer.
It renders the objects associated to a raster layer.
Utility functions for MapTools module.
A canvas is an abstraction of a drawing area.
Definition: Canvas.h:91
virtual void setStyle(te::se::Style *style)
It sets the Style associated to the layer.
virtual int getSRID() const
It returns the Spatial Reference System ID associated to the Layer.
Envelope intersection(const Envelope &rhs) const
It returns an envelope that represents the point set intersection with another envelope.
Definition: Envelope.h:543
void transform(int oldsrid, int newsrid)
It will transform the coordinates of the Envelope from the old SRS to the new one.
Definition: Envelope.cpp:92
TEMAPEXPORT void DrawRaster(te::da::DataSetType *type, te::da::DataSourcePtr ds, Canvas *canvas, const te::gm::Envelope &bbox, int bboxSRID, const te::gm::Envelope &visibleArea, int srid, te::se::CoverageStyle *style)
Definition: Utils.cpp:460