Differences
This shows you the differences between two versions of the page.
Next revision | Previous revision | ||
wiki:documentation:mini_curso:dataaccess [2016/01/19 12:11] gribeiro created |
wiki:documentation:mini_curso:dataaccess [2016/01/20 15:56] gribeiro |
||
---|---|---|---|
Line 1: | Line 1: | ||
- | ====== Data Access ====== | + | ====== Data Access ====== |
- | **1.** Script CMake: | + | **1.** [[:wiki:documentation:devguide:data_access_module|Link para documentação do módulo Data Access]]. |
- | <code cmake> | + | |
+ | **2.** Script CMake: | ||
+ | <file cmake CMakeLists.txt> | ||
cmake_minimum_required(VERSION 2.8.12) | cmake_minimum_required(VERSION 2.8.12) | ||
Line 32: | Line 34: | ||
${BOOST_SYSTEM_LIBRARY}) | ${BOOST_SYSTEM_LIBRARY}) | ||
- | </code> | + | </file> |
- | **2.** Código: | + | **3.** Código: |
- | <code cpp> | + | <file cpp main.cpp> |
// TerraLib | // TerraLib | ||
#include <terralib/common.h> | #include <terralib/common.h> | ||
+ | #include <terralib/dataaccess.h> | ||
#include <terralib/plugin.h> | #include <terralib/plugin.h> | ||
Line 67: | Line 70: | ||
} | } | ||
+ | void PrintDataSet(std::string datasetName, te::da::DataSet* dataset) | ||
+ | { | ||
+ | if(dataset == 0) | ||
+ | { | ||
+ | std::cout << "The informed dataset is NULL!" << std::endl; | ||
+ | return; | ||
+ | } | ||
+ | |||
+ | // this will be used just to count the items in the dataset | ||
+ | int item = 0; | ||
+ | |||
+ | // traverse the dataset and print each dataset item | ||
+ | std::cout << "DATASET: " << datasetName; | ||
+ | |||
+ | while(dataset->moveNext()) | ||
+ | { | ||
+ | std::cout << std::endl << "ITEM NUMBER: " << item++ << " =======================" << std::endl; | ||
+ | |||
+ | for(std::size_t i = 0; i < dataset->getNumProperties(); ++i) | ||
+ | { | ||
+ | std::cout << dataset->getPropertyName(i) << ": " ; | ||
+ | |||
+ | if(dataset->isNull(i)) | ||
+ | { | ||
+ | std::cout << std::endl; | ||
+ | continue; | ||
+ | } | ||
+ | |||
+ | std::cout << dataset->getAsString(i) << std::endl; | ||
+ | } | ||
+ | } | ||
+ | } | ||
+ | |||
+ | void ReadShapefile() | ||
+ | { | ||
+ | std::unique_ptr<te::da::DataSource> ds = te::da::DataSourceFactory::make("OGR"); | ||
+ | |||
+ | std::map<std::string, std::string> connInfo; | ||
+ | connInfo["URI"] = "/home/terralib5/curso/data/shp/munic_2001.shp"; | ||
+ | |||
+ | ds->setConnectionInfo(connInfo); | ||
+ | |||
+ | ds->open(); | ||
+ | |||
+ | std::cout << "Datasource is opened? " | ||
+ | << std::boolalpha | ||
+ | << ds->isOpened() << std::endl; | ||
+ | |||
+ | // check point: what can be done with this datasource | ||
+ | //PrintDataSourceCapabilities(ds.get()); | ||
+ | |||
+ | // check point: retrieving data from the datasource | ||
+ | std::cout << "\nDatasource has " | ||
+ | << ds->getNumberOfDataSets() | ||
+ | << " datasources" << std::endl; | ||
+ | |||
+ | std::vector<std::string> dsets = ds->getDataSetNames(); | ||
+ | |||
+ | for (size_t i=0; i<ds->getNumberOfDataSets(); ++i) | ||
+ | std::cout << '[' << (i + 1) | ||
+ | << "]: " | ||
+ | << dsets[i] | ||
+ | << std::endl; | ||
+ | |||
+ | // check point: retrieving the data from a dataset of the datasource | ||
+ | if(ds->getNumberOfDataSets() == 0) | ||
+ | return; | ||
+ | |||
+ | std::unique_ptr<te::da::DataSet> dataset = ds->getDataSet(dsets[0]); | ||
+ | |||
+ | PrintDataSet(dsets[0], dataset.get()); | ||
+ | } | ||
int main(int argc, char* argv[]) | int main(int argc, char* argv[]) | ||
Line 73: | Line 148: | ||
| | ||
LoadModules(); | LoadModules(); | ||
+ | |||
+ | ReadShapefile(); | ||
Line 81: | Line 158: | ||
return EXIT_SUCCESS; | return EXIT_SUCCESS; | ||
} | } | ||
+ | </file> | ||
+ | |||
+ | **4.** Opções do CMake: | ||
+ | <code cmake> | ||
+ | -DCMAKE_BUILD_TYPE:STRING="Debug" | ||
+ | |||
+ | -DCMAKE_PREFIX_PATH:PATH="/home/terralib5/mylibs;/home/terralib5/mylibs/terralib5/lib/cmake" | ||
</code> | </code> | ||
- | **3.** Opções do CMake: | + | **5.** Variável de ambiente para execução: |
+ | <code bash> | ||
+ | LD_LIBRARY_PATH=/home/terralib5/mylibs/lib/:/home/terralib5/mylibs/gdal2/lib:/home/terralib5/mylibs/pgsql/lib:/home/terralib5/mylibs/terralib5/lib | ||
+ | </code> |