src/terralib/qt/plugins/datasource/pgisRaster/Utils.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 terralib/qt/plugins/datasource/gdal/Utils.cpp
22 
23 \brief Utility functions for the GDAL data source widget plugin.
24 */
25 
26 // TerraLib
27 #include "../../../../core/logger/Logger.h"
28 #include "../../../../core/translator/Translator.h"
29 #include "../../../../dataaccess/dataset/DataSetType.h"
30 #include "../../../../dataaccess/datasource/DataSourceManager.h"
31 #include "../../../../dataaccess/utils/Utils.h"
32 #include "../../../../maptools/AbstractLayer.h"
33 #include "../../../../srs/SpatialReferenceSystemManager.h"
34 #include "../../../widgets/layer/utils/DataSet2Layer.h"
35 #include "../../../af/ApplicationController.h"
36 #include "../../../af/events/LayerEvents.h"
37 #include "Utils.h"
38 
39 // Qt
40 #include <QApplication>
41 #include <QDir>
42 #include <QFileInfo>
43 #include <QMessageBox>
44 
45 // STL
46 #include <cassert>
47 
48 // Boost
49 #include <boost/uuid/random_generator.hpp>
50 #include <boost/uuid/uuid_io.hpp>
51 #include <boost/filesystem.hpp>
52 
54 {
55  std::list<te::map::AbstractLayerPtr> layers;
56 
57  for (std::size_t t = 0; t < vec.size(); ++t)
58  {
59  PostGISRasterInfo info = vec[t];
60 
61  //generate id
62  boost::uuids::basic_random_generator<boost::mt19937> gen;
63  boost::uuids::uuid u = gen();
64  std::string id = boost::uuids::to_string(u);
65 
66  //create datasource info
68 
69  dsInfo->setAccessDriver("GDAL");
70  dsInfo->setConnInfo(info.m_uri);
71  dsInfo->setDescription("A PostGIS Raster");
72  dsInfo->setId(id);
73  dsInfo->setTitle(info.m_tableName);
74  dsInfo->setType("GDALPOSTGISRASTER");
75 
77  dsInfo = te::da::DataSourceInfoManager::getInstance().getByConnInfo(dsInfo->getConnInfoAsString());
78 
79  //create layers
80  te::da::DataSourcePtr ds = te::da::DataSourceManager::getInstance().get(dsInfo->getId(), dsInfo->getAccessDriver(), dsInfo->getConnInfo());
81 
82  te::da::DataSetTypePtr dataSetType = ds->getDataSetType(info.m_tableName);
83 
84  try
85  {
86  te::qt::widgets::DataSet2Layer ds2layer(dsInfo->getId());
87  te::map::AbstractLayerPtr l = ds2layer(dataSetType);
88 
89  layers.push_back(l);
90  }
91  catch (std::exception&)
92  {
93  QMessageBox::warning(nullptr, TE_TR("PostGIS Raster"), TE_TR("There were issues while reading the layer from the requested PostGIS Raster."));
94  }
95  }
96 
97  te::map::AbstractLayerPtr parentLayer(nullptr);
98  te::qt::af::evt::LayersAdded added(layers, parentLayer);
100 }
boost::shared_ptr< DataSetType > DataSetTypePtr
Definition: DataSetType.h:653
boost::shared_ptr< DataSource > DataSourcePtr
This event signals that a list of layers have been created.
Definition: LayerEvents.h:95
static te::dt::Date ds(2010, 01, 01)
#define TE_TR(message)
It marks a string in order to get translated.
Definition: Translator.h:242
static DataSourceInfoManager & getInstance()
It returns a reference to the singleton instance.
Utility functions for the data access module.
A class that represents a data source component.
boost::intrusive_ptr< AbstractLayer > AbstractLayerPtr
boost::shared_ptr< DataSourceInfo > DataSourceInfoPtr