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 "../core/translator/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 == nullptr);
59 
60  m_grid = new Grid(*(rasters[0]->getGrid()));
61 }
62 
64 {
65  throw Exception(TE_TR("Not implemented yet!"));
66 }
67 
69 
70 void te::rst::ProxyRaster::swap(std::size_t first, std::size_t second)
71 {
72  std::swap(m_bands[first], m_bands[second]);
73  std::swap(m_rasters[first], m_rasters[second]);
74 }
75 
76 void te::rst::ProxyRaster::open(const std::map<std::string, std::string>& /*rinfo*/, te::common::AccessPolicy /*p*/)
77 {
78 }
79 
80 std::map<std::string, std::string> te::rst::ProxyRaster::getInfo() const
81 {
82  return m_rinfo;
83 }
84 
86 {
87  return m_bands.size();
88 }
89 
90 int te::rst::ProxyRaster::getBandDataType(std::size_t i) const
91 {
92  assert(i < m_bands.size());
93  assert(m_bands[i]);
94  assert(m_bands[i]->getProperty());
95 
96  return m_bands[i]->getProperty()->getType();
97 }
98 
99 const te::rst::Band* te::rst::ProxyRaster::getBand(std::size_t i) const
100 {
101  assert(i < m_bands.size());
102 
103  return m_bands[i];
104 }
105 
107 {
108  assert(i < m_bands.size());
109 
110  return m_bands[i];
111 }
112 
114 {
115  assert(i < m_bands.size());
116  assert(m_bands[i]);
117 
118  return *(m_bands[i]);
119 }
120 
122 {
123  assert(i < m_bands.size());
124  assert(m_bands[i]);
125 
126  return *(m_bands[i]);
127 }
128 
An exception class for the Raster module.
It gives access to values in one band (dimension) of a raster.
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:76
Base exception class for plugin module.
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:85
#define TE_TR(message)
It marks a string in order to get translated.
Definition: Translator.h:242
std::map< std::string, std::string > m_rinfo
Proxy raster additional information.
Definition: ProxyRaster.h:111
const Band & operator[](std::size_t i) const
Access band in i position.
std::vector< RasterPtr > m_rasters
The list of proxed rasters.
Definition: ProxyRaster.h:109
Grid * m_grid
The spatial support for raster data.
AccessPolicy
Supported data access policies (can be used as bitfield).
boost::shared_ptr< Raster > RasterPtr
int b
Definition: TsRtree.cpp:32
void swap(std::size_t first, std::size_t second)
Definition: ProxyRaster.cpp:70
int getBandDataType(std::size_t i) const
Returns the data type in a particular band (or dimension).
Definition: ProxyRaster.cpp:90
std::vector< Band * > m_bands
The proxy raster bands.
Definition: ProxyRaster.h:110
~ProxyRaster()
Destructor.
const Band * getBand(std::size_t i) const
Returns the raster i-th band.
Definition: ProxyRaster.cpp:99
A raster band description.
Grid * getGrid()
It returns the raster grid.
A proxy class for bands of several rasters over the same region.
Definition: ProxyRaster.h:43
A rectified grid is the spatial support for raster data.
std::map< std::string, std::string > getInfo() const
It returns additional information about the raster.
Definition: ProxyRaster.cpp:80
list rasters
Definition: compose.py:3
ProxyRaster(const std::vector< RasterPtr > &rasters)
Constructor from a set of rasters.
Definition: ProxyRaster.cpp:38