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 a proper driver.
113 
114  \param rType The name of the specific driver to create the raster.
115  \param g The raster grid. The factory will take its ownership.
116  \param bands A vector of band properties, one property for each band. The factory will take the ownership of all properties.
117  \param rinfo The necessary information to create the raster.
118  \param metadata Raster metadadata in a form [metadata name, value].
119  \param h It may be any specific value for a given driver.
120  \param deleter A pointer to a deleter function used to free the memory pointed by h.
121 
122  \return A new raster.
123 
124  \note The caller will take the ownership of the returned pointer.
125 
126  \note If you inform a deleter when the created raster is destroyed it will call it for the informed h pointer.
127  */
128  static Raster* make(const std::string& rType, Grid* g,
129  const std::vector<BandProperty*> bands,
130  const std::map<std::string, std::string>& rinfo,
131  const std::map<std::string, std::string>& metadata,
132  void* h = 0, void (*deleter)(void*) = 0);
133 
134  /*!
135  \brief It creates a raster with the given parameters using the default driver.
136 
137  \param rinfo The necessary information to create the raster.
138  \param h It may be any specific value for a given driver.
139  \param deleter A pointer to a deleter function used to free the memory pointed by h.
140 
141  \return A new raster.
142 
143  \note The caller will take the ownership of the returned pointer.
144 
145  \note If you inform a deleter when the created raster is destroyed it will call it for the informed h pointer.
146  */
147  static Raster* make(const std::map<std::string, std::string>& rinfo, void* h = 0, void (*deleter)(void*) = 0);
148 
149  /*!
150  \brief It creates a raster with the given parameters using a proper driver.
151 
152  \param rType The name of the specific driver to create the raster.
153  \param rinfo The necessary information to create the raster.
154  \param h It may be any specific value for a given driver.
155  \param deleter A pointer to a deleter function used to free the memory pointed by h.
156 
157  \return A new raster.
158 
159  \note The caller will take the ownership of the returned pointer.
160 
161  \note If you inform a deleter when the created raster is destroyed it will call it for the informed h pointer.
162  */
163  static Raster* make(const std::string& rType, const std::map<std::string, std::string>& rinfo, void* h, void (*deleter)(void*) = 0);
164 
165  /*!
166  \brief It opens a raster with the given parameters and default raster driver.
167 
168  \param rinfo The necessary information to open the raster.
169  \param p The access policy.
170 
171  \return The opened raster.
172 
173  \note The caller will take the ownership of the returned pointer.
174  */
175  static Raster* open(const std::map<std::string, std::string>& rinfo, te::common::AccessPolicy p = te::common::RAccess);
176 
177  /*!
178  \brief It creates a raster with the given parameters.
179 
180  \param rType The name of the specific driver to create the raster.
181  \param rinfo The necessary information to open the raster.
182  \param p The access policy.
183 
184  \return The opened raster.
185 
186  \note The caller will take the ownership of the returned pointer.
187  */
188  static Raster* open(const std::string& rType, const std::map<std::string, std::string>& rinfo, te::common::AccessPolicy p = te::common::RAccess);
189 
190  /*!
191  \brief It creates a raster with the given parameters and default raster driver.
192 
193  \param key The name of the key used to define raster location, ex.: "URI".
194  \param value The value of the key to define raster location, ex.: "/path/to/raster.tif".
195  \param p The access policy.
196 
197  \return The opened raster.
198 
199  \note The caller will take the ownership of the returned pointer.
200  */
201  static Raster* open(const std::string& key, const std::string& value, te::common::AccessPolicy p = te::common::RAccess);
202 
203  /*!
204  \brief It creates a raster with the given parameters.
205 
206  \param rType The name of the specific driver to create the raster.
207  \param key The name of the key used to define raster location, ex.: "URI".
208  \param value The value of the key to define raster location, ex.: "/path/to/raster.tif".
209  \param p The access policy.
210 
211  \return The opened raster.
212 
213  \note The caller will take the ownership of the returned pointer.
214  */
215  static Raster* open(const std::string& rType, const std::string& key, const std::string& value, te::common::AccessPolicy p = te::common::RAccess);
216 
217  /*! \brief Destructor. */
218  virtual ~RasterFactory() {}
219 
220  /*! \brief Returns the type (name) of this factory. */
221  virtual const std::string& getType() const = 0;
222 
223  /*! \brief It returns the list of parameters accepted as raster info. */
224  virtual void getCreationalParameters(std::vector< std::pair<std::string, std::string> >& params) const = 0;
225 
226  /*! \brief It returns a map<string, string> containing all supported formats. */
227  virtual std::map<std::string, std::string> getCapabilities() const = 0;
228 
229  protected:
230 
231  /*!
232  \brief Constructor.
233 
234  \param factorKey The key that identifies the factory.
235  */
236  RasterFactory(const std::string& factoryKey);
237 
238  /*!
239  \brief This method may be re-implemented by subclasses in order to have a finner control for the raster object instantiation.
240 
241  \param rinfo The necessary information to open the raster.
242  \param p The access policy.
243 
244  \return A raster.
245 
246  \note The caller will take the ownership of the returned pointer.
247  */
248  virtual Raster* iOpen(const std::map<std::string, std::string>& rinfo, te::common::AccessPolicy p = te::common::RAccess);
249 
250  /*!
251  \brief This method must be implemented by subclasses (raster drivers).
252 
253  \param g The raster grid. May be a NULL parameter. Implementations must take its ownership.
254  \param bands A vector of band properties, one for each band. Implementations must take ownership of the pointers in this vector.
255  \param rinfo The necessary information to create the raster.
256  \param metadata Raster metadata in a form [metadada name, metadata value].
257  \param h It may be any specific value for a given driver. May be a NULL parameter.
258  \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.
259 
260  \return The new raster.
261 
262  \note The caller will take the ownership of the returned pointer.
263  */
264  virtual Raster* create(Grid* g, const std::vector<BandProperty*> bands,
265  const std::map<std::string, std::string>& rinfo,
266  const std::map<std::string, std::string>& metadata,
267  void* h = 0, void (*deleter)(void*) = 0) = 0;
268  };
269 
270  } // end namespace rst
271 } // end namespace te
272 
273 #endif // __TERRALIB_RASTER_INTERNAL_RASTERFACTORY_H
This class defines the interface of abstract factories without initializing parameters.
A rectified grid is the spatial support for raster data.
Definition: Grid.h:69
This is the abstract factory for Rasters.
Definition: RasterFactory.h:51
virtual void getCreationalParameters(std::vector< std::pair< std::string, std::string > > &params) const =0
It returns the list of parameters accepted as raster info.
virtual std::map< std::string, std::string > getCapabilities() const =0
It returns a map<string, string> containing all supported formats.
static Raster * make(const std::map< std::string, std::string > &rinfo, void *h=0, void(*deleter)(void *)=0)
It creates a raster with the given parameters using the default driver.
static Raster * make(const std::string &rType, Grid *g, const std::vector< BandProperty * > bands, const std::map< std::string, std::string > &rinfo, const std::map< std::string, std::string > &metadata, void *h=0, void(*deleter)(void *)=0)
It creates a raster with the given parameters using a proper driver.
RasterFactory(const std::string &factoryKey)
Constructor.
static Raster * make()
It creates and returns an empty raster with default raster driver.
static Raster * open(const std::string &key, const std::string &value, te::common::AccessPolicy p=te::common::RAccess)
It creates a raster with the given parameters and default raster driver.
static Raster * make(const std::string &rType, const std::map< std::string, std::string > &rinfo, void *h, void(*deleter)(void *)=0)
It creates a raster with the given parameters using a proper driver.
virtual ~RasterFactory()
Destructor.
static Raster * make(const std::string &rType)
It creates an empty raster with the proper driver.
virtual const std::string & getType() const =0
Returns the type (name) of this factory.
static Raster * open(const std::string &rType, const std::map< std::string, std::string > &rinfo, te::common::AccessPolicy p=te::common::RAccess)
It creates a raster with the given parameters.
virtual Raster * create(Grid *g, const std::vector< BandProperty * > bands, const std::map< std::string, std::string > &rinfo, const std::map< std::string, std::string > &metadata, void *h=0, void(*deleter)(void *)=0)=0
This method must be implemented by subclasses (raster drivers).
static Raster * open(const std::map< std::string, std::string > &rinfo, te::common::AccessPolicy p=te::common::RAccess)
It opens a raster with the given parameters and default raster driver.
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)
It creates a raster with the given parameters using a proper driver.
virtual Raster * iOpen(const std::map< std::string, std::string > &rinfo, te::common::AccessPolicy p=te::common::RAccess)
This method may be re-implemented by subclasses in order to have a finner control for the raster obje...
static Raster * open(const std::string &rType, const std::string &key, const std::string &value, te::common::AccessPolicy p=te::common::RAccess)
It creates a raster with the given parameters.
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)
It creates a raster with the given parameters using the default raster driver.
An abstract class for raster data strucutures.
Definition: Raster.h:72
AccessPolicy
Supported data access policies (can be used as bitfield).
Definition: Enums.h:41
@ RAccess
Definition: Enums.h:43
@ Grid
Definition: Enums.h:106
TerraLib.
Raster implementaton for TerraLib 4.x.
#define TERASTEREXPORT
You can use this macro in order to export/import classes and functions from this module.
Definition: Config.h:63