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  \note Accepted rinfo tags: FORCE_MEM_DRIVER="TRUE" - Force the creation of a memory raster, RTYPE="driver name" (use the specified raster driver name).
90  */
91  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);
92 
93  /*!
94  \brief It creates a raster with the given parameters using a proper driver.
95 
96  \param rType The name of the specific driver to create the raster.
97  \param g The raster grid. The factory will take its ownership.
98  \param bands A vector of band properties, one property for each band. The factory will take the ownership of all properties.
99  \param rinfo The necessary information to create the raster.
100  \param h It may be any specific value for a given driver.
101  \param deleter A pointer to a deleter function used to free the memory pointed by h.
102 
103  \return A new raster.
104 
105  \note The caller will take the ownership of the returned pointer.
106 
107  \note If you inform a deleter when the created raster is destroyed it will call it for the informed h pointer.
108  */
109  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);
110 
111  /*!
112  \brief It creates a raster with the given parameters using the default driver.
113 
114  \param rinfo The necessary information to create the raster.
115  \param h It may be any specific value for a given driver.
116  \param deleter A pointer to a deleter function used to free the memory pointed by h.
117 
118  \return A new raster.
119 
120  \note The caller will take the ownership of the returned pointer.
121 
122  \note If you inform a deleter when the created raster is destroyed it will call it for the informed h pointer.
123  */
124  static Raster* make(const std::map<std::string, std::string>& rinfo, void* h = 0, void (*deleter)(void*) = 0);
125 
126  /*!
127  \brief It creates a raster with the given parameters using a proper driver.
128 
129  \param rType The name of the specific driver to create the raster.
130  \param rinfo The necessary information to create the raster.
131  \param h It may be any specific value for a given driver.
132  \param deleter A pointer to a deleter function used to free the memory pointed by h.
133 
134  \return A new raster.
135 
136  \note The caller will take the ownership of the returned pointer.
137 
138  \note If you inform a deleter when the created raster is destroyed it will call it for the informed h pointer.
139  */
140  static Raster* make(const std::string& rType, const std::map<std::string, std::string>& rinfo, void* h, void (*deleter)(void*) = 0);
141 
142  /*!
143  \brief It opens a raster with the given parameters and default raster driver.
144 
145  \param rinfo The necessary information to open the raster.
146  \param p The access policy.
147 
148  \return The opened raster.
149 
150  \note The caller will take the ownership of the returned pointer.
151  */
152  static Raster* open(const std::map<std::string, std::string>& rinfo, te::common::AccessPolicy p = te::common::RAccess);
153 
154  /*!
155  \brief It creates a raster with the given parameters.
156 
157  \param rType The name of the specific driver to create the raster.
158  \param rinfo The necessary information to open the raster.
159  \param p The access policy.
160 
161  \return The opened raster.
162 
163  \note The caller will take the ownership of the returned pointer.
164  */
165  static Raster* open(const std::string& rType, const std::map<std::string, std::string>& rinfo, te::common::AccessPolicy p = te::common::RAccess);
166 
167  /*!
168  \brief It creates a raster with the given parameters and default raster driver.
169 
170  \param key The name of the key used to define raster location, ex.: "URI".
171  \param value The value of the key to define raster location, ex.: "/path/to/raster.tif".
172  \param p The access policy.
173 
174  \return The opened raster.
175 
176  \note The caller will take the ownership of the returned pointer.
177  */
178  static Raster* open(const std::string& key, const std::string& value, te::common::AccessPolicy p = te::common::RAccess);
179 
180  /*!
181  \brief It creates a raster with the given parameters.
182 
183  \param rType The name of the specific driver to create the raster.
184  \param key The name of the key used to define raster location, ex.: "URI".
185  \param value The value of the key to define raster location, ex.: "/path/to/raster.tif".
186  \param p The access policy.
187 
188  \return The opened raster.
189 
190  \note The caller will take the ownership of the returned pointer.
191  */
192  static Raster* open(const std::string& rType, const std::string& key, const std::string& value, te::common::AccessPolicy p = te::common::RAccess);
193 
194  /*! \brief Destructor. */
195  virtual ~RasterFactory() {}
196 
197  /*! \brief Returns the type (name) of this factory. */
198  virtual const std::string& getType() const = 0;
199 
200  /*! \brief It returns the list of parameters accepted as raster info. */
201  virtual void getCreationalParameters(std::vector< std::pair<std::string, std::string> >& params) const = 0;
202 
203  /*! \brief It returns a map<string, string> containing all supported formats. */
204  virtual std::map<std::string, std::string> getCapabilities() const = 0;
205 
206  protected:
207 
208  /*!
209  \brief Constructor.
210 
211  \param factorKey The key that identifies the factory.
212  */
213  RasterFactory(const std::string& factoryKey);
214 
215  /*!
216  \brief This method may be re-implemented by subclasses in order to have a finner control for the raster object instantiation.
217 
218  \param rinfo The necessary information to open the raster.
219  \param p The access policy.
220 
221  \return A raster.
222 
223  \note The caller will take the ownership of the returned pointer.
224  */
225  virtual Raster* iOpen(const std::map<std::string, std::string>& rinfo, te::common::AccessPolicy p = te::common::RAccess);
226 
227  /*!
228  \brief This method must be implemented by subclasses (raster drivers).
229 
230  \param g The raster grid. May be a NULL parameter. Implementations must take its ownership.
231  \param bands A vector of band properties, one for each band. Implementations must take ownership of the pointers in this vector.
232  \param rinfo The necessary information to create the raster.
233  \param h It may be any specific value for a given driver. May be a NULL parameter.
234  \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.
235 
236  \return The new raster.
237 
238  \note The caller will take the ownership of the returned pointer.
239  */
240  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;
241  };
242 
243  } // end namespace rst
244 } // end namespace te
245 
246 #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