Raster.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/gdal/Raster.h
22 
23  \brief This is a class that represents a GDAL Raster.
24  */
25 
26 #ifndef __TERRALIB_GDAL_INTERNAL_RASTER_H
27 #define __TERRALIB_GDAL_INTERNAL_RASTER_H
28 
29 //TerraLib
30 #include "../raster/Raster.h"
31 #include "Band.h"
32 #include "Config.h"
33 #include "DataSetUseCounter.h"
34 
35 #include <string>
36 #include <memory>
37 
38 #include <gdal_priv.h>
39 
40 // Forward declaration
41 class GDALDataset;
42 class GDALRasterBand;
43 
44 namespace te
45 {
46  namespace gdal
47  {
48  // Forward declaration
49  class Band;
50 
51  /*!
52  \class Raster
53 
54  \brief This class represents Raster data.
55 
56  This class is a concrete implementation of a Raster using the GDAL library to access
57  the data.
58 
59  \sa te::rst::Raster
60  */
62  {
63  public:
64 
66 
67  Raster();
68 
69  /*!
70  \brief Constructor.
71 
72  \param rinfo The information needed to open the raster.
73  \param p Access Policy.
74  */
75  Raster(const std::string& rinfo, te::common::AccessPolicy p = te::common::RAccess);
76 
77  /*!
78  \brief Constructor.
79 
80  \param grid The grid definition. The Raster will take its ownership.
81  \param bprops A vector of band properties, one for each band. The Raster will take its ownership.
82  \param optparams Extra information to create the raster. See GDAL documentation for more information.
83  Parameters include NBANDS, BANDSTYPE, NCOLS, NROWS, RESX, RESY, SRID, ULX, ULY.
84  \param p Access Policy.
85  */
86  Raster(te::rst::Grid* grid, const std::vector<te::rst::BandProperty*>& bprops, const std::map<std::string, std::string>& optParams, te::common::AccessPolicy p = te::common::RAccess);
87 
88  /*!
89  \brief Constructor.
90 
91  \param gdataset A GDAL dataset handler.
92  \param p Access Policy.
93  */
94  //Raster(GDALDataset* gdataset, te::common::AccessPolicy p = te::common::RAccess);
95 
96  Raster(const Raster& rhs);
97 
98  ~Raster();
99 
100  void open(const std::map<std::string, std::string>& rinfo, te::common::AccessPolicy p = te::common::RAccess);
101 
102  std::map<std::string, std::string> getInfo() const;
103 
104  std::size_t getNumberOfBands() const;
105 
106  int getBandDataType(std::size_t i) const;
107 
108  const te::rst::Band* getBand(std::size_t i) const;
109 
110  te::rst::Band* getBand(std::size_t i);
111 
112  const te::rst::Band& operator[](std::size_t i) const;
113 
114  te::rst::Band& operator[](std::size_t i);
115 
116  /*! \brief Returns the raster GDAL handler. */
117  GDALDataset* getGDALDataset() const;
118 
119  te::dt::AbstractData* clone() const;
120 
121  Raster& operator=(const Raster& rhs);
122 
123  te::rst::Raster* resample(int method, int scale, const std::map<std::string, std::string>& rinfo) const;
124 
125  /*!
126  \note When the parameter USE_TERRALIB_REPROJECTION = TRUE in rinfo, the default reprojection will be called.
127  Otherwise this method will call the GDAL reprojection method. The rinfo must define a GDAL compatible raster.
128  The parameter m (interpolation method) is not used in GDAL implementation.
129  */
130  te::rst::Raster* transform(int srid, double llx, double lly, double urx, double ury, double resx, double resy, const std::map<std::string, std::string>& rinfo, int m = 0) const;
131 
132  void transform(te::rst::Raster* outRaster);
133 
134  /*!
135  \note GDAL driver extended method.
136  */
137  void create(te::rst::Grid* g,
138  const std::vector<te::rst::BandProperty*> bands,
139  const std::map<std::string, std::string>& rinfo,
140  void* h, void (*deleter)(void*));
141 
142  bool createMultiResolution( const unsigned int levels, const te::rst::InterpolationMethod interpMethod );
143 
144  bool removeMultiResolution();
145 
146  unsigned int getMultiResLevelsCount() const;
147 
148  te::rst::Raster* getMultiResLevel( const unsigned int level ) const;
149 
150  protected :
151 
152  /*!
153  \brief Constructor.
154 
155  \param multiResolutionLevel Level of a multi-resolution pyramid.
156  \param uRI The raster URI.
157  \param policy The raster access policy.
158  */
159  Raster( const unsigned int multiResolutionLevel, const std::string& uRI,
160  const te::common::AccessPolicy& policy );
161 
162  private:
163 
164  GDALDataset* m_gdataset; //!< Gdal data set handler.
165  std::vector<Band*> m_bands; //!< The vector of available bands in the raster.
166  void (*m_deleter)(void*); //!< A pointer to a deleter function, if the buffer needs to be deleted by this object.
167  std::string m_myURI; //!< This instance URI;
168  std::auto_ptr<DataSetUseCounter> m_dsUseCounterPtr; //!< Dataset use counter pointer.
169  };
170  } // end namespace gdal
171 } // end namespace te
172 
173 #endif // __TERRALIB_GDAL_INTERNAL_RASTER_H
This class represents Raster data.
Definition: Raster.h:61
It gives access to values in one band (dimension) of a raster.
#define TEGDALEXPORT
You can use this macro in order to export/import classes and functions from this module.
Definition: Config.h:67
InterpolationMethod
Allowed interpolation methods.
Definition: Enums.h:92
GDALDataset * m_gdataset
Gdal data set handler.
Definition: Raster.h:164
AccessPolicy
Supported data access policies (can be used as bitfield).
Definition: Enums.h:40
std::auto_ptr< DataSetUseCounter > m_dsUseCounterPtr
Dataset use counter pointer.
Definition: Raster.h:168
An abstract class for raster data strucutures.
Definition: Raster.h:71
URI C++ Library.
std::string m_myURI
This instance URI;.
Definition: Raster.h:167
A base class for values that can be retrieved from the data access module.
Definition: AbstractData.h:57
A raster band description.
Definition: Band.h:63
virtual Raster * transform(int srid, const std::map< std::string, std::string > &rinfo, int m=1) const
Reprojects this raster to a distinct SRS. This method reprojects this raster to a distinct SRS...
std::vector< Band * > m_bands
The vector of available bands in the raster.
Definition: Raster.h:165
A rectified grid is the spatial support for raster data.
Definition: Grid.h:68
Configuration flags for the GDAL Driver of TerraLib.