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 "../BuildConfig.h"
28 #include "../common/Logger.h"
29 #include "../common/PlatformUtils.h"
30 #include "../common/Translator.h"
31 #include "../dataaccess/datasource/DataSourceManager.h"
32 #include "../dataaccess/datasource/DataSourceFactory.h"
33 #include "../dataaccess/query/BinaryOpEncoder.h"
34 #include "../dataaccess/query/FunctionEncoder.h"
35 #include "../dataaccess/query/SQLDialect.h"
36 #include "../dataaccess/query/SQLFunctionEncoder.h"
37 #include "../dataaccess/query/TemplateEncoder.h"
38 #include "../dataaccess/query/UnaryOpEncoder.h"
39 #include "DataSource.h"
40 #include "Globals.h"
41 #include "Module.h"
42 
43 // OGR
44 #include <cpl_conv.h>
45 #include <ogr_api.h>
46 
48  : te::plugin::Plugin(pluginInfo)
49 {
50 }
51 
53 {
54 }
55 
57 {
58  if(m_initialized)
59  return;
60 
61 // for all platforms, first look at TERRALIB_GDAL_DATA detected by CMAKE
62 // note: installed versions on developers machine may look for this version of GDAL
63  std::string gdal_data_dir(TERRALIB_GDAL_DATA);
64 
65  if(gdal_data_dir.empty())
66  {
67  // search for GDAL in TerraLib PATH
68 #if TE_PLATFORM == TE_PLATFORMCODE_MSWINDOWS
69  gdal_data_dir = te::common::FindInTerraLibPath("/share/data");
70 #elif TE_PLATFORM == TE_PLATFORMCODE_APPLE
71  gdal_data_dir = te::common::FindInTerraLibPath("/share/gdal");
72 #elif TE_PLATFORM == TE_PLATFORMCODE_LINUX
73  gdal_data_dir= te::common::FindInTerraLibPath("/share/gdal");
74 #else
75 #error "unsupported plataform: please, contact terralib-team@terralib.org"
76 #endif
77  }
78 
79  if(!gdal_data_dir.empty())
80  {
81  CPLSetConfigOption("GDAL_DATA", gdal_data_dir.c_str());
82  }
83 
84  CPLSetConfigOption("GDAL_PAM_ENABLED", "NO");
85 
86 // registers all format drivers built into OGR.
87  OGRRegisterAll();
88 
89 // it initializes the OGR Factory support
91 
92  #include "OGRDialect.h"
93 
94 #if GDAL_VERSION_NUM >= 1900
95  const char* currentValue = CPLGetConfigOption("GDAL_FIX_ESRI_WKT", "");
96  if(strcmp(currentValue, "") == 0) // to avoid override
97  CPLSetConfigOption("GDAL_FIX_ESRI_WKT", "GEOGCS");
98 #endif
99 
100  TE_LOG_TRACE(TE_TR("TerraLib OGR driver startup!"));
101 
102  m_initialized = true;
103 }
104 
106 {
107  if(!m_initialized)
108  return;
109 
110 // it finalizes the OGR factory support.
112 
113 // free OGR registered drivers
115 
116  OGRCleanupAll();
117 
119 
120  TE_LOG_TRACE(TE_TR("TerraLib OGR driver shutdown!"));
121 
122  m_initialized = false;
123 }
124 
126 
#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:52
TECOMMONEXPORT std::string FindInTerraLibPath(const std::string &p)
Returns the path relative to a directory or file in the context of TerraLib.
#define OGR_DRIVER_IDENTIFIER
The OGR driver identifier string.
Definition: Config.h:34
#define TE_TR(message)
It marks a string in order to get translated.
Definition: Translator.h:346
#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:54
static DataSourceManager & getInstance()
It returns a reference to the singleton instance.
The TerraLib OGR driver is a plugin.
Definition: Module.h:42
URI C++ Library.
The TerraLib OGR driver is a plugin.
Module(const te::plugin::PluginInfo &pluginInfo)
Plugin constructor.
Definition: Module.cpp:47
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:56
static void setDialect(te::da::SQLDialect *dialect)
Definition: DataSource.cpp:192
void shutdown()
It finalizes all TerraLib OGR driver support.
Definition: Module.cpp:105