DataAccessExamples.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 DataAccessExamples.h
22 
23  \brief Examples on how to access/manipulate DataSources in TerraLib.
24  */
25 
26 #ifndef __TERRALIB_EXAMPLES_DATAACCESS_INTERNAL_DATAACCESSEXAMPLES_H
27 #define __TERRALIB_EXAMPLES_DATAACCESS_INTERNAL_DATAACCESSEXAMPLES_H
28 
29 // TerraLib
30 #include <terralib_buildconfig.h>
31 
32 #include <terralib/common.h>
33 #include <terralib/dataaccess.h>
34 #include <terralib/datatype_fw.h>
35 #include <terralib/dataaccess_fw.h>
36 
38 #include <terralib/geometry.h>
39 
40 te::da::DataSetType* CreateDataSetType(const std::string& datasetname,te::da::DataSetType* dt, te::da::DataSourceTransactor* transactor);
41 
42 te::da::DataSetType* CreateDataSetTypeInMemory(const std::string& datasettypename);
43 
44 /*
45  \brief It adds a Primary Key to the given dataset type.
46 
47  \param datasetname The target dataset name.
48  \param transactor The transactor to be used to persist the modifications
49 
50  \return A pointer to the created primary key.
51 
52  \pre The dataset type DOES NOT need to be associated to a data source catalog in memory.
53  \pre The dataset type must have an attribute called 'gid'.
54  \pre The dataset type must not have a primary key.
55 
56  \post The dataset type will have an associated primary key.
57 
58  \exception Exception It throws an exception if something goes wrong.
59  */
60 te::da::PrimaryKey* AddPrimaryKey(const std::string& datasetname,
61  te::da::DataSourceTransactor* transactor);
62 
63 /*
64  \brief It adds an Unique Key to the given dataset type.
65 
66  \param datasetType The target dataset type.
67  \param transactor The transactor to be used to persist the modifications
68 
69  \return A pointer to the created unique key.
70 
71  \pre The dataset type DOES NOT need to be associated to a data source catalog in memory.
72  \pre The dataset type must have an attribute called 'country_name'.
73  \pre The dataset type must have an attribute called 'city_name'.
74 
75  \post The dataset type will have an associated unique key.
76 
77  \exception Exception It throws an exception if something goes wrong.
78  */
79 te::da::UniqueKey* AddUniqueKey(const std::string& datasetname,
80  te::da::DataSourceTransactor* transactor);
81 
82 /*
83  \brief It adds a spatial index to the given dataset type.
84 
85  \param datasetType The target dataset type.
86  \param transactor The transactor to be used to persist the modifications
87 
88  \return A pointer to the created index.
89 
90  \pre The dataset type DOES NOT need to be associated to a data source catalog in memory.
91  \pre The dataset type must have an attribute called 'spatial_data'.
92 
93  \post The dataset type will have an associated index.
94 
95  \exception Exception It throws an exception if something goes wrong.
96  */
97 te::da::Index* AddSpatialIndex(const std::string& datasetname,
98  te::da::DataSourceTransactor* transactor);
99 
100 /*
101  \brief It adds an integer property called 'population' to the given dataset type.
102 
103  \param datasetType The target dataset type.
104  \param transactor The transactor to be used to persist the modifications
105 
106  \return A pointer to the created property.
107 
108  \pre The dataset type DOES NOT need to be associated to a data source catalog in memory.
109  \pre The dataset type must be associated to a data source catalog.
110  \pre The dataset type must not have an attribute called 'population'.
111 
112  \post The dataset type will have an associated property called 'population'.
113 
114  \exception Exception It throws an exception if something goes wrong.
115  */
116 te::dt::SimpleProperty* AddProperty(const std::string& datasetname,
117  te::da::DataSourceTransactor* transactor);
118 
119 /*!
120  \brief This example will print to standard output all information about the datasets stored in the data source.
121 
122  \param ds The data source used to retrieve information about its datasets.
123  */
125 
126 /*!
127  \brief It prints datasets in a given data source.
128  \param ds The data source you want to print its data
129  */
131 
132 /*!
133  \brief It prints the data in a given dataset.
134  \param datasetName the dataset name
135  \param dataset pointer to a dataset. Do not pass NULL.
136 
137  This function will move the dataset to the item before first and return it there after printing.
138 
139  */
140 void PrintDataSet(std::string datasetName, te::da::DataSet* dataset);
141 
142 /*!
143  \brief An example showing how to retrieve data using a spatial filter.
144 
145  \param transactor The transactor to be used to retrieve the data.
146  */
148 
149 /*!
150  \brief An example showing how to retrieve the extent of a DataSet.
151 
152  \param transactor The transactor to be used to retrieve the data.
153  */
155 
156 /*! \brief It loads the data source drivers. */
157 void LoadModules();
158 
159 /*! \brief An example using OGR data source driver to retrieve data from a datafile */
160 void OGRExampleRead();
161 
162 /*! \brief An example using OGR data source driver to persist data to a datafile */
163 void ORGExampleWrite();
164 
165 /*! \brief An example using OGR data source driver to export some ; */
166 void ExportingOGR();
167 
168 /*! \brief An example using PostGIS data source driver. */
169 void PostGISExample();
170 
171 /*! \brief An example using GDAL data source driver. */
172 void GDALExample();
173 
174 /*! \brief Quering a dataset. */
175 void QueryExample();
176 
177 /*! \brief Quering Insert clause. */
178 void QueryInsertExample();
179 
180 /*! \brief This example shows how to copy a given dataset from one data source to another one. */
181 void CopyingData();
182 
183 /*! \brief This example shows how to create DataSet and DataSetType in memory. */
184 void MemoryExample();
185 
186 /*! \brief An example using MySQL data source driver. */
187 void MySQLExample();
188 
189 /*! \brief An example using SQLite data source driver. */
190 void SQLiteExample();
191 
192 /*!
193  \brief It creates a data set in memory.
194 
195  \return It returns a data set in memory.
196 
197  \note The caller is responsible for deleting the returned data set.
198 */
199 te::da::DataSet* CreatingDataSetInMemory(const std::string& datasetName);
200 
201 
203 
204 /*! \brief This example shows how to use the TerraLib Persistence. */
205 void PersistenceExample();
206 
207 /*!
208  \brief It copies a data set to a data source.
209 
210  \param dataSet the dataSet that will be copied to data source.
211  \param dsName the data source name
212  \param dsInfo the data source info
213 */
214 void CopyingDataSetToDataSource(te::da::DataSet* dataSet, const std::string& dsName, std::map<std::string, std::string>& dsInfo);
215 
216 /*!
217  \brief It adds a new data set property and its values.
218 
219  \param dataSet the dataSet that will be added.
220 */
222 
223 /*!
224  \brief It removes a property from the data set type and from the associated data source.
225 
226  \param prop the property that will be removed.
227  \param trans the transactor to be used in the removing.
228 */
229 //void DroppingDataSetTypeProperty(te::dt::Property* prop, te::da::DataSourceTransactor* trans);
230 void DroppingDataSetTypeProperty(const std::string& datasetname, const std::string &propname, te::da::DataSourceTransactor* trans);
231 
232 /*!
233  \brief It removes a data set type from the associated data source.
234 
235  \param dt the dataSetType that will be removed from data source.
236  \param trans the transactor to be used in the removing.
237 */
238 //void DroppingDataSetType(te::da::DataSetType* dt, te::da::DataSourceTransactor* trans);
239 void DroppingDataSetType(const std::string& datasetname, te::da::DataSourceTransactor* trans);
240 
241 /*!
242  \brief It retrieves and prints the capabilities of a given data source.
243 
244  \param ds A valid data source.
245 */
247 
248 /*! \brief DataSet Adapter example. */
249 void DataSetAdapter();
250 
251 /*! \brief ObjectId example. */
252 void ObjectId();
253 
254 void ObjectId_query();
255 
256 void ObjectId3();
257 
258 #endif // __TERRALIB_EXAMPLES_DATAACCESS_INTERNAL_DATAACCESSEXAMPLES_H
void OGRExampleRead()
An example using OGR data source driver to retrieve data from a datafile.
Definition: OGRExample.cpp:13
An atomic property like an integer or double.
void MySQLExample()
An example using MySQL data source driver.
A class that models the description of a dataset.
Definition: DataSetType.h:72
void RetrieveUsingSpatialFilter(te::da::DataSource *ds)
An example showing how to retrieve data using a spatial filter.
void PostGISExample()
An example using PostGIS data source driver.
void QueryExample()
Quering a dataset.
void DroppingDataSetTypeProperty(const std::string &datasetname, const std::string &propname, te::da::DataSourceTransactor *trans)
It removes a property from the data set type and from the associated data source. ...
Forward declarations for the Data Access module.
static te::dt::Date ds(2010, 01, 01)
void LoadModules()
It loads the data source drivers.
An abstract class for data providers like a DBMS, Web Services or a regular file. ...
void PrintDataSourceCapabilities(te::da::DataSource *ds)
It retrieves and prints the capabilities of a given data source.
te::da::UniqueKey * AddUniqueKey(const std::string &datasetname, te::da::DataSourceTransactor *transactor)
void DataSetAdapter()
DataSet Adapter example.
void SQLiteExample()
An example using SQLite data source driver.
te::da::DataSetType * CreateDataSetType(const std::string &datasetname, te::da::DataSetType *dt, te::da::DataSourceTransactor *transactor)
te::da::Index * AddSpatialIndex(const std::string &datasetname, te::da::DataSourceTransactor *transactor)
void ObjectId_query()
void ObjectId()
ObjectId example.
void DataSetGetExtent(te::da::DataSourceTransactor *transactor)
An example showing how to retrieve the extent of a DataSet.
static te::dt::TimeDuration dt(20, 30, 50, 11)
A factory for data sources.
te::da::DataSet * CreatingDataSetInMemory(const std::string &datasetName)
It creates a data set in memory.
te::da::DataSetType * CreateDataSetTypeInMemory(const std::string &datasettypename)
void CopyingData()
This example shows how to copy a given dataset from one data source to another one.
Definition: CopyingData.cpp:14
It describes a unique key (uk) constraint.
Definition: UniqueKey.h:53
A DataSourceTransactor can be viewed as a connection to the data source for reading/writing things in...
void ORGExampleWrite()
An example using OGR data source driver to persist data to a datafile.
Definition: OGRExample.cpp:65
void CopyingDataSetToDataSource(te::da::DataSet *dataSet, const std::string &dsName, std::map< std::string, std::string > &dsInfo)
It copies a data set to a data source.
void GDALExample()
An example using GDAL data source driver.
void PrintCatalog(te::da::DataSource *ds)
This example will print to standard output all information about the datasets stored in the data sour...
This file contains forward declarations for the Data Type module of TerraLib.
void ExportingOGR()
An example using OGR data source driver to export some ;.
A dataset is the unit of information manipulated by the data access module of TerraLib.
It describes a primary key (pk) constraint.
Definition: PrimaryKey.h:52
te::da::PrimaryKey * AddPrimaryKey(const std::string &datasetname, te::da::DataSourceTransactor *transactor)
te::da::DataSet * CreatingDataSetInMemoryGivingDt(te::da::DataSetType *dt)
void AddingDataSetPropertyValues(te::da::DataSet *ds)
It adds a new data set property and its values.
void PrintDataSets(te::da::DataSource *ds)
It prints datasets in a given data source.
void DroppingDataSetType(const std::string &datasetname, te::da::DataSourceTransactor *trans)
It removes a data set type from the associated data source.
te::dt::SimpleProperty * AddProperty(const std::string &datasetname, te::da::DataSourceTransactor *transactor)
This file contains include headers for the TerraLib Common Runtime module.
This file contains include headers for the Vector Geometry model of TerraLib.
This file contains include headers for the Data Access module of TerraLib.
void ObjectId3()
void MemoryExample()
This example shows how to create DataSet and DataSetType in memory.
void QueryInsertExample()
Quering Insert clause.
It describes an index associated to a DataSetType.
void PrintDataSet(std::string datasetName, te::da::DataSet *dataset)
It prints the data in a given dataset.
Definition: PrintDataSet.cpp:7
void PersistenceExample()
This example shows how to use the TerraLib Persistence.