All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
Module.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/ogr/Module.h
22 
23  \brief The TerraLib OGR driver is a plugin.
24 */
25 
26 // TerraLib
27 #include "terralib_config.h"
28 #include "../common/Logger.h"
29 #include "../common/Translator.h"
30 #include "../dataaccess/datasource/DataSourceManager.h"
31 #include "../dataaccess/datasource/DataSourceFactory.h"
32 #include "../dataaccess/query/BinaryOpEncoder.h"
33 #include "../dataaccess/query/FunctionEncoder.h"
34 #include "../dataaccess/query/SQLDialect.h"
35 #include "../dataaccess/query/SQLFunctionEncoder.h"
36 #include "../dataaccess/query/TemplateEncoder.h"
37 #include "../dataaccess/query/UnaryOpEncoder.h"
38 #include "DataSource.h"
39 #include "Globals.h"
40 #include "Module.h"
41 
42 // OGR
43 #include <cpl_conv.h>
44 #include <ogr_api.h>
45 
47  : te::plugin::Plugin(pluginInfo)
48 {
49 }
50 
52 {
53 }
54 
56 {
57  if(m_initialized)
58  return;
59 
60  std::string gdal_data;
61  char* gdata = getenv("GDAL_DATA");
62 
63  if(gdata != 0)
64  gdal_data = std::string(gdata);
65 
66  if(gdal_data.empty())
67  {
68  char* tDir = getenv("TERRALIB_HOME");
69  std::string teDir;
70 
71  if(tDir != 0)
72  teDir = std::string(tDir);
73 
74  if(!teDir.empty())
75  gdal_data = teDir + "/share/gdal-data";
76  }
77 
78  if(gdal_data.empty())
79  gdal_data = TERRALIB_GDAL_DATA;
80 
81  if( !gdal_data.empty() )
82  {
83  CPLSetConfigOption("GDAL_DATA", gdal_data.c_str());
84  }
85 
86  CPLSetConfigOption("GDAL_PAM_ENABLED", "NO");
87 
88 // registers all format drivers built into OGR.
89  OGRRegisterAll();
90 
91 // it initializes the OGR Factory support
93 
94  #include "OGRDialect.h"
95 
96 #if GDAL_VERSION_NUM >= 1900
97  const char* currentValue = CPLGetConfigOption("GDAL_FIX_ESRI_WKT", "");
98  if(strcmp(currentValue, "") == 0) // to avoid override
99  CPLSetConfigOption("GDAL_FIX_ESRI_WKT", "GEOGCS");
100 #endif
101 
102  TE_LOG_TRACE(TE_TR("TerraLib OGR driver startup!"));
103 
104  m_initialized = true;
105 }
106 
108 {
109  if(!m_initialized)
110  return;
111 
112 // it finalizes the OGR factory support.
114 
115 // free OGR registered drivers
117 
118  OGRCleanupAll();
119 
121 
122  TE_LOG_TRACE(TE_TR("TerraLib OGR driver shutdown!"));
123 
124  m_initialized = false;
125 }
126 
128 
#define TE_LOG_TRACE(msg)
Use this tag in order to log a message to a specified logger with the TRACE level.
Definition: Logger.h:137
A class for data providers of OGR.
~Module()
Destructor.
Definition: Module.cpp:51
#define OGR_DRIVER_IDENTIFIER
The OGR driver identifier string.
Definition: Config.h:36
#define TE_TR(message)
It marks a string in order to get translated.
Definition: Translator.h:347
#define PLUGIN_CALL_BACK_IMPL(PLUGIN_CLASS_NAME)
This macro should be used by C++ plugins in order to declare the exportable/callable DLL function...
Definition: Config.h:57
static DataSourceManager & getInstance()
It returns a reference to the singleton instance.
The TerraLib OGR driver is a plugin.
Definition: Module.h:42
The TerraLib OGR driver is a plugin.
Module(const te::plugin::PluginInfo &pluginInfo)
Plugin constructor.
Definition: Module.cpp:46
DataSource * Build()
Definition: DataSource.cpp:309
static void add(const std::string &dsType, FactoryFnctType f)
The basic information about a plugin.
Definition: PluginInfo.h:61
static void remove(const std::string &dsType)
An static class with global definitions.
void startup()
It initializes all TerraLib OGR driver support.
Definition: Module.cpp:55
static void setDialect(te::da::SQLDialect *dialect)
Definition: DataSource.cpp:192
void shutdown()
It finalizes all TerraLib OGR driver support.
Definition: Module.cpp:107