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