RasterFactory.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/raster/RasterFactory.h
22 
23  \brief This is the abstract factory for Rasters.
24 */
25 
26 #ifndef __TERRALIB_RASTER_INTERNAL_RASTERFACTORY_H
27 #define __TERRALIB_RASTER_INTERNAL_RASTERFACTORY_H
28 
29 // TerraLib
30 #include "../common/AbstractFactory.h"
31 #include "Raster.h"
32 
33 namespace te
34 {
35  namespace rst
36  {
37 // Forward declaration
38  class BandProperty;
39  class Grid;
40 
41  /*!
42  \class RasterFactory
43 
44  \brief This is the abstract factory for Rasters.
45 
46  \ingroup rst
47 
48  \sa Raster
49  */
50  class TERASTEREXPORT RasterFactory : public te::common::AbstractFactory<Raster, std::string>
51  {
52  public:
53 
54  /*!
55  \brief It creates and returns an empty raster with default raster driver.
56 
57  \return An empty raster.
58 
59  \note The caller will take the ownership of the returned pointer.
60  */
61  static Raster* make();
62 
63  /*!
64  \brief It creates an empty raster with the proper driver.
65 
66  \param rType The name of the specific driver to be used to create the raster.
67 
68  \return An empty raster.
69 
70  \note The caller will take the ownership of the returned pointer.
71  */
72  static Raster* make(const std::string& rType);
73 
74  /*!
75  \brief It creates a raster with the given parameters using the default raster driver.
76 
77  \param g The raster grid. The factory will take its ownership.
78  \param bands A vector of band properties with one property for each band. The factory will take the ownership of all properties.
79  \param rinfo The necessary information to create the raster.
80  \param h It may be any specific value for a given driver.
81  \param deleter A pointer to a deleter function used to free the memory pointed by h.
82 
83  \return A new raster.
84 
85  \note The caller will take the ownership of the returned pointer.
86 
87  \note If you inform a deleter when the created raster is destroyed it will call it for the informed h pointer.
88  */
89  static Raster* make(Grid* g, const std::vector<BandProperty*> bands, const std::map<std::string, std::string>& rinfo, void* h = 0, void (*deleter)(void*) = 0);
90 
91  /*!
92  \brief It creates a raster with the given parameters using a proper driver.
93 
94  \param rType The name of the specific driver to create the raster.
95  \param g The raster grid. The factory will take its ownership.
96  \param bands A vector of band properties, one property for each band. The factory will take the ownership of all properties.
97  \param rinfo The necessary information to create the raster.
98  \param h It may be any specific value for a given driver.
99  \param deleter A pointer to a deleter function used to free the memory pointed by h.
100 
101  \return A new raster.
102 
103  \note The caller will take the ownership of the returned pointer.
104 
105  \note If you inform a deleter when the created raster is destroyed it will call it for the informed h pointer.
106  */
107  static Raster* make(const std::string& rType, Grid* g, const std::vector<BandProperty*> bands, const std::map<std::string, std::string>& rinfo, void* h = 0, void (*deleter)(void*) = 0);
108 
109  /*!
110  \brief It creates a raster with the given parameters using the default driver.
111 
112  \param rinfo The necessary information to create the raster.
113  \param h It may be any specific value for a given driver.
114  \param deleter A pointer to a deleter function used to free the memory pointed by h.
115 
116  \return A new raster.
117 
118  \note The caller will take the ownership of the returned pointer.
119 
120  \note If you inform a deleter when the created raster is destroyed it will call it for the informed h pointer.
121  */
122  static Raster* make(const std::map<std::string, std::string>& rinfo, void* h = 0, void (*deleter)(void*) = 0);
123 
124  /*!
125  \brief It creates a raster with the given parameters using a proper driver.
126 
127  \param rType The name of the specific driver to create the raster.
128  \param rinfo The necessary information to create the raster.
129  \param h It may be any specific value for a given driver.
130  \param deleter A pointer to a deleter function used to free the memory pointed by h.
131 
132  \return A new raster.
133 
134  \note The caller will take the ownership of the returned pointer.
135 
136  \note If you inform a deleter when the created raster is destroyed it will call it for the informed h pointer.
137  */
138  static Raster* make(const std::string& rType, const std::map<std::string, std::string>& rinfo, void* h, void (*deleter)(void*) = 0);
139 
140  /*!
141  \brief It opens a raster with the given parameters and default raster driver.
142 
143  \param rinfo The necessary information to open the raster.
144  \param p The access policy.
145 
146  \return The opened raster.
147 
148  \note The caller will take the ownership of the returned pointer.
149  */
150  static Raster* open(const std::map<std::string, std::string>& rinfo, te::common::AccessPolicy p = te::common::RAccess);
151 
152  /*!
153  \brief It creates a raster with the given parameters.
154 
155  \param rType The name of the specific driver to create the raster.
156  \param rinfo The necessary information to open the raster.
157  \param p The access policy.
158 
159  \return The opened raster.
160 
161  \note The caller will take the ownership of the returned pointer.
162  */
163  static Raster* open(const std::string& rType, const std::map<std::string, std::string>& rinfo, te::common::AccessPolicy p = te::common::RAccess);
164 
165  /*!
166  \brief It creates a raster with the given parameters and default raster driver.
167 
168  \param key The name of the key used to define raster location, ex.: "URI".
169  \param value The value of the key to define raster location, ex.: "/path/to/raster.tif".
170  \param p The access policy.
171 
172  \return The opened raster.
173 
174  \note The caller will take the ownership of the returned pointer.
175  */
176  static Raster* open(const std::string& key, const std::string& value, te::common::AccessPolicy p = te::common::RAccess);
177 
178  /*!
179  \brief It creates a raster with the given parameters.
180 
181  \param rType The name of the specific driver to create the raster.
182  \param key The name of the key used to define raster location, ex.: "URI".
183  \param value The value of the key to define raster location, ex.: "/path/to/raster.tif".
184  \param p The access policy.
185 
186  \return The opened raster.
187 
188  \note The caller will take the ownership of the returned pointer.
189  */
190  static Raster* open(const std::string& rType, const std::string& key, const std::string& value, te::common::AccessPolicy p = te::common::RAccess);
191 
192  /*! \brief Destructor. */
193  virtual ~RasterFactory() {}
194 
195  /*! \brief Returns the type (name) of this factory. */
196  virtual const std::string& getType() const = 0;
197 
198  /*! \brief It returns the list of parameters accepted as raster info. */
199  virtual void getCreationalParameters(std::vector< std::pair<std::string, std::string> >& params) const = 0;
200 
201  /*! \brief It returns a map<string, string> containing all supported formats. */
202  virtual std::map<std::string, std::string> getCapabilities() const = 0;
203 
204  protected:
205 
206  /*!
207  \brief Constructor.
208 
209  \param factorKey The key that identifies the factory.
210  */
211  RasterFactory(const std::string& factoryKey);
212 
213  /*!
214  \brief This method may be re-implemented by subclasses in order to have a finner control for the raster object instantiation.
215 
216  \param rinfo The necessary information to open the raster.
217  \param p The access policy.
218 
219  \return A raster.
220 
221  \note The caller will take the ownership of the returned pointer.
222  */
223  virtual Raster* iOpen(const std::map<std::string, std::string>& rinfo, te::common::AccessPolicy p = te::common::RAccess);
224 
225  /*!
226  \brief This method must be implemented by subclasses (raster drivers).
227 
228  \param g The raster grid. May be a NULL parameter. Implementations must take its ownership.
229  \param bands A vector of band properties, one for each band. Implementations must take ownership of the pointers in this vector.
230  \param rinfo The necessary information to create the raster.
231  \param h It may be any specific value for a given driver. May be a NULL parameter.
232  \param deleter A pointer to a deleter function used to free the memory pointed by h. May be a NULL parameter. Implementations must use this method when it doesn't use 'h' anymore.
233 
234  \return The new raster.
235 
236  \note The caller will take the ownership of the returned pointer.
237  */
238  virtual Raster* create(Grid* g, const std::vector<BandProperty*> bands, const std::map<std::string, std::string>& rinfo, void* h = 0, void (*deleter)(void*) = 0) = 0;
239  };
240 
241  } // end namespace rst
242 } // end namespace te
243 
244 #endif // __TERRALIB_RASTER_INTERNAL_RASTERFACTORY_H
This class defines the interface of abstract factories without initializing parameters.
#define TERASTEREXPORT
You can use this macro in order to export/import classes and functions from this module.
Definition: Config.h:62
AccessPolicy
Supported data access policies (can be used as bitfield).
Definition: Enums.h:40
An abstract class for raster data strucutures.
An abstract class for raster data strucutures.
Definition: Raster.h:71
URI C++ Library.
virtual ~RasterFactory()
Destructor.
This is the abstract factory for Rasters.
Definition: RasterFactory.h:50
A rectified grid is the spatial support for raster data.
Definition: Grid.h:68