All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
Utils.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/tools/rastermanager/core/Utils.cpp
22 
23  \brief Terralib Raster Manager Tool Utils
24  */
25 
26 // Terralib Raster Manager tool
27 #include "Utils.h"
28 
29 // TerraLib
32 
33 // STL
34 #include <map>
35 
36 // Boost
37 #include <boost/filesystem.hpp>
38 
39 namespace fs = boost::filesystem;
40 
41 bool te::tools::rastermanager::Utils::checkInputPath(std::string inputPath, std::string & errorMessage)
42 {
43 
44  fs::path in(inputPath);
45 
46  if(fs::exists(in))
47  {
48  if(fs::is_directory(in))
49  {
50  errorMessage = "Enter with the full path, including the file name and extension!";
51  return false;
52  }
53  if(!fs::is_regular_file(in))
54  {
55  errorMessage = "Input not identified!";
56  return false;
57  }
58 
59  std::string extension = fs::extension(in);
60 
61  }
62  else
63  {
64  errorMessage = "Input Raster not exists!";
65  return false;
66  }
67 
68  return true;
69 }
70 
71 bool te::tools::rastermanager::Utils::checkOutputPath(std::string outputPath, std::string & errorMessage)
72 {
73  if(outputPath.empty())
74  {
75  errorMessage = "Output path invalid!!";
76  return false;
77  }
78 
79  fs::path out(outputPath);
80  std::string extension = fs::extension(out);
81 
82  out.remove_filename();
83 
84  if(!fs::exists(out))
85  {
86  errorMessage = "The Output path not exists!";
87  return false;
88  }
89 
90  return true;
91 }
92 
93 bool te::tools::rastermanager::Utils::getRaster(std::string path, te::rst::Raster* & raster, std::string & errorMessage)
94 {
95 
96  std::map<std::string, std::string> rasterInfo;
97  rasterInfo["URI"] = path;
98 
99  raster = te::rst::RasterFactory::open(rasterInfo);
100 
101  return true;
102 }
103 
104 bool te::tools::rastermanager::Utils::loadModules(std::string & errorMessage)
105 {
106 
107  // Load OGR
108  {
110 
111  #if TE_PLATFORM == TE_PLATFORMCODE_MSWINDOWS
112  info.m_type = "dll";
113  #elif TE_PLATFORM == TE_PLATFORMCODE_LINUX
114  info.m_type = "s.o.";
115  #elif TE_PLATFORM == TE_PLATFORMCODE_APPLE
116  info.m_type = "dylib";
117  #else
118  #error "Platform not supported yet"
119  #endif
120 
121  info.m_name = "OGR DataSource Driver";
122  info.m_description = "This data source driver supports...";
123 
124  #if TE_PLATFORM == TE_PLATFORMCODE_MSWINDOWS
125  #ifdef NDEBUG
126  info.m_mainFile = "terralib_ogr.dll";
127  #else
128  info.m_mainFile = "terralib_ogr_d.dll";
129  #endif
130  #endif
131 
132  #if TE_PLATFORM == TE_PLATFORMCODE_LINUX
133  #ifdef NDEBUG
134  info.m_mainFile = "libterralib_ogr.so";
135  #else
136  info.m_mainFile = "libterralib_ogr_d.so";
137  #endif
138  #endif
139 
140  #if TE_PLATFORM == TE_PLATFORMCODE_APPLE
141  #ifdef NDEBUG
142  info.m_mainFile = "libterralib_ogr.dylib";
143  #else
144  info.m_mainFile = "libterralib_ogr.dylib";
145  #endif
146  #endif
147 
148  te::plugin::PluginManager::getInstance().loadPlugin(info);
149 
150  }
151 
152  // Load GDAL
153  {
155 
156  #if TE_PLATFORM == TE_PLATFORMCODE_MSWINDOWS
157  info.m_type = "dll";
158  #elif TE_PLATFORM == TE_PLATFORMCODE_LINUX
159  info.m_type = "s.o.";
160  #elif TE_PLATFORM == TE_PLATFORMCODE_APPLE
161  info.m_type = "dylib";
162  #else
163  #error "Platform not supported yet"
164  #endif
165 
166  info.m_name = "GDAL DataSource Driver";
167  info.m_description = "This data source driver supports...";
168 
169  #if TE_PLATFORM == TE_PLATFORMCODE_MSWINDOWS
170  #ifdef NDEBUG
171  info.m_mainFile = "terralib_gdal.dll";
172  #else
173  info.m_mainFile = "terralib_gdal_d.dll";
174  #endif
175  #endif
176 
177  #if TE_PLATFORM == TE_PLATFORMCODE_LINUX
178  #ifdef NDEBUG
179  info.m_mainFile = "libterralib_gdal.so";
180  #else
181  info.m_mainFile = "libterralib_gdal_d.so";
182  #endif
183  #endif
184 
185  #if TE_PLATFORM == TE_PLATFORMCODE_APPLE
186  #ifdef NDEBUG
187  info.m_mainFile = "libterralib_gdal.dylib";
188  #else
189  info.m_mainFile = "libterralib_gdal.dylib";
190  #endif
191  #endif
192 
193  te::plugin::PluginManager::getInstance().loadPlugin(info);
194  }
195 
196  // Load GRIB
197 /* {
198  te::plugin::PluginInfo info;
199 
200 #if TE_PLATFORM == TE_PLATFORMCODE_MSWINDOWS
201  info.m_type = "dll";
202 #elif TE_PLATFORM == TE_PLATFORMCODE_LINUX
203  info.m_type = "s.o.";
204 #elif TE_PLATFORM == TE_PLATFORMCODE_APPLE
205  info.m_type = "dylib";
206 #else
207  #error "Platform not supported yet"
208 #endif
209 
210  info.m_name = "GRIB DataSource Driver";
211  info.m_description = "This data source driver supports...";
212 
213 #if TE_PLATFORM == TE_PLATFORMCODE_MSWINDOWS
214 #ifdef NDEBUG
215  info.m_mainFile = "terralib_grib.dll";
216 #else
217  info.m_mainFile = "terralib_grib_d.dll";
218 #endif
219 #endif
220 
221 #if TE_PLATFORM == TE_PLATFORMCODE_LINUX
222 #ifdef NDEBUG
223  info.m_mainFile = "libterralib_grib.so";
224 #else
225  info.m_mainFile = "libterralib_grib.so";
226 #endif
227 #endif
228 
229 #if TE_PLATFORM == TE_PLATFORMCODE_APPLE
230 #ifdef NDEBUG
231  info.m_mainFile = "libterralib_grib.dylib";
232 #else
233  info.m_mainFile = "libterralib_grib.dylib";
234 #endif
235 #endif
236 
237  te::plugin::PluginManager::getInstance().loadPlugin(info);
238  }*/
239 
240  return true;
241 }
std::string m_name
The plugin name: an internal value used to identify the plugin in the system. Must be a unique value...
Definition: PluginInfo.h:66
static bool loadModules(std::string &errorMessage)
Load Terralib modules.
Definition: Utils.cpp:104
static PluginManager & getInstance()
It returns a reference to the singleton instance.
Terralib Raster Manager Tool Utils.
An abstract class for raster data strucutures.
Definition: Raster.h:71
static bool checkInputPath(std::string inputPath, std::string &errorMessage)
Check input raster path.
Definition: Utils.cpp:41
static bool getRaster(std::string path, te::rst::Raster *&raster, std::string &errorMessage)
Get a raster based in the path.
Definition: Utils.cpp:93
A singleton for managing plugins.
std::string m_description
A brief explanation about the plugin.
Definition: PluginInfo.h:68
This is the abstract factory for Rasters.
The basic information about a plugin.
Definition: PluginInfo.h:61
static bool checkOutputPath(std::string outputPath, std::string &errorMessage)
Check output raster path.
Definition: Utils.cpp:71
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.