All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
RasterLayer.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/RasterLayer.cpp
22 
23  \brief A layer with reference to a raster.
24 */
25 
26 // TerraLib
27 #include "../common/Translator.h"
28 #include "../dataaccess/dataset/DataSetType.h"
29 #include "../raster/Band.h"
30 #include "../raster/BandProperty.h"
31 #include "../raster/Grid.h"
32 #include "../raster/Raster.h"
33 #include "../raster/RasterFactory.h"
34 #include "Exception.h"
35 #include "RasterLayer.h"
36 #include "RendererFactory.h"
37 
38 // Boost
39 #include <boost/filesystem.hpp>
40 #include <boost/format.hpp>
41 
42 const std::string te::map::RasterLayer::sm_type("RASTERLAYER");
43 
45  : AbstractLayer(parent)
46 {
47 }
48 
49 te::map::RasterLayer::RasterLayer(const std::string& id, AbstractLayer* parent)
50  : AbstractLayer(id, parent)
51 {
52 }
53 
54 te::map::RasterLayer::RasterLayer(const std::string& id,
55  const std::string& title,
56  AbstractLayer* parent)
57  : AbstractLayer(id, title, parent)
58 {
59 }
60 
62 {
63  m_rinfo.clear();
64 }
65 
66 std::auto_ptr<te::map::LayerSchema> te::map::RasterLayer::getSchema() const
67 {
68  LayerSchema* ls = 0;
69 
71 
72  if(r)
73  {
74  te::rst::Grid* grid = new te::rst::Grid(*r->getGrid());
75 
76  std::vector<te::rst::BandProperty*> bprops;
77 
78  for(size_t t = 0; t < r->getNumberOfBands(); ++t)
79  {
81 
82  bprops.push_back(bp);
83  }
84 
85  te::rst::RasterProperty* rp = new te::rst::RasterProperty(grid, bprops, m_rinfo);
86 
87  std::string path = "";
88 
89  std::map<std::string, std::string>::const_iterator it = m_rinfo.find("URI");
90 
91  if(it != m_rinfo.end())
92  {
93  path = it->second;
94  }
95 
96  boost::filesystem::path rpath (path);
97 
98  ls = new te::da::DataSetType(rpath.filename().string());
99 
100  ls->add(rp);
101  }
102 
103  delete r;
104 
105  return std::auto_ptr<LayerSchema>(ls);
106 }
107 
108 std::auto_ptr<te::da::DataSet> te::map::RasterLayer::getData( te::common::TraverseType travType,
109  const te::common::AccessPolicy) const
110 {
111  return std::auto_ptr<te::da::DataSet>(0);
112 }
113 
114 std::auto_ptr<te::da::DataSet> te::map::RasterLayer::getData(const std::string& /*propertyName*/,
115  const te::gm::Envelope* /*e*/,
117  te::common::TraverseType /*travType*/,
118  const te::common::AccessPolicy) const
119 {
120  return std::auto_ptr<te::da::DataSet>(0);
121 }
122 
123 std::auto_ptr<te::da::DataSet> te::map::RasterLayer::getData(const std::string& /*propertyName*/,
124  const te::gm::Geometry* /*g*/,
126  te::common::TraverseType /*travType*/,
127  const te::common::AccessPolicy) const
128 {
129  return std::auto_ptr<te::da::DataSet>(0);
130 }
131 
132 std::auto_ptr<te::da::DataSet> te::map::RasterLayer::getData(te::da::Expression* /*restriction*/,
133  te::common::TraverseType /*travType*/,
134  const te::common::AccessPolicy) const
135 {
136  return std::auto_ptr<te::da::DataSet>(0);
137 }
138 
139 std::auto_ptr<te::da::DataSet> te::map::RasterLayer::getData(const te::da::ObjectIdSet* /*oids*/,
140  te::common::TraverseType /*travType*/,
141  const te::common::AccessPolicy) const
142 {
143  return std::auto_ptr<te::da::DataSet>(0);
144 }
145 
146 
148 {
149  return true;
150 }
151 
152 void te::map::RasterLayer::draw(Canvas* canvas, const te::gm::Envelope& bbox, int srid)
153 {
154  if(m_rendererType.empty())
155  throw Exception((boost::format(TE_TR("Could not draw the data set layer %1%. The renderer type is empty!")) % getTitle()).str());
156 
157  // Try get the defined renderer
158  std::auto_ptr<AbstractRenderer> renderer(RendererFactory::make(m_rendererType));
159  if(renderer.get() == 0)
160  throw Exception((boost::format(TE_TR("Could not draw the data set layer %1%. The renderer %2% could not be created!")) % getTitle() % m_rendererType).str());
161 
162  renderer->draw(this, canvas, bbox, srid);
163 }
164 
165 const std::string& te::map::RasterLayer::getType() const
166 {
167  return sm_type;
168 }
169 
170 const std::string& te::map::RasterLayer::getRendererType() const
171 {
172  return m_rendererType;
173 }
174 
175 void te::map::RasterLayer::setRendererType(const std::string& t)
176 {
177  m_rendererType = t;
178 }
179 
181 {
183 
184  return r;
185 }
186 
187 void te::map::RasterLayer::setRasterInfo(const std::map<std::string, std::string>& rinfo)
188 {
189  m_rinfo = rinfo;
190 
192 
193  if(r)
194  {
195  setSRID(r->getSRID());
196  setExtent(*r->getExtent());
197  }
198 
199  delete r;
200 }
201 
202 std::map<std::string, std::string> te::map::RasterLayer::getRasterInfo() const
203 {
204  return m_rinfo;
205 }
te::gm::Envelope * getExtent()
Returns the geographic extension of the raster data.
Definition: Raster.cpp:104
A layer with reference to a raster.
~RasterLayer()
Destructor.
Definition: RasterLayer.cpp:61
This is the base class for layers.
Definition: AbstractLayer.h:76
void setRasterInfo(const std::map< std::string, std::string > &rinfo)
A raster band description.
Definition: BandProperty.h:61
A class that models the description of a dataset.
Definition: DataSetType.h:72
virtual const Band * getBand(std::size_t i) const =0
Returns the raster i-th band.
An abstract factory for layer renderers.
te::rst::Raster * getRaster() const
SpatialRelation
Spatial relations between geometric objects.
Definition: Enums.h:122
std::map< std::string, std::string > getRasterInfo() const
#define TE_TR(message)
It marks a string in order to get translated.
Definition: Translator.h:347
Raster property.
RasterLayer(AbstractLayer *parent=0)
It initializes a new layer.
Definition: RasterLayer.cpp:44
This is an abstract class that models a query expression.
Definition: Expression.h:47
An exception class for the MapTools module.
AccessPolicy
Supported data access policies (can be used as bitfield).
Definition: Enums.h:40
TraverseType
A dataset can be traversed in two ways:
Definition: Enums.h:53
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
An abstract class for raster data strucutures.
Definition: Raster.h:71
bool isValid() const
It returns true if the layer can be used for instance to draw, otherwise, it returns false...
BandProperty * getProperty()
Returns the band property.
Definition: Band.cpp:428
virtual std::size_t getNumberOfBands() const =0
Returns the number of bands (dimension of cells attribute values) in the raster.
Grid * getGrid()
It returns the raster grid.
Definition: Raster.cpp:94
Geometry is the root class of the geometries hierarchy, it follows OGC and ISO standards.
Definition: Geometry.h:73
static AbstractRenderer * make(const std::string &factoryKey)
It creates an object with the appropriated factory.
void add(Constraint *c)
It adds a new constraint.
A canvas is an abstraction of a drawing area.
Definition: Canvas.h:91
int getSRID() const
Returns the raster spatial reference system identifier.
Definition: Raster.cpp:203
std::auto_ptr< LayerSchema > getSchema() const
It returns the layer schema.
Definition: RasterLayer.cpp:66
static const std::string sm_type
A static data member used in the implementation of getType method.
Definition: RasterLayer.h:160
const std::string & getType() const
It returns the layer type: RASTER_LAYER.
std::auto_ptr< te::da::DataSet > getData(te::common::TraverseType travType=te::common::FORWARDONLY, const te::common::AccessPolicy accessPolicy=te::common::RAccess) const
It gets the dataset identified by the layer name.
A rectified grid is the spatial support for raster data.
Definition: Grid.h:68
void setRendererType(const std::string &t)
void draw(Canvas *canvas, const te::gm::Envelope &bbox, int srid)
It draws the layer geographic objects in the given canvas using the informed SRS. ...
const std::string & getRendererType() const
static Raster * open(const std::map< std::string, std::string > &rinfo, te::common::AccessPolicy p=te::common::RAccess)
It opens a raster with the given parameters and default raster driver.