All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
ProxyRaster.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/raster/ProxyRaster.cpp
22 
23  \brief A proxy class for bands of several rasters over the same region.
24 */
25 
26 // TerraLib
27 #include "../common/Translator.h"
28 #include "Band.h"
29 #include "BandProperty.h"
30 #include "Exception.h"
31 #include "Grid.h"
32 #include "ProxyRaster.h"
33 
34 // STL
35 #include <cassert>
36 #include <utility>
37 
38 te::rst::ProxyRaster::ProxyRaster(const std::vector<RasterPtr>& rasters)
39  : m_rasters(rasters)
40 {
41 // TODO: check if all rasters have the same grid!
42  assert(rasters.empty() == false);
43 
44  const std::size_t nrasters = rasters.size();
45 
46  for(std::size_t i = 0; i != nrasters; ++i)
47  {
48  RasterPtr r(rasters[i]);
49 
50  const std::size_t nbands = r->getNumberOfBands();
51 
52  for(std::size_t b = 0; b != nbands; ++b)
53  {
54  m_bands.push_back(r->getBand(b));
55  }
56  }
57 
58  assert(m_grid == 0);
59 
60  m_grid = new Grid(*(rasters[0]->getGrid()));
61 }
62 
64 {
65  throw Exception(TE_TR("Not implemented yet!"));
66 }
67 
69 {
70 }
71 
72 void te::rst::ProxyRaster::swap(std::size_t first, std::size_t second)
73 {
74  std::swap(m_bands[first], m_bands[second]);
75  std::swap(m_rasters[first], m_rasters[second]);
76 }
77 
78 void te::rst::ProxyRaster::open(const std::map<std::string, std::string>& /*rinfo*/, te::common::AccessPolicy /*p*/)
79 {
80 }
81 
82 std::map<std::string, std::string> te::rst::ProxyRaster::getInfo() const
83 {
84  return m_rinfo;
85 }
86 
88 {
89  return m_bands.size();
90 }
91 
92 int te::rst::ProxyRaster::getBandDataType(std::size_t i) const
93 {
94  assert(i < m_bands.size());
95  assert(m_bands[i]);
96  assert(m_bands[i]->getProperty());
97 
98  return m_bands[i]->getProperty()->getType();
99 }
100 
101 const te::rst::Band* te::rst::ProxyRaster::getBand(std::size_t i) const
102 {
103  assert(i < m_bands.size());
104 
105  return m_bands[i];
106 }
107 
109 {
110  assert(i < m_bands.size());
111 
112  return m_bands[i];
113 }
114 
116 {
117  assert(i < m_bands.size());
118  assert(m_bands[i]);
119 
120  return *(m_bands[i]);
121 }
122 
124 {
125  assert(i < m_bands.size());
126  assert(m_bands[i]);
127 
128  return *(m_bands[i]);
129 }
130 
It describes one band (or dimension) of a raster.
void open(const std::map< std::string, std::string > &rinfo, te::common::AccessPolicy p=te::common::RAccess)
Opens a raster.
Definition: ProxyRaster.cpp:78
A proxy class for bands of several rasters over the same region.
std::size_t getNumberOfBands() const
Returns the number of bands (dimension of cells attribute values) in the raster.
Definition: ProxyRaster.cpp:87
#define TE_TR(message)
It marks a string in order to get translated.
Definition: Translator.h:347
const Band & operator[](std::size_t i) const
Access band in i position.
Grid * m_grid
The spatial support for raster data.
Definition: Raster.h:681
AccessPolicy
Supported data access policies (can be used as bitfield).
Definition: Enums.h:40
boost::shared_ptr< Raster > RasterPtr
Definition: Raster.h:685
An exception class for the Raster module.
void swap(std::size_t first, std::size_t second)
Definition: ProxyRaster.cpp:72
int getBandDataType(std::size_t i) const
Returns the data type in a particular band (or dimension).
Definition: ProxyRaster.cpp:92
std::vector< Band * > m_bands
The proxy raster bands.
Definition: ProxyRaster.h:110
~ProxyRaster()
Destructor.
Definition: ProxyRaster.cpp:68
const Band * getBand(std::size_t i) const
Returns the raster i-th band.
It gives access to values in one band (dimension) of a raster.
A raster band description.
Definition: Band.h:63
Grid * getGrid()
It returns the raster grid.
Definition: Raster.cpp:94
A proxy class for bands of several rasters over the same region.
Definition: ProxyRaster.h:43
std::map< std::string, std::string > getInfo() const
It returns additional information about the raster.
Definition: ProxyRaster.cpp:82
A rectified grid is the spatial support for raster data.
ProxyRaster(const std::vector< RasterPtr > &rasters)
Constructor from a set of rasters.
Definition: ProxyRaster.cpp:38