src/terralib/raster/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 "../core/translator/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("RTYPE");
50  if( it != rinfo.end() )
51  {
52  return make(it->second, g, bands, rinfo, h, deleter);
53  }
54 
55  it = rinfo.find("FORCE_MEM_DRIVER");
56  if( ( it != rinfo.end() ) &&
57  (te::common::Convert2UCase(it->second) == "TRUE") )
58  {
59  return make("MEM", g, bands, rinfo, h, deleter);
60  }
61 
62  return make(TE_DEFAULT_RASTER_TYPE, g, bands, rinfo, h, deleter);
63 }
64 
65 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*))
66 {
67  std::string ucase = te::common::Convert2UCase(rType);
68 
70 
71  RasterFactory* f = static_cast<RasterFactory*>(d.find(ucase));
72 
73  if(f == nullptr)
74  throw Exception(TE_TR("Could not find concrete factory! Check if it was initialized!"));
75 
76  Raster* r = f->create(g, bands, rinfo, h, deleter);
77 
78  return r;
79 }
80 
81 te::rst::Raster* te::rst::RasterFactory::make(const std::map<std::string, std::string>& rinfo, void* h, void (*deleter)(void*))
82 {
83  return make(TE_DEFAULT_RASTER_TYPE, nullptr, std::vector<BandProperty*>(), rinfo, h, deleter);
84 }
85 
86 te::rst::Raster* te::rst::RasterFactory::make(const std::string& rType, const std::map<std::string, std::string>& rinfo, void* h, void (*deleter)(void*))
87 {
88  return make(rType, nullptr, std::vector<BandProperty*>(), rinfo, h, deleter);
89 }
90 
91 te::rst::Raster* te::rst::RasterFactory::open(const std::map<std::string, std::string>& rinfo, te::common::AccessPolicy p)
92 {
93  return open(TE_DEFAULT_RASTER_TYPE, rinfo, p);
94 }
95 
96 te::rst::Raster* te::rst::RasterFactory::open(const std::string& rType, const std::map<std::string, std::string>& rinfo, te::common::AccessPolicy p)
97 {
98  std::string ucase = te::common::Convert2UCase(rType);
99 
101 
102  RasterFactory* f = static_cast<RasterFactory*>(d.find(ucase));
103 
104  if(f == nullptr)
105  throw Exception(TE_TR("Could not find concrete factory! Check if it was initialized!"));
106 
107  return f->iOpen(rinfo, p);
108 }
109 
110 te::rst::Raster* te::rst::RasterFactory::open(const std::string& key, const std::string& value, te::common::AccessPolicy p)
111 {
112  return open(TE_DEFAULT_RASTER_TYPE, key, value, p);
113 }
114 
115 te::rst::Raster* te::rst::RasterFactory::open(const std::string& rType, const std::string& key, const std::string& value, te::common::AccessPolicy p)
116 {
117  std::map<std::string, std::string> rinfo;
118 
119  rinfo[key] = value;
120 
121  return open(rType, rinfo, p);
122 }
123 
124 te::rst::RasterFactory::RasterFactory(const std::string& factoryKey)
125  : te::common::AbstractFactory<te::rst::Raster, std::string>(factoryKey)
126 {
127 }
128 
129 te::rst::Raster* te::rst::RasterFactory::iOpen(const std::map<std::string, std::string>& rinfo, te::common::AccessPolicy p)
130 {
131  std::unique_ptr<Raster> r(make(getKey()));
132 
133  r->open(rinfo, p);
134 
135  return r.release();
136 }
137 
An exception class for the Raster module.
#define TE_DEFAULT_RASTER_TYPE
Base exception class for plugin module.
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:168
#define TE_TR(message)
It marks a string in order to get translated.
Definition: Translator.h:242
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).
This is the abstract factory for Rasters.
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.
URI C++ Library.
Definition: Attributes.h:37
static te::dt::DateTime d(2010, 8, 9, 15, 58, 39)
list bands
Definition: compose.py:2
AbstractFactory(const std::string &factoryKey)
It creates the factory and automatically registers it in the dictionary.
te::gm::Polygon * p
static TPRODUCT * make(const TFACTORYKEY &factoryKey)
It creates an object with the appropriated factory.
const std::string & getKey() const
It returns the factory key associated to the concreate 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.
A rectified grid is the spatial support for raster data.
Definition: raster/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.