MemoryExample.cpp
Go to the documentation of this file.
1 // TerraLib
2 #include "../Config.h"
3 
4 // Examples
5 #include "DataAccessExamples.h"
6 
7 // STL
8 #include <iostream>
9 
10 
12 {
13  try
14  {
15  // a folder that contains some auxiliary data
16  std::string data_dir = TERRALIB_DATA_DIR;
17 
18  // creates a datasource in memory
19  std::unique_ptr<te::da::DataSource> dsMem = te::da::DataSourceFactory::make("MEM", "memory:");
20 
21  // creates a datasettype, named "SoilMeasures", in the memory datasource
22  std::string dsName("SoilMeasures");
24  std::map<std::string, std::string> options;
25  dsMem->createDataSet(dType, options); // no specific options
26 
27  // check point: datasettype was created and can be retrieved from datasource
28  std::unique_ptr<te::da::DataSetType> dType_ret = dsMem->getDataSetType(dsName);
29  std::cout << std::endl << "DATASETTYPE in memory has been created" << std::endl;
30 
31  // creates a dataset in memory that follows the previous create
33 
34  // check point: dataset is correct and populated
35  std::cout << std::endl << "DATASET " << dsName << " in memory has been created:" << std::endl;
36  PrintDataSet(dsName, dSet);
37 
38  // adds the dataset to datasource
39  dsMem->add(dsName,dSet, options);
40 
41  // check point: retrieve the dataset from datasource
42  std::unique_ptr<te::da::DataSet> ds_ret = dsMem->getDataSet(dsName);
43  std::cout << std::endl << "DATASET " << dsName << " was inserted in retrieved from datasource:" << std::endl;
44  PrintDataSet(dsName, ds_ret.get());
45 
46  delete dSet; // releases the dataset created
47  }
48  catch(const std::exception& e)
49  {
50  std::cout << std::endl << "An exception has occurred in Memory Example: " << e.what() << std::endl;
51  return;
52  }
53  catch(...)
54  {
55  std::cout << std::endl << "An unexpected exception has occurred in Memory Example!" << std::endl;
56  return;
57  }
58 }
59 
static std::unique_ptr< DataSource > make(const std::string &driver, const te::core::URI &connInfo)
A class that models the description of a dataset.
Definition: DataSetType.h:72
te::da::DataSetType * CreateDataSetTypeInMemory(const std::string &datasettypename)
void MemoryExample()
This example shows how to create DataSet and DataSetType in memory.
te::da::DataSet * CreatingDataSetInMemoryGivingDt(te::da::DataSetType *dt)
Examples on how to access/manipulate DataSources in TerraLib.
A dataset is the unit of information manipulated by the data access module of TerraLib.
void PrintDataSet(std::string datasetName, te::da::DataSet *dataset)
It prints the data in a given dataset.
Definition: PrintDataSet.cpp:7