27 #include "../../common/progress/ProgressManager.h"
28 #include "../../common/Translator.h"
29 #include "../../dataaccess/dataset/DataSetType.h"
30 #include "../../dataaccess/datasource/DataSourceInfo.h"
31 #include "../../dataaccess/datasource/DataSourceInfoManager.h"
32 #include "../../dataaccess/datasource/DataSourceManager.h"
33 #include "../../dataaccess/datasource/DataSourceFactory.h"
34 #include "../../dataaccess/utils/Utils.h"
35 #include "../../datatype/Property.h"
36 #include "../../qt/widgets/datasource/selector/DataSourceSelectorDialog.h"
37 #include "../../qt/widgets/progress/ProgressViewerDialog.h"
38 #include "../../srs/Config.h"
39 #include "../Exception.h"
40 #include "../Intersection.h"
41 #include "../qt/widgets/layer/utils/DataSet2Layer.h"
44 #include "ui_IntersectionDialogForm.h"
45 #include "VectorProcessingConfig.h"
49 #include <QtGui/QFileDialog>
50 #include <QtGui/QMessageBox>
51 #include <QtGui/QTreeWidget>
54 #include <boost/filesystem.hpp>
55 #include <boost/uuid/random_generator.hpp>
56 #include <boost/uuid/uuid_io.hpp>
60 m_ui(new Ui::IntersectionDialogForm),
66 m_ui->m_imgLabel->setPixmap(QIcon::fromTheme(VP_IMAGES
"/vp-intersection-hint").pixmap(48,48));
67 m_ui->m_targetDatasourceToolButton->setIcon(QIcon::fromTheme(
"datasource"));
76 m_ui->m_helpPushButton->setNameSpace(
"dpi.inpe.br.plugins");
77 m_ui->m_helpPushButton->setPageReference(
"plugins/vp/vp_intersection.html");
88 std::list<te::map::AbstractLayerPtr>::iterator it = m_layers.begin();
90 while(it != m_layers.end())
92 std::auto_ptr<te::da::DataSetType> dsType = it->get()->getSchema();
94 m_ui->m_firstLayerComboBox->addItem(QString(it->get()->getTitle().c_str()), QVariant(it->get()->getId().c_str()));
101 return m_layerResult;
106 std::list<te::map::AbstractLayerPtr>::iterator it = m_layers.begin();
107 std::string layerID = m_ui->m_firstLayerComboBox->itemData(index, Qt::UserRole).toString().toStdString();
109 m_ui->m_secondLayerComboBox->clear();
110 while(it != m_layers.end())
112 if(layerID != it->get()->getId().c_str())
114 std::auto_ptr<te::da::DataSetType> dsType = it->get()->getSchema();
115 if(dsType->hasGeom())
116 m_ui->m_secondLayerComboBox->addItem(QString(it->get()->getTitle().c_str()), QVariant(it->get()->getId().c_str()));
121 m_firstSelectedLayer = selectedLayer;
130 std::list<te::map::AbstractLayerPtr>::iterator it = m_layers.begin();
131 std::string layerID = m_ui->m_secondLayerComboBox->itemData(index, Qt::UserRole).toString().toStdString();
133 while(it != m_layers.end())
135 if(layerID == it->get()->getId().c_str())
138 m_secondSelectedLayer = selectedLayer;
147 QMessageBox::information(
this,
"Intersection Operation",
"Under development");
152 if(m_ui->m_firstLayerComboBox->currentText().isEmpty())
154 QMessageBox::warning(
this,
TR_VP(
"Intersection"),
TR_VP(
"Select a first input layer."));
159 if(!firstDataSetLayer)
161 QMessageBox::information(
this,
"Intersection",
"Can not execute this operation on this type of first layer.");
166 if (!firstDataSource.get())
168 QMessageBox::information(
this,
"Intersection",
"The selected first input data source can not be accessed.");
172 if(m_ui->m_secondLayerComboBox->currentText().isEmpty())
174 QMessageBox::warning(
this,
TR_VP(
"Intersection"),
TR_VP(
"Select a second input layer."));
179 if(!secondDataSetLayer)
181 QMessageBox::information(
this,
"Intersection",
"Can not execute this operation on this type of second layer.");
186 if (!secondDataSource.get())
188 QMessageBox::information(
this,
"Intersection",
"The selected second input data source can not be accessed.");
192 if(m_ui->m_repositoryLineEdit->text().isEmpty())
194 QMessageBox::warning(
this,
TR_VP(
"Intersection"),
TR_VP(
"Select a repository for the resulting layer."));
198 if(m_ui->m_newLayerNameLineEdit->text().isEmpty())
200 QMessageBox::warning(
this,
TR_VP(
"Intersection"),
TR_VP(
"Define a name for the resulting layer."));
207 int ret = QMessageBox::question(
this,
"Intersection",
"The two layers have incompatible SRS. The result might be incorrect. Do you wish to continue?", QMessageBox::No, QMessageBox::Yes);
208 if (ret == QMessageBox::No)
218 bool copyInputColumns = m_ui->m_copyColumnsCheckBox->isChecked();
219 std::string outputdataset = m_ui->m_newLayerNameLineEdit->text().toStdString();
224 boost::filesystem::path uri(m_ui->m_repositoryLineEdit->text().toStdString());
226 if (boost::filesystem::exists(uri))
228 QMessageBox::information(
this,
"Intersection",
"Output file already exists. Remove it and try again. ");
232 std::size_t idx = outputdataset.find(
".");
233 if(idx != std::string::npos)
234 outputdataset = outputdataset.substr(0, idx);
236 std::map<std::string, std::string> dsinfo;
237 dsinfo[
"URI"] = uri.string();
240 dsOGR->setConnectionInfo(dsinfo);
242 if(dsOGR->dataSetExists(outputdataset))
244 QMessageBox::information(
this,
"Intersection",
"Output file already exists. Remove it or select a new name and try again.");
248 this->setCursor(Qt::WaitCursor);
250 firstDataSource.get(),
252 secondDataSource.get(),
260 QMessageBox::information(
this,
"Intersection",
"Error: could not generate the intersection.");
266 boost::uuids::basic_random_generator<boost::mt19937> gen;
267 boost::uuids::uuid u = gen();
268 std::string
id = boost::uuids::to_string(u);
271 ds->setConnInfo(dsinfo);
272 ds->setTitle(uri.stem().string());
273 ds->setAccessDriver(
"OGR");
275 ds->setDescription(uri.string());
281 m_outputDatasource = ds;
288 QMessageBox::information(
this,
"Intersection",
"The output data source can not be accessed.");
291 if (aux->dataSetExists(outputdataset))
293 QMessageBox::information(
this,
"Intersection",
"Dataset already exists. Remove it or select a new name and try again. ");
296 this->setCursor(Qt::WaitCursor);
298 firstDataSource.get(),
300 secondDataSource.get(),
306 this->setCursor(Qt::ArrowCursor);
307 QMessageBox::information(
this,
"Intersection",
"Error: could not generate the intersection.");
318 m_layerResult = converter(dt);
320 catch(
const std::exception& e)
322 this->setCursor(Qt::ArrowCursor);
323 QMessageBox::warning(
this,
TR_VP(
"Intersection"), e.what());
329 this->setCursor(Qt::ArrowCursor);
335 m_ui->m_newLayerNameLineEdit->clear();
336 m_ui->m_newLayerNameLineEdit->setEnabled(
true);
340 std::list<te::da::DataSourceInfoPtr> dsPtrList = dlg.
getSelecteds();
342 if(dsPtrList.size() <= 0)
345 std::list<te::da::DataSourceInfoPtr>::iterator it = dsPtrList.begin();
347 m_ui->m_repositoryLineEdit->setText(QString(it->get()->getTitle().c_str()));
349 m_outputDatasource = *it;
356 m_ui->m_newLayerNameLineEdit->clear();
357 m_ui->m_repositoryLineEdit->clear();
359 QString fileName = QFileDialog::getSaveFileName(
this, tr(
"Save as..."),
360 QString(), tr(
"Shapefile (*.shp *.SHP);;"),0, QFileDialog::DontConfirmOverwrite);
362 if (fileName.isEmpty())
365 boost::filesystem::path outfile(fileName.toStdString());
366 std::string aux = outfile.leaf().string();
367 m_ui->m_newLayerNameLineEdit->setText(aux.c_str());
368 aux = outfile.string();
369 m_ui->m_repositoryLineEdit->setText(aux.c_str());
372 m_ui->m_newLayerNameLineEdit->setEnabled(
false);
A layer with reference to a dataset.
const std::string & getDataSetName() const
A dialog for selecting a data source.
void onOkPushButtonClicked()
TEDATAACCESSEXPORT DataSourcePtr GetDataSource(const std::string &datasourceId, const bool opened=true)
Search for a data source with the informed id in the DataSourceManager.
IntersectionDialog(QWidget *parent=0, Qt::WindowFlags f=0)
void onHelpPushButtonClicked()
A class that represents a data source component.
const std::list< te::da::DataSourceInfoPtr > & getSelecteds() const
static std::auto_ptr< DataSource > make(const std::string &dsType)
void onFirstLayerComboBoxChanged(int index)
const std::string & getDataSourceId() const
#define TE_UNKNOWN_SRS
A numeric value to represent a unknown SRS identification in TerraLib.
A dialog intersection operation.
TEVPEXPORT bool Intersection(const std::string &inFirstDataSetName, te::da::DataSource *inFirstDataSource, const std::string &inSecondDataSetName, te::da::DataSource *inSecondDataSource, const bool ©InputColumns, const std::string &outDataSetName, te::da::DataSource *outDataSource)
void setLayers(std::list< te::map::AbstractLayerPtr > layers)
Set the layer that can be used.
Utility functions for the data access module.
The class that defines the model used in the Qt Model/View architecture.
void onSecondLayerComboBoxChanged(int index)
std::auto_ptr< Ui::IntersectionDialogForm > m_ui
boost::shared_ptr< DataSource > DataSourcePtr
te::map::AbstractLayerPtr getLayer()
boost::shared_ptr< DataSetType > DataSetTypePtr
void onTargetDatasourceToolButtonPressed()
boost::intrusive_ptr< AbstractLayer > AbstractLayerPtr
static T & getInstance()
It returns a reference to the singleton instance.
void onTargetFileToolButtonPressed()
boost::shared_ptr< DataSourceInfo > DataSourceInfoPtr
virtual int getSRID() const
It returns the Spatial Reference System ID associated to the Layer.
#define TR_VP(message)
It marks a string in order to get translated. This is a special mark used in the Terrralib Vector Pro...