CopyDataSet.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 examples/ado/CopyDataSet.cpp
22 
23  \brief It copy a DataSet
24 */
25 
26 // Example
27 #include "ADOExamples.h"
28 
29 // TerraLib
30 #include <terralib/common.h>
33 
34 // STL
35 #include <iostream>
36 
37 void CreateDataSource(std::string name)
38 {
39  // Set the minimum server connection information needed to connect to the database server
40  std::string connInfo("file://");
41  std::string data_dir = TERRALIB_DATA_DIR;
42  std::string aux("");
43 
44  std::cout << "Inform the user to access your Microsoft Access database (ENTER if there is none): ";
45  std::getline(std::cin, aux);
46  connInfo += aux.empty() ? "" : aux + ":";
47 
48  std::cout << "Inform the Password to access Microsoft Access database (ENTER if there is none): ";
49  std::getline(std::cin, aux);
50  connInfo += aux.empty() ? "" : aux + "@";
51 
52  std::cout << "Inform the location of your Microsoft Access database (ENTER to accept default \'" << (data_dir + "/ado/ADODataSource.mdb") << "\'): ";
53  std::getline(std::cin, aux);
54  if (!aux.empty())
55  connInfo += aux;
56  else
57  connInfo += data_dir + "/ado/ADODataSource.mdb";
58 
59  #ifdef _M_IX86
60  connInfo += "?&PROVIDER=Microsoft.Jet.OLEDB.4.0";
61  #else
62  connInfo += "?&PROVIDER=Microsoft.ACE.OLEDB.12.0";
63  #endif
64 
65  std::unique_ptr<te::da::DataSource> outDs = te::da::DataSource::create("ADO", connInfo);
66 }
67 
68 void Copy(std::string dataSetName, std::unique_ptr<te::da::DataSource> inDs, te::da::DataSource* outDs)
69 {
70  std::unique_ptr<te::da::DataSetType> inDst = inDs->getDataSetType(dataSetName);
71 
72  std::unique_ptr<te::da::DataSet> inDset = inDs->getDataSet(dataSetName);
73 
74  std::map<std::string, std::string> options;
75 
76  inDset->moveFirst();
77 
78  te::da::Create(outDs, inDst.get(), inDset.get(), options);
79 }
80 
82 {
83  // let's take the input dataset from a shape file
84  std::string connInfo("file://");
85  std::string data_dir = TERRALIB_DATA_DIR;
86 
87  std::string aux("");
88  std::cout << "Inform the location of your data source (ENTER to accept default \'" << (data_dir + "/shape/poligono_unico.shp") << "\'): ";
89  std::getline(std::cin, aux);
90  if (!aux.empty())
91  connInfo += aux;
92  else
93  connInfo += data_dir + "/shape/poligono_unico.shp";
94 
95  std::unique_ptr<te::da::DataSource> inDs = te::da::DataSourceFactory::make("OGR", connInfo);
96  inDs->open();
97 
98  if(!aux.empty())
99  Copy(aux, std::move(inDs), ds);
100  else
101  Copy("poligono_unico", std::move(inDs), ds);
102 }
static std::unique_ptr< DataSource > create(const std::string &dsType, const std::string &connInfo)
It creates a new repository for a data source.
static std::unique_ptr< DataSource > make(const std::string &driver, const te::core::URI &connInfo)
Examples that show how to access/manipulate an ADO data source.
static te::dt::Date ds(2010, 01, 01)
An abstract class for data providers like a DBMS, Web Services or a regular file. ...
void Copy(std::string dataSetName, std::unique_ptr< te::da::DataSource > inDs, te::da::DataSource *outDs)
Definition: CopyDataSet.cpp:68
TEDATAACCESSEXPORT void Create(DataSource *ds, DataSetType *dt, DataSet *d, std::size_t limit=0)
It creates the dataset definition in a data source and then fill it with data from the input dataset...
A factory for data sources.
Utility functions for the data access module.
void CreateDataSource(std::string name)
Definition: CopyDataSet.cpp:37
This file contains include headers for the TerraLib Common Runtime module.
void CopyFromShapeFile(te::da::DataSource *ds)
It copies a shapefile to the given datasource.
Definition: CopyDataSet.cpp:81