All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
RasterFactory.cpp
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.cpp
22 
23  \brief This is the abstract factory for Rasters.
24 */
25 
26 // TerraLib
27 #include "../common/StringUtils.h"
28 #include "../common/Translator.h"
29 #include "Exception.h"
30 #include "RasterFactory.h"
31 
32 // STL
33 #include <memory>
34 
36 {
38 }
39 
41 {
42  std::string ucase = te::common::Convert2UCase(rType);
43 
45 }
46 
47 te::rst::Raster* te::rst::RasterFactory::make(Grid* g, const std::vector<BandProperty*> bands, const std::map<std::string, std::string>& rinfo, void* h, void (*deleter)(void*))
48 {
49  std::map<std::string, std::string>::const_iterator it = rinfo.find("FORCE_MEM_DRIVER");
50 
51  if((it != rinfo.end()) &&
52  (te::common::Convert2UCase(it->second) == "TRUE"))
53  return make("MEM", g, bands, rinfo, h, deleter);
54 
55  return make(TE_DEFAULT_RASTER_TYPE, g, bands, rinfo, h, deleter);
56 }
57 
58 te::rst::Raster* te::rst::RasterFactory::make(const std::string& rType, Grid* g, const std::vector<BandProperty*> bands, const std::map<std::string, std::string>& rinfo, void* h, void (*deleter)(void*))
59 {
60  std::string ucase = te::common::Convert2UCase(rType);
61 
63 
64  RasterFactory* f = static_cast<RasterFactory*>(d.find(ucase));
65 
66  if(f == 0)
67  throw Exception(TE_TR("Could not find concrete factory! Check if it was initialized!"));
68 
69  Raster* r = f->create(g, bands, rinfo, h, deleter);
70 
71  return r;
72 }
73 
74 te::rst::Raster* te::rst::RasterFactory::make(const std::map<std::string, std::string>& rinfo, void* h, void (*deleter)(void*))
75 {
76  return make(TE_DEFAULT_RASTER_TYPE, 0, std::vector<BandProperty*>(), rinfo, h, deleter);
77 }
78 
79 te::rst::Raster* te::rst::RasterFactory::make(const std::string& rType, const std::map<std::string, std::string>& rinfo, void* h, void (*deleter)(void*))
80 {
81  return make(rType, 0, std::vector<BandProperty*>(), rinfo, h, deleter);
82 }
83 
84 te::rst::Raster* te::rst::RasterFactory::open(const std::map<std::string, std::string>& rinfo, te::common::AccessPolicy p)
85 {
86  return open(TE_DEFAULT_RASTER_TYPE, rinfo, p);
87 }
88 
89 te::rst::Raster* te::rst::RasterFactory::open(const std::string& rType, const std::map<std::string, std::string>& rinfo, te::common::AccessPolicy p)
90 {
91  std::string ucase = te::common::Convert2UCase(rType);
92 
94 
95  RasterFactory* f = static_cast<RasterFactory*>(d.find(ucase));
96 
97  if(f == 0)
98  throw Exception(TE_TR("Could not find concrete factory! Check if it was initialized!"));
99 
100  return f->iOpen(rinfo, p);
101 }
102 
103 te::rst::Raster* te::rst::RasterFactory::open(const std::string& key, const std::string& value, te::common::AccessPolicy p)
104 {
105  return open(TE_DEFAULT_RASTER_TYPE, key, value, p);
106 }
107 
108 te::rst::Raster* te::rst::RasterFactory::open(const std::string& rType, const std::string& key, const std::string& value, te::common::AccessPolicy p)
109 {
110  std::map<std::string, std::string> rinfo;
111 
112  rinfo[key] = value;
113 
114  return open(rType, rinfo, p);
115 }
116 
117 te::rst::RasterFactory::RasterFactory(const std::string& factoryKey)
118  : te::common::AbstractFactory<te::rst::Raster, std::string>(factoryKey)
119 {
120 }
121 
122 te::rst::Raster* te::rst::RasterFactory::iOpen(const std::map<std::string, std::string>& rinfo, te::common::AccessPolicy p)
123 {
124  std::auto_ptr<Raster> r(make(getKey()));
125 
126  r->open(rinfo, p);
127 
128  return r.release();
129 }
130 
static dictionary_type & getDictionary()
It returns a reference to the internal dictionary of concrete factories.
std::string Convert2UCase(const std::string &value)
It converts a string to upper case.
Definition: StringUtils.h:163
#define TE_TR(message)
It marks a string in order to get translated.
Definition: Translator.h:347
TFACTORY * find(const TFACTORYKEY &factoryKey) const
It looks for a given factory identified by a key.
AccessPolicy
Supported data access policies (can be used as bitfield).
Definition: Enums.h:40
An exception class for the Raster module.
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...
An abstract class for raster data strucutures.
Definition: Raster.h:71
#define TE_DEFAULT_RASTER_TYPE
Definition: Config.h:34
static TPRODUCT * make(const TFACTORYKEY &factoryKey)
It creates an object with the appropriated factory.
static Raster * make()
It creates and returns an empty raster with default raster driver.
RasterFactory(const std::string &factoryKey)
Constructor.
This is the abstract factory for Rasters.
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
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
This method must be implemented by subclasses (raster drivers).
This class represents a dictionary of factories.
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.