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_RASTER_EXTENSIONS-The supported raster file extensions,
78  SUPPORTED_RASTER_CREATION_EXTENSIONS-The supported raster file extensions (with creation support),
79  SUPPORTED_VECTOR_EXTENSIONS-The supported vector file extensions.
80  */
82  {
83  public:
84 
85  DataSource(const std::string& connInfo);
86 
88 
90 
91  std::string getType() const;
92 
93  std::unique_ptr<te::da::DataSourceTransactor> getTransactor();
94 
95  void open();
96 
97  void close();
98 
99  bool isOpened() const;
100 
101  bool isValid() const;
102 
104 
105  std::size_t getNumberOfItems(const std::string& datasetName)
106  { return 1; }
107 
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::unique_ptr<te::da::ForeignKey> getForeignKey(const std::string& , const std::string& )
154  { return std::unique_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::unique_ptr<te::da::UniqueKey> getUniqueKey(const std::string& , const std::string& )
169  { return std::unique_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::unique_ptr<te::da::CheckConstraint> getCheckConstraint(const std::string& , const std::string& )
181  { return std::unique_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::unique_ptr<te::da::Index> getIndex(const std::string& , const std::string& )
196  { return std::unique_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::unique_ptr<te::da::Sequence> getSequence(const std::string& )
212  { return std::unique_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::string& connInfo);
229 
230  void drop(const std::string& connInfo);
231 
232  bool exists(const std::string& connInfo);
233 
234  std::vector<std::string> getDataSourceNames(const std::string& connInfo);
235 
236  private:
237 
238  std::string m_straccess;
241 
242  };
243  } // end namespace gdal
244 } // end namespace te
245 
246 #endif // __TERRALIB_GDAL_INTERNAL_DATASOURCE_H
247 
te::da::DataSourceCapabilities capabilities
A class to store the proxy information that must be used to access data located in URIs.
Definition: URI.h:50
A class that describes a check constraint.
A dataset is the unit of information manipulated by the data access module of TerraLib.
Definition: DataSet.h:114
A class that represents the known capabilities of a specific data source, i.e. this class informs all...
An abstract class for data providers like a DBMS, Web Services or a regular file.
Definition: DataSource.h:120
It models a foreign key constraint for a DataSetType.
Definition: ForeignKey.h:49
It describes an index associated to a DataSetType.
Definition: Index.h:53
This class represents a set of unique ids created in the same context. i.e. from the same data set.
Definition: ObjectIdSet.h:56
It describes a primary key (pk) constraint.
Definition: PrimaryKey.h:49
A Query is independent from the data source language/dialect.
Definition: Query.h:47
It represents the SQL query dialect accepted by a given data source.
Definition: SQLDialect.h:56
It describes a sequence (a number generator).
Definition: Sequence.h:57
It describes a unique key (uk) constraint.
Definition: UniqueKey.h:50
It models a property definition.
Definition: Property.h:60
A driver to access raster data using the GDAL library.
Definition: DataSource.h:82
void dropIndex(const std::string &, const std::string &)
It removes the index from the given dataset.
Definition: DataSource.h:208
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
static void setCapabilities(const te::da::DataSourceCapabilities &capabilities)
void addProperty(const std::string &, te::dt::Property *)
It adds a new property to the dataset schema.
Definition: DataSource.h:110
void execute(const te::da::Query &)
It executes the specified command using a generic query representation.
Definition: DataSource.h:135
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::unique_ptr< te::da::Sequence > getSequence(const std::string &)
It gets the sequence with the given name in the data source.
Definition: DataSource.h:211
void create(const std::string &connInfo)
It creates a new data source.
void dropProperty(const std::string &, const std::string &)
It removes a property from the given dataset.
Definition: DataSource.h:112
void addUniqueKey(const std::string &, te::da::UniqueKey *)
It adds a unique key constraint to the dataset.
Definition: DataSource.h:174
void renameProperty(const std::string &, const std::string &, const std::string &)
It renames a property of the given dataset.
Definition: DataSource.h:114
DataSource(const te::core::URI &uri)
void dropPrimaryKey(const std::string &)
It removes the primary key constraint from the dataset schema.
Definition: DataSource.h:150
void addCheckConstraint(const std::string &, te::da::CheckConstraint *)
It adds a check constraint to the dataset.
Definition: DataSource.h:189
std::unique_ptr< te::da::ForeignKey > getForeignKey(const std::string &, const std::string &)
It retrieves the foreign key from the given dataset.
Definition: DataSource.h:153
std::unique_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
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 open()
It opens the data source and makes it ready for using.
std::string escape(const std::string &value)
It escapes a string for using in commands and queries.
Definition: DataSource.h:141
void close()
It closes the data source and clears all the resources used by its internal communication channel.
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
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 dropForeignKey(const std::string &, const std::string &)
It removes the foreign key constraint from the dataset schema.
Definition: DataSource.h:165
void addPrimaryKey(const std::string &, te::da::PrimaryKey *)
It adds a primary key constraint to the dataset schema.
Definition: DataSource.h:147
const te::da::SQLDialect * getDialect() const
It returns the data source SQL dialect, if there is one.
Definition: DataSource.h:132
std::vector< std::string > getForeignKeyNames(const std::string &)
It gets the foreign key names of the given dataset.
Definition: DataSource.h:156
bool sequenceExists(const std::string &)
It checks if a sequence with the given name exists in the data source.
Definition: DataSource.h:217
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
std::string getType() const
It returns the data source type name (in UPPER CASE). Ex: POSTGIS, SQLITE, WFS, WMS,...
bool isOpened() const
It returns true if the data source is opened, otherwise it returns false.
bool isValid() const
It checks if the data source is valid (available for using).
const te::da::DataSourceCapabilities & getCapabilities() const
It returns the known capabilities of the data source.
void dropSequence(const std::string &)
It removes the sequence from the data source.
Definition: DataSource.h:223
void execute(const std::string &)
It executes the specified command in the data source native language.
Definition: DataSource.h:138
std::vector< std::string > getCheckConstraintNames(const std::string &)
It gets the check constraint names of the given dataset.
Definition: DataSource.h:183
std::vector< std::string > getDataSourceNames(const std::string &connInfo)
It gets the data source names available in a driver.
std::unique_ptr< te::da::DataSourceTransactor > getTransactor()
It returns the set of parameters used to set up the access channel to the underlying repository.
std::vector< std::string > getIndexNames(const std::string &)
It gets the index names of the given dataset.
Definition: DataSource.h:198
bool exists(const std::string &connInfo)
Check the existence of a data source in a driver.
void addSequence(te::da::Sequence *)
It adds a new sequence in the data source.
Definition: DataSource.h:220
static te::da::DataSourceCapabilities sm_capabilities
Definition: DataSource.h:240
std::size_t getNumberOfItems(const std::string &datasetName)
It retrieves the number of items of the given dataset.
Definition: DataSource.h:105
void remove(const std::string &, const te::da::ObjectIdSet *)
It removes all the informed items from the dataset.
Definition: DataSource.h:122
std::string m_straccess
Definition: DataSource.h:238
bool primaryKeyExists(const std::string &, const std::string &)
It checks if a primary key exists in the dataset.
Definition: DataSource.h:144
std::unique_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
~DataSource()
Virtual destructor.
void dropUniqueKey(const std::string &, const std::string &)
It removes the unique key constraint from the dataset.
Definition: DataSource.h:177
void drop(const std::string &connInfo)
It removes the data source with the connection information from a driver.
DataSource(const std::string &connInfo)
void addForeignKey(const std::string &, te::da::ForeignKey *)
It adds a foreign key constraint to a dataset.
Definition: DataSource.h:162
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
std::unique_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 > getSequenceNames()
It gets the sequence names available in the data source.
Definition: DataSource.h:214
void dropCheckConstraint(const std::string &, const std::string &)
It removes the check constraint from the dataset.
Definition: DataSource.h:192
TerraLib.
#define TEGDALEXPORT
You can use this macro in order to export/import classes and functions from this module.
Definition: Config.h:67
Proxy configuration file for TerraView (see terraview_config.h).
Implementation of the transactor for the WS OGC WMS.
An exception class for the XML module.