27 #include "../../common/progress/ProgressManager.h"
28 #include "../../common/Logger.h"
29 #include "../../common/Translator.h"
30 #include "../../common/STLUtils.h"
31 #include "../../dataaccess/dataset/DataSetType.h"
32 #include "../../dataaccess/dataset/ObjectIdSet.h"
33 #include "../../dataaccess/datasource/DataSourceCapabilities.h"
34 #include "../../dataaccess/datasource/DataSourceInfo.h"
35 #include "../../dataaccess/datasource/DataSourceInfoManager.h"
36 #include "../../dataaccess/datasource/DataSourceFactory.h"
37 #include "../../dataaccess/datasource/DataSourceManager.h"
38 #include "../../dataaccess/utils/Utils.h"
39 #include "../../datatype/Enums.h"
40 #include "../../datatype/Property.h"
41 #include "../../geometry/GeometryProperty.h"
42 #include "../../maptools/AbstractLayer.h"
43 #include "../../qt/af/Utils.h"
44 #include "../../qt/widgets/datasource/selector/DataSourceSelectorDialog.h"
45 #include "../../qt/widgets/layer/utils/DataSet2Layer.h"
46 #include "../../qt/widgets/progress/ProgressViewerDialog.h"
47 #include "../Config.h"
48 #include "../Exception.h"
49 #include "../LineToPolygonMemory.h"
50 #include "../LineToPolygonOp.h"
51 #include "../LineToPolygonQuery.h"
53 #include "ui_LineToPolygonDialogForm.h"
56 #include <QFileDialog>
57 #include <QMessageBox>
61 #include <boost/algorithm/string.hpp>
62 #include <boost/filesystem.hpp>
63 #include <boost/uuid/random_generator.hpp>
64 #include <boost/uuid/uuid_io.hpp>
68 m_ui(new Ui::LineToPolygonDialogForm),
77 m_ui->m_imgLabel->setPixmap(QIcon::fromTheme(
"vp-line-polygon-hint").pixmap(112,48));
78 m_ui->m_targetDatasourceToolButton->setIcon(QIcon::fromTheme(
"datasource"));
90 m_ui->m_helpPushButton->setNameSpace(
"dpi.inpe.br.plugins");
102 std::list<te::map::AbstractLayerPtr>::iterator it = m_layers.begin();
104 while(it != m_layers.end())
106 std::auto_ptr<te::map::LayerSchema> layerSchema = it->get()->getSchema();
119 m_ui->m_layersComboBox->addItem(QString(it->get()->getTitle().c_str()), QVariant(it->get()->getId().c_str()));
132 std::list<te::map::AbstractLayerPtr>::iterator it = m_layers.begin();
134 std::string layerID = m_ui->m_layersComboBox->itemData(index, Qt::UserRole).toString().toStdString();
136 while(it != m_layers.end())
138 if(layerID == it->get()->getId().c_str())
141 m_selectedLayer = selectedLayer;
151 m_ui->m_newLayerNameLineEdit->clear();
152 m_ui->m_newLayerNameLineEdit->setEnabled(
true);
156 std::list<te::da::DataSourceInfoPtr> dsPtrList = dlg.
getSelecteds();
158 if(dsPtrList.size() <= 0)
161 std::list<te::da::DataSourceInfoPtr>::iterator it = dsPtrList.begin();
163 m_ui->m_repositoryLineEdit->setText(QString(it->get()->getTitle().c_str()));
165 m_outputDatasource = *it;
172 m_ui->m_newLayerNameLineEdit->clear();
173 m_ui->m_repositoryLineEdit->clear();
175 QString fileName = QFileDialog::getSaveFileName(
this, tr(
"Save as..."),
176 QString(), tr(
"Shapefile (*.shp *.SHP);;"),0, QFileDialog::DontConfirmOverwrite);
178 if (fileName.isEmpty())
181 boost::filesystem::path outfile(fileName.toStdString());
182 std::string aux = outfile.leaf().string();
183 m_ui->m_newLayerNameLineEdit->setText(aux.c_str());
184 aux = outfile.string();
185 m_ui->m_repositoryLineEdit->setText(aux.c_str());
188 m_ui->m_newLayerNameLineEdit->setEnabled(
false);
193 if(m_ui->m_layersComboBox->count() == 0)
195 QMessageBox::information(
this,
"Line to polygon",
"Select input layer.");
202 QMessageBox::information(
this,
"Line to polygon",
"Can not execute this operation on this type of layer.");
206 if(m_ui->m_onlySelectedCheckBox->isChecked())
208 oidSet = m_selectedLayer->getSelected();
211 QMessageBox::information(
this,
"Line to polygon",
"Select the layer objects to perform the polygon to line operation.");
217 if(!inDataSource.get())
219 QMessageBox::information(
this,
"Line to polygon",
"The selected input data source can not be accessed.");
223 if(m_ui->m_repositoryLineEdit->text().isEmpty())
225 QMessageBox::information(
this,
"Line to polygon",
"Define a repository for the result.");
229 std::string outputDataSet = m_ui->m_newLayerNameLineEdit->text().toStdString();
230 if(outputDataSet.empty())
232 QMessageBox::information(
this,
"Line to polygon",
"Define a name for the resulting layer.");
246 boost::filesystem::path uri(m_ui->m_repositoryLineEdit->text().toStdString());
247 if (boost::filesystem::exists(uri))
249 QMessageBox::information(
this,
"Line to polygon",
"Output file already exists. Remove it or select a new name and try again.");
253 std::size_t idx = outputDataSet.find(
".");
254 if (idx != std::string::npos)
255 outputDataSet=outputDataSet.substr(0,idx);
257 std::map<std::string, std::string> dsinfo;
258 dsinfo[
"URI"] = uri.string();
261 dsOGR->setConnectionInfo(dsinfo);
263 if (dsOGR->dataSetExists(outputDataSet))
265 QMessageBox::information(
this,
"Line to polygon",
"There is already a dataset with the requested name in the output data source. Remove it or select a new name and try again.");
269 this->setCursor(Qt::WaitCursor);
282 line2polygonOp->
setOutput(dsOGR, outputDataSet);
287 res = line2polygonOp->
run();
291 this->setCursor(Qt::ArrowCursor);
293 QMessageBox::information(
this,
"Line to polygon",
"Error: Error in operation.");
298 delete line2polygonOp;
301 boost::uuids::basic_random_generator<boost::mt19937> gen;
302 boost::uuids::uuid u = gen();
303 std::string id_ds = boost::uuids::to_string(u);
306 ds->setConnInfo(dsinfo);
307 ds->setTitle(uri.stem().string());
308 ds->setAccessDriver(
"OGR");
310 ds->setDescription(uri.string());
316 m_outputDatasource = ds;
323 QMessageBox::information(
this,
"Line to polygon",
"The selected output datasource can not be accessed.");
327 if(dsOGR->dataSetExists(outputDataSet))
329 QMessageBox::information(
this,
"Line to polygon",
"Dataset already exists. Remove ir or select a new name and try again.");
333 this->setCursor(Qt::WaitCursor);
345 line2polygonOp->
setOutput(dsOGR, outputDataSet);
350 res = line2polygonOp->
run();
352 delete line2polygonOp;
356 this->setCursor(Qt::ArrowCursor);
357 QMessageBox::information(
this,
"Line to polygon",
"Error in operation.");
366 m_outLayer = converter(dt);
368 catch(
const std::exception& e)
370 this->setCursor(Qt::ArrowCursor);
372 QMessageBox::information(
this,
"Line to polygon", e.what());
374 #ifdef TERRALIB_LOGGER_ENABLED
375 std::string str =
"Line to polygon - ";
377 te::common::Logger::logDebug(
"vp", str.c_str());
385 this->setCursor(Qt::ArrowCursor);
TEDATAACCESSEXPORT DataSourcePtr GetDataSource(const std::string &datasourceId, const bool opened=true)
Search for a data source with the informed id in the DataSourceManager.
GeomType
Each enumerated type is compatible with a Well-known Binary (WKB) type code.
const std::string & getDataSetName() const
LineToPolygonDialog(QWidget *parent=0, Qt::WindowFlags f=0)
boost::shared_ptr< DataSetType > DataSetTypePtr
boost::shared_ptr< DataSource > DataSourcePtr
A class that represents the known capabilities of a specific data source, i.e. this class informs all...
const QueryCapabilities & getQueryCapabilities() const
void removeViewer(int viewerId)
Dettach a progress viewer.
static ProgressManager & getInstance()
It returns a reference to the singleton instance.
const std::string & getDataSourceId() const
This class represents a set of unique ids created in the same context. i.e. from the same data set...
static std::auto_ptr< DataSource > make(const std::string &dsType)
void onCancelPushButtonClicked()
GeomType getGeometryType() const
It returns the geometry subtype allowed for the property.
void onOkPushButtonClicked()
void onLayerComboBoxChanged(int index)
void onTargetFileToolButtonPressed()
bool supportsSpatialSQLDialect() const
int addViewer(AbstractProgressViewer *apv)
Attach a progress viewer.
void setLayers(std::list< te::map::AbstractLayerPtr > layers)
Set the layer that can be used.
bool supportsPreparedQueryAPI() const
void setOutput(te::da::DataSourcePtr outDsrc, std::string dsname)
A class that represents a data source component.
A layer with reference to a dataset.
void setInput(te::da::DataSourcePtr inDsrc, std::string inDsetName, const te::da::ObjectIdSet *oidSet=0)
boost::intrusive_ptr< AbstractLayer > AbstractLayerPtr
virtual bool paramsAreValid()
A dialog for line to polygon operation.
boost::shared_ptr< DataSourceInfo > DataSourceInfoPtr
te::map::AbstractLayerPtr getLayer()
void onTargetDatasourceToolButtonPressed()
std::auto_ptr< Ui::LineToPolygonDialogForm > m_ui