All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
DataSource.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/wms/DataSource.cpp
22 
23  \brief Implementation of the data source for the WMS driver.
24 */
25 
26 // TerraLib
27 #include "../dataaccess/datasource/DataSourceTransactor.h"
28 #include "../common/StringUtils.h"
29 #include "../common/Translator.h"
30 #include "DataSource.h"
31 #include "Exception.h"
32 #include "Transactor.h"
33 #include "Utils.h"
34 
35 // GDAL
36 #include <gdal_priv.h>
37 
39 
41  : m_isOpened(false)
42 {
43 }
44 
46 {}
47 
48 std::string te::wms::DataSource::getType() const
49 {
51 }
52 
53 const std::map<std::string, std::string>& te::wms::DataSource::getConnectionInfo() const
54 {
55  return m_connectionInfo;
56 }
57 
58 void te::wms::DataSource::setConnectionInfo(const std::map<std::string, std::string>& connInfo)
59 {
60  m_connectionInfo = connInfo;
61 }
62 
63 std::auto_ptr<te::da::DataSourceTransactor> te::wms::DataSource::getTransactor()
64 {
65  if(!m_isOpened)
66  throw Exception(TE_TR("The data source is not opened!"));
67 
68  return std::auto_ptr<te::da::DataSourceTransactor>(new Transactor(m_connectionInfo.find("URI")->second, m_layersInfo));
69 }
70 
72 {
73  if(m_isOpened)
74  return;
75 
76  verifyConnectionInfo();
77 
78  GDALDataset* gds = static_cast<GDALDataset*>(GDALOpen(m_connectionInfo.find("URI")->second.c_str(), GA_ReadOnly));
79  if(gds == 0)
80  throw Exception(TE_TR("Error establishing connection with the informed server!"));
81 
82  // Gets the layer informations from server
83  char** subdatasets = gds->GetMetadata("SUBDATASETS");
84 
85  // Builds the layer informations from informed GDAL subdatasets
86  BuildLayersInfo(subdatasets, m_layersInfo);
87 
88  GDALClose(gds);
89 
90  m_isOpened = true;
91 }
92 
94 {
95  m_isOpened = false;
96  m_layersInfo.clear();
97 }
98 
100 {
101  return m_isOpened;
102 }
103 
105 {
106  if(m_connectionInfo.empty())
107  return false;
108 
109  std::map<std::string, std::string>::const_iterator it = m_connectionInfo.find("URI");
110  if(it == m_connectionInfo.end())
111  return false;
112 
113  GDALDataset* gds = static_cast<GDALDataset*>(GDALOpen(it->second.c_str(), GA_ReadOnly));
114  if(gds == 0)
115  return false;
116 
117  GDALClose(gds);
118 
119  return true;
120 }
121 
123 {
124  return sm_capabilities;
125 }
126 
128 {
129  sm_capabilities = capabilities;
130 }
131 
133 {
134  return 0;
135 }
136 
137 const std::map<std::string, te::wms::WMSLayerInfo>& te::wms::DataSource::getLayersInfo() const
138 {
139  return m_layersInfo;
140 }
141 
142 void te::wms::DataSource::create(const std::map<std::string, std::string>& /*dsInfo*/)
143 {
144  throw Exception(TE_TR("The create() method is not supported by the WMS driver!"));
145 }
146 
147 void te::wms::DataSource::drop(const std::map<std::string, std::string>& /*dsInfo*/)
148 {
149  throw Exception(TE_TR("The drop() method is not supported by the WMS driver!"));
150 }
151 
152 bool te::wms::DataSource::exists(const std::map<std::string, std::string>& dsInfo)
153 {
154  if(dsInfo.empty())
155  return false;
156 
157  std::map<std::string, std::string>::const_iterator it = dsInfo.find("URI");
158  if(it == dsInfo.end())
159  return false;
160 
161  GDALDataset* gds = static_cast<GDALDataset*>(GDALOpen(it->second.c_str(), GA_ReadOnly));
162  if(gds == 0)
163  return false;
164 
165  GDALClose(gds);
166 
167  return true;
168 }
169 
170 std::vector<std::string> te::wms::DataSource::getDataSourceNames(const std::map<std::string, std::string>& /*dsInfo*/)
171 {
172  return std::vector<std::string>();
173 }
174 
175 std::vector<te::common::CharEncoding> te::wms::DataSource::getEncodings(const std::map<std::string, std::string>& /*dsInfo*/)
176 {
177  return std::vector<te::common::CharEncoding>();
178 }
179 
181 {
182  if(m_connectionInfo.empty())
183  throw Exception(TE_TR("The connection information is empty!"));
184 
185  std::map<std::string, std::string>::const_iterator it = m_connectionInfo.find("URI");
186  if(it == m_connectionInfo.end())
187  throw Exception(TE_TR("The connection information is invalid. Missing URI parameter!"));
188 }
Implementation of the transactor for the WMS driver.
Definition: Transactor.h:48
const te::da::DataSourceCapabilities & getCapabilities() const
It returns the known capabilities of the data source.
Definition: DataSource.cpp:122
std::auto_ptr< te::da::DataSourceTransactor > getTransactor()
It returns an object that can execute transactions in the context of a data source.
Definition: DataSource.cpp:63
const std::map< std::string, WMSLayerInfo > & getLayersInfo() const
Definition: DataSource.cpp:137
It represents the SQL query dialect accepted by a given data source.
Definition: SQLDialect.h:55
#define TE_WMS_DRIVER_IDENTIFIER
Definition: Config.h:39
bool isOpened() const
It returns true if the data source is opened, otherwise it returns false.
Definition: DataSource.cpp:99
std::vector< te::common::CharEncoding > getEncodings(const std::map< std::string, std::string > &dsInfo)
It gets the encodings for the data source.
Definition: DataSource.cpp:175
std::vector< std::string > getDataSourceNames(const std::map< std::string, std::string > &dsInfo)
It gets the data source names available in a driver.
Definition: DataSource.cpp:170
A class that represents the known capabilities of a specific data source, i.e. this class informs all...
void close()
It closes the data source and clears all the resources used by its internal communication channel...
Definition: DataSource.cpp:93
#define TE_TR(message)
It marks a string in order to get translated.
Definition: Translator.h:347
bool exists(const std::map< std::string, std::string > &dsInfo)
Check the existence of a data source in a driver.
Definition: DataSource.cpp:152
void setConnectionInfo(const std::map< std::string, std::string > &connInfo)
It sets the connection information to be used when connecting to the data source. ...
Definition: DataSource.cpp:58
const te::da::SQLDialect * getDialect() const
It returns the data source SQL dialect, if there is one.
Definition: DataSource.cpp:132
An exception class for the TerraLib WMS module.
void BuildLayersInfo(char **subdatasets, std::map< std::string, WMSLayerInfo > &info)
Definition: Utils.cpp:38
te::da::DataSourceCapabilities capabilities
static void setCapabilities(const te::da::DataSourceCapabilities &capabilities)
Definition: DataSource.cpp:127
void drop(const std::map< std::string, std::string > &dsInfo)
It removes the data source with the connection information from a driver.
Definition: DataSource.cpp:147
Implementation of the data source for the WMS driver.
const std::map< std::string, std::string > & getConnectionInfo() const
It returns the set of parameters used to set up the access channel to the underlying repository...
Definition: DataSource.cpp:53
std::string getType() const
It returns the data source type name (in UPPER CASE). Ex: POSTGIS, SQLITE, WFS, WMS, or MYSQL.
Definition: DataSource.cpp:48
Utility functions for WMS driver.
void create(const std::map< std::string, std::string > &dsInfo)
It creates a new data source.
Definition: DataSource.cpp:142
static te::da::DataSourceCapabilities sm_capabilities
Definition: DataSource.h:102
bool isValid() const
It checks if the data source is valid (available for using).
Definition: DataSource.cpp:104
void open()
It opens the data source and makes it ready for using.
Definition: DataSource.cpp:71
void verifyConnectionInfo() const
Definition: DataSource.cpp:180
~DataSource()
Virtual destructor.
Definition: DataSource.cpp:45
Implementation of the transactor for the WMS driver.