21 #include "../../../common/progress/ProgressManager.h"
22 #include "../../../dataaccess/datasource/DataSource.h"
23 #include "../../../dataaccess/datasource/DataSourceInfoManager.h"
24 #include "../../../dataaccess/datasource/DataSourceInfoManager.h"
25 #include "../../../dataaccess/datasource/DataSourceManager.h"
26 #include "../../../dataaccess/utils/Utils.h"
27 #include "../../../datatype/SimpleProperty.h"
28 #include "../../../geometry/GeometryProperty.h"
29 #include "../../../memory/DataSet.h"
30 #include "../../../memory/DataSetItem.h"
31 #include "../../widgets/layer/utils/DataSet2Layer.h"
32 #include "../help/HelpPushButton.h"
33 #include "../layer/search/LayerSearchWidget.h"
34 #include "../layer/search/LayerSearchWizardPage.h"
35 #include "../progress/ProgressViewerDialog.h"
40 #include <boost/algorithm/string.hpp>
41 #include <boost/filesystem.hpp>
42 #include <boost/lexical_cast.hpp>
43 #include <boost/uuid/random_generator.hpp>
44 #include <boost/uuid/uuid_io.hpp>
47 #include <QApplication>
48 #include <QMessageBox>
53 this->setWizardStyle(QWizard::ModernStyle);
54 this->setWindowTitle(tr(
"Vectorization"));
56 this->setOption(QWizard::HaveHelpButton,
true);
57 this->setOption(QWizard::HelpButtonOnRight,
false);
61 this->setButton(QWizard::HelpButton, helpButton);
74 if(currentPage() == m_layerSearchPage.get())
76 std::list<te::map::AbstractLayerPtr> list = m_layerSearchPage->getSearchWidget()->getSelecteds();
78 if(list.empty() ==
false)
82 m_vectorPage->setLayer(l);
85 return m_layerSearchPage->isComplete();
87 else if(currentPage() == m_vectorPage.get())
97 m_layerSearchPage->getSearchWidget()->setList(layerList);
98 m_layerSearchPage->getSearchWidget()->filterOnlyByRaster();
103 return m_outputLayer;
109 addPage(m_layerSearchPage.get());
112 addPage(m_vectorPage.get());
118 std::string outputdataset = m_vectorPage->getLayerName();
120 if(outputdataset.empty())
122 QMessageBox::warning(
this, tr(
"Vectorizer"), tr(
"Output dataset name not defined."));
126 std::string uriStr = m_vectorPage->getRepositoryName();
130 QMessageBox::warning(
this, tr(
"Vectorizer"), tr(
"Output repository name not defined."));
137 bool toFile = m_vectorPage->outputDataSourceToFile();
141 boost::filesystem::path uri(uriStr);
143 std::size_t idx = outputdataset.find(
".");
144 if(idx != std::string::npos)
145 outputdataset = outputdataset.substr(0,idx);
147 std::map<std::string, std::string> dsinfo;
148 dsinfo[
"URI"] = uri.string();
151 boost::uuids::basic_random_generator<boost::mt19937> gen;
152 boost::uuids::uuid u = gen();
153 std::string
id = boost::uuids::to_string(u);
156 ds->setConnInfo(dsinfo);
157 ds->setTitle(uri.stem().string());
158 ds->setAccessDriver(
"OGR");
160 ds->setDescription(uri.string());
168 outDSInfo = m_vectorPage->getDataSourceInfo();
172 std::auto_ptr<te::rst::Raster> raster = m_vectorPage->getRaster();
173 unsigned int band = m_vectorPage->getBand();
174 unsigned int maxGeom = 0;
175 m_vectorPage->hasMaxGeom(maxGeom);
178 std::vector<te::gm::Geometry*> geomVec;
184 QApplication::setOverrideCursor(Qt::WaitCursor);
189 raster->vectorize(geomVec, band, maxGeom);
191 catch(
const std::exception& e)
193 QMessageBox::warning(
this, tr(
"Vectorizer"), e.what());
197 QApplication::restoreOverrideCursor();
203 QMessageBox::warning(
this, tr(
"Vectorizer"), tr(
"An exception has occurred!"));
207 QApplication::restoreOverrideCursor();
214 QApplication::restoreOverrideCursor();
219 std::auto_ptr<te::da::DataSetType> dsType = createDataSetType(outputdataset, raster->getSRID());
221 std::auto_ptr<te::mem::DataSet> dsMem = createDataSet(dsType.get(), geomVec);
225 saveDataSet(dsMem.get(), dsType.get(), ds, outputdataset);
234 m_outputLayer = converter(dt);
236 catch(
const std::exception& e)
238 QMessageBox::warning(
this, tr(
"Vectorizer"), e.what());
244 QMessageBox::warning(
this, tr(
"Vectorizer"), tr(
"An exception has occurred saving geometries!"));
258 dsType->add(idProperty);
262 dsType->add(geomProperty);
265 std::string pkName =
"pk_id";
266 pkName+=
"_" + dataSetName;
277 for(std::size_t t = 0; t < geoms.size(); ++t)
299 std::map<std::string, std::string> options;
301 ds->createDataSet(dsType, options);
303 ds->add(dataSetName, dataSet, options);
TEDATAACCESSEXPORT DataSourcePtr GetDataSource(const std::string &datasourceId, const bool opened=true)
Search for a data source with the informed id in the DataSourceManager.
void add(te::dt::Property *p)
It adds a property to the list of properties of the primary key.
void setGeometry(std::size_t i, te::gm::Geometry *value)
It sets the value of the i-th property.
boost::shared_ptr< DataSetType > DataSetTypePtr
An atomic property like an integer or double.
boost::shared_ptr< DataSource > DataSourcePtr
A class that models the description of a dataset.
void setInt32(std::size_t i, boost::int32_t value)
It sets the value of the i-th property.
Implementation of a random-access dataset class for the TerraLib In-Memory Data Access driver...
void removeViewer(int viewerId)
Dettach a progress viewer.
static DataSourceInfoManager & getInstance()
It returns a reference to the singleton instance.
bool moveBeforeFirst()
It moves the internal pointer to a position before the first item in the collection.
An implementation of the DatasetItem class for the TerraLib In-Memory Data Access driver...
int addViewer(AbstractProgressViewer *apv)
Attach a progress viewer.
It describes a primary key (pk) constraint.
A class that represents a data source component.
boost::intrusive_ptr< AbstractLayer > AbstractLayerPtr
boost::shared_ptr< DataSourceInfo > DataSourceInfoPtr