WCSLayerSelector.cpp
Go to the documentation of this file.
1 #include "WCSLayerSelector.h"
2 
3 // TerraLib
4 #include "../../../../core/translator/Translator.h"
5 #include "../../../../dataaccess/datasource/DataSource.h"
6 #include "../../../../dataaccess/datasource/DataSourceManager.h"
7 #include "../../../../dataaccess/datasource/DataSourceInfoManager.h"
8 #include "../../../../maptools/DataSetLayer.h"
9 #include "../../../../qt/widgets/dataset/selector/DataSetSelectorDialog.h"
10 #include "../../../../qt/widgets/layer/utils/DataSet2Layer.h"
11 #include "../dataaccess/DataSource.h"
12 #include "../client/WCSClient.h"
13 #include "../client/DataTypes.h"
14 
15 #include <memory>
16 
17 // BOOST
18 #include <boost/uuid/random_generator.hpp>
19 #include <boost/uuid/uuid_io.hpp>
20 
22  : te::qt::widgets::AbstractLayerSelector(parent, f)
23 {
24 
25 }
26 
28 
29 void te::ws::ogc::wcs::qt::WCSLayerSelector::set(const std::list<te::da::DataSourceInfoPtr> &datasources)
30 {
31  m_datasources = datasources;
32 }
33 
34 std::list<te::map::AbstractLayerPtr> te::ws::ogc::wcs::qt::WCSLayerSelector::getLayers()
35 {
36  std::list<te::map::AbstractLayerPtr> layers;
37  for(std::list<te::da::DataSourceInfoPtr>::iterator it = m_datasources.begin(); it != m_datasources.end(); ++it)
38  {
39  te::da::DataSourcePtr datasource = te::da::DataSourceManager::getInstance().find((*it)->getId());
40  if(datasource.get() == nullptr)
41  {
42  datasource = te::da::DataSourceManager::getInstance().get((*it)->getId(), (*it)->getAccessDriver(), (*it)->getConnInfo());
43  //if(datasource.get() == 0)
44  //throw Exception(TE_TR("Could not retrieve the data source instance!"));
45  }
46  if(!datasource->isOpened())
47  datasource->open();
48 
49  te::ws::ogc::wcs::da::DataSource* wcsDataSource = dynamic_cast<te::ws::ogc::wcs::da::DataSource*>(datasource.get());
50 
51  std::shared_ptr<te::ws::ogc::WCSClient> client = wcsDataSource->getWCSClient();
52 
53  std::unique_ptr<te::qt::widgets::DataSetSelectorDialog> ldialog(new te::qt::widgets::DataSetSelectorDialog(static_cast<QWidget*>(parent())));
54  ldialog->set(*it, true);
55  int retval = ldialog->exec();
56  if(retval == QDialog::Rejected)
57  continue;
58  std::list<te::da::DataSetTypePtr> datasets = ldialog->getCheckedDataSets();
59 
60  std::list<te::da::DataSetTypePtr>::iterator itDataset = datasets.begin();
61 
62  for(;itDataset != datasets.end(); ++itDataset)
63  {
65  request.coverageID = (*itDataset)->getName();
66  request.format = "image/tiff";
67 
68  //create data source for coverageDiskPath
69  boost::uuids::basic_random_generator<boost::mt19937> gen;
70  boost::uuids::uuid u = gen();
71  std::string id = boost::uuids::to_string(u);
72 
74  task.setTotalSteps(0);
75 
76  std::string coverageDiskPath = client->getCoverage(request, &task);
77 
78  task.setMessage("Download Done.");
79 
81  dsInfo->setConnInfo("file://" + coverageDiskPath);
82  dsInfo->setTitle(coverageDiskPath);
83  dsInfo->setAccessDriver("GDAL");
84  dsInfo->setType("GDAL");
85  dsInfo->setDescription(coverageDiskPath);
86  dsInfo->setId(id);
87 
89  te::da::DataSourcePtr ds = te::da::DataSourceManager::getInstance().get(dsInfo->getId(), dsInfo->getType(), dsInfo->getConnInfo());
90  std::string dataSetName = ds->getDataSetNames()[0];
91 
92  te::qt::widgets::DataSet2Layer converter(ds->getId());
93  te::da::DataSetTypePtr dt(ds->getDataSetType(dataSetName).release());
94  te::map::AbstractLayerPtr layer = converter(dt);
95 
96  layers.push_back(layer);
97  }
98  }
99 
100  return layers;
101 }
Implementation of the data source for the WCS driver.
void setMessage(const std::string &message)
Set the task message.
A simple widget that allows the selection of datasets from a given WCS server.
boost::shared_ptr< DataSetType > DataSetTypePtr
Definition: DataSetType.h:653
boost::shared_ptr< DataSource > DataSourcePtr
This class can be used to inform the progress of a task.
Definition: TaskProgress.h:53
static te::dt::Date ds(2010, 01, 01)
void setTotalSteps(int value)
Set the task total stepes.
std::shared_ptr< te::ws::ogc::WCSClient > getWCSClient() const
static DataSourceManager & getInstance()
It returns a reference to the singleton instance.
URI C++ Library.
Definition: Attributes.h:37
static te::dt::TimeDuration dt(20, 30, 50, 11)
A struct to set the parameters of requested coverage.
std::list< te::da::DataSourceInfoPtr > m_datasources
A class that represents a data source component.
std::list< te::map::AbstractLayerPtr > getLayers()
void set(const std::list< te::da::DataSourceInfoPtr > &datasources)
WCSLayerSelector(QWidget *parent=0, Qt::WindowFlags f=0)
boost::intrusive_ptr< AbstractLayer > AbstractLayerPtr
boost::shared_ptr< DataSourceInfo > DataSourceInfoPtr