DataSource.h
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/gdal/DataSource.h
22 
23  \brief The implementation of a DataSource that consists of datasets that can be decoded by the GDAL Library.
24  */
25 
26 #ifndef __TERRALIB_GDAL_INTERNAL_DATASOURCE_H
27 #define __TERRALIB_GDAL_INTERNAL_DATASOURCE_H
28 
29 // TerraLib
30 #include "../dataaccess/datasource/DataSource.h"
31 #include "../dataaccess/datasource/DataSourceCapabilities.h"
32 #include "../dataaccess/dataset/DataSetType.h"
33 #include "Config.h"
34 #include "Exception.h"
35 #include "Transactor.h"
36 
37 // Boost
38 #include <boost/shared_ptr.hpp>
39 #include <boost/ptr_container/ptr_vector.hpp>
40 #include <boost/filesystem.hpp>
41 
42 // STL
43 #include <map>
44 #include <memory>
45 #include <string>
46 #include <vector>
47 
48 namespace te
49 {
50  namespace dt
51  {
52  class Property;
53  }
54 
55  namespace gm
56  {
57  class Envelope;
58  class Geometry;
59  }
60  namespace da
61  {
62  class DataSet;
63  class ObjectIdSet;
64  class DataSourceTransactor;
65  }
66 
67  namespace gdal
68  {
69  /*!
70  \class DataSource
71 
72  \brief A driver to access raster data using the GDAL library.
73 
74  This class is an implementation of a DataSource that consists of raster that can be decoded
75  by the GDAL - Geospatial Data Abstraction Library (http://www.gdal.org/).
76 
77  \note Supported getCapabilities options: SUPPORTED_EXTENSIONS-The supported file extensions.
78  */
80  {
81  public:
82 
83  DataSource();
84 
85  ~DataSource();
86 
87  std::string getType() const;
88 
89  const std::map<std::string, std::string>& getConnectionInfo() const;
90 
91  void setConnectionInfo(const std::map<std::string, std::string>& connInfo);
92 
93  std::auto_ptr<te::da::DataSourceTransactor> getTransactor();
94 
95  void open();
96 
97  void close();
98 
99  bool isOpened() const;
100 
101  bool isValid() const;
102 
103  const te::da::DataSourceCapabilities& getCapabilities() const;
104 
105  std::size_t getNumberOfItems(const std::string& datasetName)
106  { return 1; }
107 
108  static void setCapabilities(const te::da::DataSourceCapabilities& capabilities);
109 
110  void addProperty(const std::string& , te::dt::Property* ) {}
111 
112  void dropProperty(const std::string& , const std::string& ) {};
113 
114  void renameProperty(const std::string& , const std::string& , const std::string& ) {}
115 
116 
117  void add(const std::string& ,
118  te::da::DataSet* ,
119  const std::map<std::string, std::string>& ,
120  std::size_t) {}
121 
122  void remove(const std::string& ,
123  const te::da::ObjectIdSet* ) {}
124 
125  void update(const std::string& ,
126  te::da::DataSet* ,
127  const std::vector<std::size_t>&,
128  const te::da::ObjectIdSet* ,
129  const std::map<std::string, std::string>& ,
130  std::size_t ) {}
131 
133  { return 0; }
134 
135  void execute(const te::da::Query&)
136  {}
137 
138  void execute(const std::string&)
139  {}
140 
141  std::string escape(const std::string& value)
142  { return value; }
143 
144  bool primaryKeyExists(const std::string& , const std::string& )
145  { return false; }
146 
147  void addPrimaryKey(const std::string& , te::da::PrimaryKey* )
148  {}
149 
150  void dropPrimaryKey(const std::string& )
151  {}
152 
153  std::auto_ptr<te::da::ForeignKey> getForeignKey(const std::string& , const std::string& )
154  { return std::auto_ptr<te::da::ForeignKey>(); }
155 
156  std::vector<std::string> getForeignKeyNames(const std::string& )
157  { return std::vector<std::string>(); }
158 
159  bool foreignKeyExists(const std::string& , const std::string& )
160  { return false; }
161 
162  void addForeignKey(const std::string&, te::da::ForeignKey* )
163  {}
164 
165  void dropForeignKey(const std::string& , const std::string& )
166  {}
167 
168  std::auto_ptr<te::da::UniqueKey> getUniqueKey(const std::string& , const std::string& )
169  { return std::auto_ptr<te::da::UniqueKey>(); }
170 
171  bool uniqueKeyExists(const std::string& , const std::string& )
172  { return false; }
173 
174  void addUniqueKey(const std::string& , te::da::UniqueKey* )
175  {}
176 
177  void dropUniqueKey(const std::string& , const std::string& )
178  {}
179 
180  std::auto_ptr<te::da::CheckConstraint> getCheckConstraint(const std::string& , const std::string& )
181  { return std::auto_ptr<te::da::CheckConstraint>(); }
182 
183  std::vector<std::string> getCheckConstraintNames(const std::string& )
184  { return std::vector<std::string>(); }
185 
186  bool checkConstraintExists(const std::string& , const std::string& )
187  { return false; }
188 
189  void addCheckConstraint(const std::string& , te::da::CheckConstraint* )
190  {}
191 
192  void dropCheckConstraint(const std::string& , const std::string& )
193  {}
194 
195  std::auto_ptr<te::da::Index> getIndex(const std::string& , const std::string& )
196  { return std::auto_ptr<te::da::Index>(); }
197 
198  std::vector<std::string> getIndexNames(const std::string& )
199  { return std::vector<std::string>(); }
200 
201  bool indexExists(const std::string& , const std::string& )
202  { return false; }
203 
204  void addIndex(const std::string& , te::da::Index* ,
205  const std::map<std::string, std::string>& )
206  {}
207 
208  void dropIndex(const std::string& , const std::string& )
209  {}
210 
211  std::auto_ptr<te::da::Sequence> getSequence(const std::string& )
212  { return std::auto_ptr<te::da::Sequence>(); }
213 
214  std::vector<std::string> getSequenceNames()
215  { return std::vector<std::string>(); }
216 
217  bool sequenceExists(const std::string& )
218  { return false; }
219 
221  {}
222 
223  void dropSequence(const std::string& )
224  {}
225 
226  protected:
227 
228  void create(const std::map<std::string, std::string>& dsInfo);
229 
230  void drop(const std::map<std::string, std::string>& dsInfo);
231 
232  bool exists(const std::map<std::string, std::string>& dsInfo);
233 
234  std::vector<std::string> getDataSourceNames(const std::map<std::string, std::string>& dsInfo);
235 
236  std::vector<te::common::CharEncoding> getEncodings(const std::map<std::string, std::string>& dsInfo);
237 
238  private:
239 
240  std::map<std::string, std::string> m_connectionInfo;
241 
242  std::string m_straccess;
243 
245 
247 
248  };
249  } // end namespace gdal
250 } // end namespace te
251 
252 #endif // __TERRALIB_GDAL_INTERNAL_DATASOURCE_H
253 
void addSequence(te::da::Sequence *)
It adds a new sequence in the data source.
Definition: DataSource.h:220
void addForeignKey(const std::string &, te::da::ForeignKey *)
It adds a foreign key constraint to a dataset.
Definition: DataSource.h:162
bool sequenceExists(const std::string &)
It checks if a sequence with the given name exists in the data source.
Definition: DataSource.h:217
void addPrimaryKey(const std::string &, te::da::PrimaryKey *)
It adds a primary key constraint to the dataset schema.
Definition: DataSource.h:147
void addProperty(const std::string &, te::dt::Property *)
It adds a new property to the dataset schema.
Definition: DataSource.h:110
const te::da::SQLDialect * getDialect() const
It returns the data source SQL dialect, if there is one.
Definition: DataSource.h:132
bool uniqueKeyExists(const std::string &, const std::string &)
It checks if a unique key with the given name exists in the dataset.
Definition: DataSource.h:171
void dropSequence(const std::string &)
It removes the sequence from the data source.
Definition: DataSource.h:223
#define TEGDALEXPORT
You can use this macro in order to export/import classes and functions from this module.
Definition: Config.h:67
bool foreignKeyExists(const std::string &, const std::string &)
It checks if a foreign key with the given name exists in the data source.
Definition: DataSource.h:159
void addUniqueKey(const std::string &, te::da::UniqueKey *)
It adds a unique key constraint to the dataset.
Definition: DataSource.h:174
void execute(const std::string &)
It executes the specified command in the data source native language.
Definition: DataSource.h:138
void execute(const te::da::Query &)
It executes the specified command using a generic query representation.
Definition: DataSource.h:135
It represents the SQL query dialect accepted by a given data source.
Definition: SQLDialect.h:55
std::map< std::string, std::string > m_connectionInfo
Definition: DataSource.h:240
bool indexExists(const std::string &, const std::string &)
It checks if an index with the given name exists in the dataset.
Definition: DataSource.h:201
It describes a sequence (a number generator).
Definition: Sequence.h:56
A class that represents the known capabilities of a specific data source, i.e. this class informs all...
static te::da::DataSourceCapabilities sm_capabilities
Definition: DataSource.h:246
A class that describes a check constraint.
An abstract class for data providers like a DBMS, Web Services or a regular file. ...
Definition: DataSource.h:118
std::vector< std::string > getIndexNames(const std::string &)
It gets the index names of the given dataset.
Definition: DataSource.h:198
std::auto_ptr< te::da::Sequence > getSequence(const std::string &)
It gets the sequence with the given name in the data source.
Definition: DataSource.h:211
std::auto_ptr< te::da::ForeignKey > getForeignKey(const std::string &, const std::string &)
It retrieves the foreign key from the given dataset.
Definition: DataSource.h:153
It models a property definition.
Definition: Property.h:59
void add(const std::string &, te::da::DataSet *, const std::map< std::string, std::string > &, std::size_t)
It adds data items to the dataset in the data source.
Definition: DataSource.h:117
void update(const std::string &, te::da::DataSet *, const std::vector< std::size_t > &, const te::da::ObjectIdSet *, const std::map< std::string, std::string > &, std::size_t)
It updates the contents of a dataset for the set of data items.
Definition: DataSource.h:125
void dropPrimaryKey(const std::string &)
It removes the primary key constraint from the dataset schema.
Definition: DataSource.h:150
An exception class for the GDAL module.
A driver to access raster data using the GDAL library.
Definition: DataSource.h:79
bool checkConstraintExists(const std::string &, const std::string &)
It checks if a check-constraint with the given name exists in the data source.
Definition: DataSource.h:186
bool primaryKeyExists(const std::string &, const std::string &)
It checks if a primary key exists in the dataset.
Definition: DataSource.h:144
This class represents a set of unique ids created in the same context. i.e. from the same data set...
Definition: ObjectIdSet.h:55
te::da::DataSourceCapabilities capabilities
void dropForeignKey(const std::string &, const std::string &)
It removes the foreign key constraint from the dataset schema.
Definition: DataSource.h:165
URI C++ Library.
It models a foreign key constraint for a DataSetType.
Definition: ForeignKey.h:50
std::string escape(const std::string &value)
It escapes a string for using in commands and queries.
Definition: DataSource.h:141
It describes a unique key (uk) constraint.
Definition: UniqueKey.h:53
std::size_t getNumberOfItems(const std::string &datasetName)
It retrieves the number of items of the given dataset.
Definition: DataSource.h:105
A dataset is the unit of information manipulated by the data access module of TerraLib.
Definition: DataSet.h:112
std::vector< std::string > getSequenceNames()
It gets the sequence names available in the data source.
Definition: DataSource.h:214
It describes a primary key (pk) constraint.
Definition: PrimaryKey.h:52
void dropCheckConstraint(const std::string &, const std::string &)
It removes the check constraint from the dataset.
Definition: DataSource.h:192
void dropUniqueKey(const std::string &, const std::string &)
It removes the unique key constraint from the dataset.
Definition: DataSource.h:177
std::auto_ptr< te::da::Index > getIndex(const std::string &, const std::string &)
It gets the index with the given name from the dataset.
Definition: DataSource.h:195
void renameProperty(const std::string &, const std::string &, const std::string &)
It renames a property of the given dataset.
Definition: DataSource.h:114
void dropIndex(const std::string &, const std::string &)
It removes the index from the given dataset.
Definition: DataSource.h:208
void dropProperty(const std::string &, const std::string &)
It removes a property from the given dataset.
Definition: DataSource.h:112
std::auto_ptr< te::da::CheckConstraint > getCheckConstraint(const std::string &, const std::string &)
It gets the check constraint of the dataset with the given name.
Definition: DataSource.h:180
void addIndex(const std::string &, te::da::Index *, const std::map< std::string, std::string > &)
It adds an index to the dataset.
Definition: DataSource.h:204
std::vector< std::string > getCheckConstraintNames(const std::string &)
It gets the check constraint names of the given dataset.
Definition: DataSource.h:183
std::auto_ptr< te::da::UniqueKey > getUniqueKey(const std::string &, const std::string &)
It gets the unique key in the dataset with the given name.
Definition: DataSource.h:168
std::vector< std::string > getForeignKeyNames(const std::string &)
It gets the foreign key names of the given dataset.
Definition: DataSource.h:156
std::string m_straccess
Definition: DataSource.h:242
A Query is independent from the data source language/dialect.
Definition: Query.h:46
It describes an index associated to a DataSetType.
Definition: Index.h:54
Configuration flags for the GDAL Driver of TerraLib.
void addCheckConstraint(const std::string &, te::da::CheckConstraint *)
It adds a check constraint to the dataset.
Definition: DataSource.h:189