All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
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 
65  Raster();
66 
67  /*!
68  \brief Constructor.
69 
70  \param rinfo The information needed to open the raster.
71  \param p Access Policy.
72  */
73  Raster(const std::string& rinfo, te::common::AccessPolicy p = te::common::RAccess);
74 
75  /*!
76  \brief Constructor.
77 
78  \param grid The grid definition. The Raster will take its ownership.
79  \param bprops A vector of band properties, one for each band. The Raster will take its ownership.
80  \param optparams Extra information to create the raster. See GDAL documentation for more information.
81  Parameters include NBANDS, BANDSTYPE, NCOLS, NROWS, RESX, RESY, SRID, ULX, ULY.
82  \param p Access Policy.
83  */
84  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);
85 
86  /*!
87  \brief Constructor.
88 
89  \param gdataset A GDAL dataset handler.
90  \param p Access Policy.
91  */
92  //Raster(GDALDataset* gdataset, te::common::AccessPolicy p = te::common::RAccess);
93 
94  Raster(const Raster& rhs);
95 
96  ~Raster();
97 
98  void open(const std::map<std::string, std::string>& rinfo, te::common::AccessPolicy p = te::common::RAccess);
99 
100  std::map<std::string, std::string> getInfo() const;
101 
102  std::size_t getNumberOfBands() const;
103 
104  int getBandDataType(std::size_t i) const;
105 
106  const te::rst::Band* getBand(std::size_t i) const;
107 
108  te::rst::Band* getBand(std::size_t i);
109 
110  const te::rst::Band& operator[](std::size_t i) const;
111 
112  te::rst::Band& operator[](std::size_t i);
113 
114  /*! \brief Returns the raster GDAL handler. */
115  GDALDataset* getGDALDataset() const;
116 
117  te::dt::AbstractData* clone() const;
118 
119  Raster& operator=(const Raster& rhs);
120 
121  te::rst::Raster* resample(int method, int scale, const std::map<std::string, std::string>& rinfo) const;
122 
123  /*!
124  \note When the parameter USE_TERRALIB_REPROJECTION = TRUE in rinfo, the default reprojection will be called.
125  Otherwise this method will call the GDAL reprojection method. The rinfo must define a GDAL compatible raster.
126  The parameter m (interpolation method) is not used in GDAL implementation.
127  */
128  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;
129 
130  void transform(te::rst::Raster* outRaster);
131 
132  /*!
133  \note GDAL driver extended method.
134  */
135  void create(te::rst::Grid* g,
136  const std::vector<te::rst::BandProperty*> bands,
137  const std::map<std::string, std::string>& rinfo,
138  void* h, void (*deleter)(void*));
139 
140  bool createMultiResolution( const unsigned int levels, const te::rst::InterpolationMethod interpMethod );
141 
142  bool removeMultiResolution();
143 
144  unsigned int getMultiResLevelsCount() const;
145 
146  te::rst::Raster* getMultiResLevel( const unsigned int level ) const;
147 
148  protected :
149 
150  /*!
151  \brief Constructor.
152 
153  \param multiResolutionLevel Level of a multi-resolution pyramid.
154  \param uRI The raster URI.
155  \param policy The raster access policy.
156  */
157  Raster( const unsigned int multiResolutionLevel, const std::string& uRI,
158  const te::common::AccessPolicy& policy );
159 
160  private:
161 
162  GDALDataset* m_gdataset; //!< Gdal data set handler.
163  std::vector<Band*> m_bands; //!< The vector of available bands in the raster.
164  void (*m_deleter)(void*); //!< A pointer to a deleter function, if the buffer needs to be deleted by this object.
165  std::string m_myURI; //!< This instance URI;
166  std::auto_ptr<DataSetUseCounter> m_dsUseCounterPtr; //!< Dataset use counter pointer.
167  };
168  } // end namespace gdal
169 } // end namespace te
170 
171 #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:69
InterpolationMethod
Allowed interpolation methods.
Definition: Enums.h:92
GDALDataset * m_gdataset
Gdal data set handler.
Definition: Raster.h:162
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:166
An abstract class for raster data strucutures.
Definition: Raster.h:71
std::string m_myURI
This instance URI;.
Definition: Raster.h:165
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
std::vector< Band * > m_bands
The vector of available bands in the raster.
Definition: Raster.h:163
A rectified grid is the spatial support for raster data.
Definition: Grid.h:68
Configuration flags for the GDAL Driver of TerraLib.