All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
VectorizationWizard.cpp
Go to the documentation of this file.
1 /* Copyright (C) 2011-2012 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 //Terralib
21 #include "../../../dataaccess/datasource/DataSourceInfoManager.h"
22 #include "../../../dataaccess/utils/Utils.h"
23 #include "../../widgets/layer/utils/DataSet2Layer.h"
24 #include "../help/HelpPushButton.h"
25 #include "../layer/search/LayerSearchWidget.h"
26 #include "../layer/search/LayerSearchWizardPage.h"
27 #include "VectorizationWizard.h"
29 
30 // BOOST
31 #include <boost/algorithm/string.hpp>
32 #include <boost/filesystem.hpp>
33 #include <boost/lexical_cast.hpp>
34 #include <boost/uuid/random_generator.hpp>
35 #include <boost/uuid/uuid_io.hpp>
36 
38 QWizard(parent)
39 {
40  this->setWizardStyle(QWizard::ModernStyle);
41  this->setWindowTitle(tr("Vectorization"));
42 
43  this->setOption(QWizard::HaveHelpButton, true);
44  this->setOption(QWizard::HelpButtonOnRight, false);
45 
47 
48  this->setButton(QWizard::HelpButton, helpButton);
49 
50  helpButton->setPageReference("plugins/rp/rp_vectorization.html");
51 
52  addPages();
53 }
54 
56 {
57 }
58 
60 {
61  if(currentPage() == m_layerSearchPage.get())
62  {
63  std::list<te::map::AbstractLayerPtr> list = m_layerSearchPage->getSearchWidget()->getSelecteds();
64 
65  if(list.empty() == false)
66  {
67  te::map::AbstractLayerPtr l = *list.begin();
68 
69  m_vectorPage->setLayer(l);
70  }
71 
72  return m_layerSearchPage->isComplete();
73  }
74  else if(currentPage() == m_vectorPage.get())
75  {
76  return execute();
77  }
78 
79  return true;
80 }
81 
82 void te::qt::widgets::VectorizationWizard::setList(std::list<te::map::AbstractLayerPtr> &layerList)
83 {
84  m_layerSearchPage->getSearchWidget()->setList(layerList);
85  m_layerSearchPage->getSearchWidget()->filterOnlyByRaster();
86 }
87 
89 {
90  return m_outputLayer;
91 }
92 
94 {
95  m_layerSearchPage.reset(new LayerSearchWizardPage(this));
96  addPage(m_layerSearchPage.get());
97 
98  m_vectorPage.reset(new VectorizationWizardPage(this));
99  addPage(m_vectorPage.get());
100 }
101 
103 {
104  //check output datasource parameters
105  te::da::DataSourceInfoPtr outDSInfo;
106 
107  std::string outputdataset = m_vectorPage->getLayerName();
108 
109  bool toFile = m_vectorPage->outputDataSourceToFile();
110 
111  if(toFile)
112  {
113  boost::filesystem::path uri(m_vectorPage->getRepositoryName());
114 
115  std::size_t idx = outputdataset.find(".");
116  if(idx != std::string::npos)
117  outputdataset = outputdataset.substr(0,idx);
118 
119  std::map<std::string, std::string> dsinfo;
120  dsinfo["URI"] = uri.string();
121 
122  // let's include the new datasource in the managers
123  boost::uuids::basic_random_generator<boost::mt19937> gen;
124  boost::uuids::uuid u = gen();
125  std::string id = boost::uuids::to_string(u);
126 
128  ds->setConnInfo(dsinfo);
129  ds->setTitle(uri.stem().string());
130  ds->setAccessDriver("OGR");
131  ds->setType("OGR");
132  ds->setDescription(uri.string());
133  ds->setId(id);
134 
136  outDSInfo = ds;
137  }
138  else
139  {
140  outDSInfo = m_vectorPage->getDataSourceInfo();
141  }
142 
143  //input parameters
144  std::auto_ptr<te::rst::Raster> raster = m_vectorPage->getRaster();
145  unsigned int band = m_vectorPage->getBand();
146  unsigned int maxGeom = 0;
147  m_vectorPage->hasMaxGeom(maxGeom);
148 
149  //output parameters
150  std::vector<te::gm::Geometry*> geomVec;
151 
152  //run operation
153  raster->vectorize(geomVec, band, maxGeom);
154 
155  //create output layer
156  te::da::DataSourcePtr outDataSource = te::da::GetDataSource(outDSInfo->getId());
157 
158  te::qt::widgets::DataSet2Layer converter(outDSInfo->getId());
159 
160  te::da::DataSetTypePtr dt(outDataSource->getDataSetType(outputdataset).release());
161 
162  m_outputLayer = converter(dt);
163 
164  return true;
165 }
166 
TEDATAACCESSEXPORT DataSourcePtr GetDataSource(const std::string &datasourceId, const bool opened=true)
Search for a data source with the informed id in the DataSourceManager.
Definition: Utils.cpp:259
boost::shared_ptr< DataSetType > DataSetTypePtr
Definition: DataSetType.h:653
boost::shared_ptr< DataSource > DataSourcePtr
Definition: DataSource.h:1435
void setPageReference(const QString &ref)
Sets the documentation page reference.
static DataSourceInfoManager & getInstance()
It returns a reference to the singleton instance.
void setList(std::list< te::map::AbstractLayerPtr > &layerList)
Push button that uses te::qt::widgets::HelpManager on its mouse pressed implementation.
A class that represents a data source component.
te::map::AbstractLayerPtr getOutputLayer()
boost::intrusive_ptr< AbstractLayer > AbstractLayerPtr
boost::shared_ptr< DataSourceInfo > DataSourceInfoPtr