27 #include "../../common/Logger.h"
28 #include "../../common/progress/ProgressManager.h"
29 #include "../../common/Translator.h"
30 #include "../../dataaccess/dataset/DataSetType.h"
31 #include "../../dataaccess/dataset/ObjectIdSet.h"
32 #include "../../dataaccess/datasource/DataSourceCapabilities.h"
33 #include "../../dataaccess/datasource/DataSourceInfo.h"
34 #include "../../dataaccess/datasource/DataSourceInfoManager.h"
35 #include "../../dataaccess/datasource/DataSourceManager.h"
36 #include "../../dataaccess/datasource/DataSourceFactory.h"
37 #include "../../dataaccess/utils/Utils.h"
38 #include "../../datatype/Property.h"
39 #include "../../qt/widgets/datasource/selector/DataSourceSelectorDialog.h"
40 #include "../../qt/widgets/layer/utils/DataSet2Layer.h"
41 #include "../../qt/widgets/progress/ProgressViewerDialog.h"
42 #include "../../srs/Config.h"
43 #include "../Exception.h"
44 #include "../IntersectionMemory.h"
45 #include "../IntersectionOp.h"
46 #include "../IntersectionQuery.h"
49 #include "ui_IntersectionDialogForm.h"
53 #include <QFileDialog>
54 #include <QMessageBox>
55 #include <QTreeWidget>
58 #include <boost/filesystem.hpp>
59 #include <boost/uuid/random_generator.hpp>
60 #include <boost/uuid/uuid_io.hpp>
64 m_ui(new Ui::IntersectionDialogForm),
70 m_ui->m_imgLabel->setPixmap(QIcon::fromTheme(
"vp-intersection-hint").pixmap(48,48));
71 m_ui->m_targetDatasourceToolButton->setIcon(QIcon::fromTheme(
"datasource"));
80 m_ui->m_helpPushButton->setNameSpace(
"dpi.inpe.br.plugins");
81 m_ui->m_helpPushButton->setPageReference(
"plugins/vp/vp_intersection.html");
92 std::list<te::map::AbstractLayerPtr>::iterator it = m_layers.begin();
94 while(it != m_layers.end())
96 std::auto_ptr<te::da::DataSetType> dsType = it->get()->getSchema();
98 m_ui->m_firstLayerComboBox->addItem(QString(it->get()->getTitle().c_str()), QVariant(it->get()->getId().c_str()));
105 return m_layerResult;
110 std::list<te::map::AbstractLayerPtr>::iterator it = m_layers.begin();
111 std::string layerID = m_ui->m_firstLayerComboBox->itemData(index, Qt::UserRole).toString().toStdString();
113 m_ui->m_secondLayerComboBox->clear();
114 while(it != m_layers.end())
116 if(layerID != it->get()->getId().c_str())
118 std::auto_ptr<te::da::DataSetType> dsType = it->get()->getSchema();
119 if(dsType->hasGeom())
120 m_ui->m_secondLayerComboBox->addItem(QString(it->get()->getTitle().c_str()), QVariant(it->get()->getId().c_str()));
125 m_firstSelectedLayer = selectedLayer;
134 std::list<te::map::AbstractLayerPtr>::iterator it = m_layers.begin();
135 std::string layerID = m_ui->m_secondLayerComboBox->itemData(index, Qt::UserRole).toString().toStdString();
137 while(it != m_layers.end())
139 if(layerID == it->get()->getId().c_str())
142 m_secondSelectedLayer = selectedLayer;
151 QMessageBox::information(
this,
"Intersection Operation",
"Under development");
156 if(m_ui->m_firstLayerComboBox->currentText().isEmpty())
158 QMessageBox::warning(
this,
TE_TR(
"Intersection"),
TE_TR(
"Select a first input layer."));
163 if(!firstDataSetLayer)
165 QMessageBox::information(
this,
"Intersection",
"Can not execute this operation on this type of first layer.");
170 if(m_ui->m_firstSelectedCheckBox->isChecked())
175 QMessageBox::information(
this,
"Intersection",
"Select the layer objects to perform the intersection operation.");
181 if (!firstDataSource.get())
183 QMessageBox::information(
this,
"Intersection",
"The selected first input data source can not be accessed.");
187 if(m_ui->m_secondLayerComboBox->currentText().isEmpty())
189 QMessageBox::warning(
this,
TE_TR(
"Intersection"),
TE_TR(
"Select a second input layer."));
194 if(!secondDataSetLayer)
196 QMessageBox::information(
this,
"Intersection",
"Can not execute this operation on this type of second layer.");
201 if(m_ui->m_secondSelectedCheckBox->isChecked())
203 secondOidSet = m_secondSelectedLayer->getSelected();
206 QMessageBox::information(
this,
"Intersection",
"Select the layer objects to perform the intersection operation.");
212 if (!secondDataSource.get())
214 QMessageBox::information(
this,
"Intersection",
"The selected second input data source can not be accessed.");
218 if(m_ui->m_repositoryLineEdit->text().isEmpty())
220 QMessageBox::warning(
this,
TE_TR(
"Intersection"),
TE_TR(
"Select a repository for the resulting layer."));
224 if(m_ui->m_newLayerNameLineEdit->text().isEmpty())
226 QMessageBox::warning(
this,
TE_TR(
"Intersection"),
TE_TR(
"Define a name for the resulting layer."));
233 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);
234 if (ret == QMessageBox::No)
244 bool copyInputColumns = m_ui->m_copyColumnsCheckBox->isChecked();
245 std::string outputdataset = m_ui->m_newLayerNameLineEdit->text().toStdString();
250 boost::filesystem::path uri(m_ui->m_repositoryLineEdit->text().toStdString());
252 if (boost::filesystem::exists(uri))
254 QMessageBox::information(
this,
"Intersection",
"Output file already exists. Remove it and try again. ");
258 std::size_t idx = outputdataset.find(
".");
259 if(idx != std::string::npos)
260 outputdataset = outputdataset.substr(0, idx);
262 std::map<std::string, std::string> dsinfo;
263 dsinfo[
"URI"] = uri.string();
266 dsOGR->setConnectionInfo(dsinfo);
268 if(dsOGR->dataSetExists(outputdataset))
270 QMessageBox::information(
this,
"Intersection",
"Output file already exists. Remove it or select a new name and try again.");
274 this->setCursor(Qt::WaitCursor);
284 (firstDataSource->getId() == secondDataSource->getId()))
295 firstOidSet, secondOidSet);
296 intersectionOp->
setOutput(dsOGR, outputdataset);
302 res = intersectionOp->
run();
307 QMessageBox::information(
this,
"Intersection",
"Error: could not generate the intersection.");
312 delete intersectionOp;
315 boost::uuids::basic_random_generator<boost::mt19937> gen;
316 boost::uuids::uuid u = gen();
317 std::string
id = boost::uuids::to_string(u);
320 ds->setConnInfo(dsinfo);
321 ds->setTitle(uri.stem().string());
322 ds->setAccessDriver(
"OGR");
324 ds->setDescription(uri.string());
330 m_outputDatasource = ds;
337 QMessageBox::information(
this,
"Intersection",
"The output data source can not be accessed.");
340 if (aux->dataSetExists(outputdataset))
342 QMessageBox::information(
this,
"Intersection",
"Dataset already exists. Remove it or select a new name and try again. ");
345 this->setCursor(Qt::WaitCursor);
355 (firstDataSource->getId() == secondDataSource->getId()) &&
367 firstOidSet, secondOidSet);
368 intersectionOp->
setOutput(aux, outputdataset);
374 res = intersectionOp->
run();
376 delete intersectionOp;
380 this->setCursor(Qt::ArrowCursor);
381 QMessageBox::information(
this,
"Intersection",
"Error: could not generate the intersection.");
392 m_layerResult = converter(dt);
394 catch(
const std::exception& e)
396 this->setCursor(Qt::ArrowCursor);
397 QMessageBox::warning(
this,
TE_TR(
"Intersection"), e.what());
399 #ifdef TERRALIB_LOGGER_ENABLED
400 std::string str =
"Intersection - ";
402 te::common::Logger::logDebug(
"vp", str.c_str());
403 #endif //TERRALIB_LOGGER_ENABLED
410 this->setCursor(Qt::ArrowCursor);
416 m_ui->m_newLayerNameLineEdit->clear();
417 m_ui->m_newLayerNameLineEdit->setEnabled(
true);
421 std::list<te::da::DataSourceInfoPtr> dsPtrList = dlg.
getSelecteds();
423 if(dsPtrList.size() <= 0)
426 std::list<te::da::DataSourceInfoPtr>::iterator it = dsPtrList.begin();
428 m_ui->m_repositoryLineEdit->setText(QString(it->get()->getTitle().c_str()));
430 m_outputDatasource = *it;
437 m_ui->m_newLayerNameLineEdit->clear();
438 m_ui->m_repositoryLineEdit->clear();
440 QString fileName = QFileDialog::getSaveFileName(
this, tr(
"Save as..."),
441 QString(), tr(
"Shapefile (*.shp *.SHP);;"),0, QFileDialog::DontConfirmOverwrite);
443 if (fileName.isEmpty())
446 boost::filesystem::path outfile(fileName.toStdString());
447 std::string aux = outfile.leaf().string();
448 m_ui->m_newLayerNameLineEdit->setText(aux.c_str());
449 aux = outfile.string();
450 m_ui->m_repositoryLineEdit->setText(aux.c_str());
453 m_ui->m_newLayerNameLineEdit->setEnabled(
false);
TEDATAACCESSEXPORT DataSourcePtr GetDataSource(const std::string &datasourceId, const bool opened=true)
Search for a data source with the informed id in the DataSourceManager.
void onOkPushButtonClicked()
Utility functions for the data access module.
const std::string & getDataSetName() const
void setLayers(std::list< te::map::AbstractLayerPtr > layers)
Set the layer that can be used.
void setInput(te::da::DataSourcePtr inFirstDsrc, std::string inFirstDsetName, std::auto_ptr< te::da::DataSetType > inFirstDsetType, te::da::DataSourcePtr inSecondDsrc, std::string inSecondDsetName, std::auto_ptr< te::da::DataSetType > inSecondDsetType, const te::da::ObjectIdSet *firstOidSet=0, const te::da::ObjectIdSet *secondOidSet=0)
std::auto_ptr< Ui::IntersectionDialogForm > m_ui
void onTargetDatasourceToolButtonPressed()
boost::shared_ptr< DataSetType > DataSetTypePtr
boost::shared_ptr< DataSource > DataSourcePtr
void onHelpPushButtonClicked()
A class that represents the known capabilities of a specific data source, i.e. this class informs all...
virtual bool paramsAreValid()
#define TE_TR(message)
It marks a string in order to get translated.
const QueryCapabilities & getQueryCapabilities() const
The class that defines the model used in the Qt Model/View architecture.
void removeViewer(int viewerId)
Dettach a progress viewer.
static ProgressManager & getInstance()
It returns a reference to the singleton instance.
const std::string & getDataSourceId() const
#define TE_UNKNOWN_SRS
A numeric value to represent a unknown SRS identification in TerraLib.
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)
te::map::AbstractLayerPtr getLayer()
void onTargetFileToolButtonPressed()
bool supportsSpatialSQLDialect() const
void setOutput(te::da::DataSourcePtr outDsrc, std::string dsname)
void setParams(const bool ©InputColumns, std::size_t inSRID)
A dialog intersection operation.
int addViewer(AbstractProgressViewer *apv)
Attach a progress viewer.
virtual const te::da::ObjectIdSet * getSelected() const
It returns the selected group of this Layer.
A class that represents a data source component.
virtual int getSRID() const
It returns the Spatial Reference System ID associated to the Layer.
A layer with reference to a dataset.
void onSecondLayerComboBoxChanged(int index)
std::auto_ptr< LayerSchema > getSchema() const
It returns the layer schema.
IntersectionDialog(QWidget *parent=0, Qt::WindowFlags f=0)
boost::intrusive_ptr< AbstractLayer > AbstractLayerPtr
void onFirstLayerComboBoxChanged(int index)
boost::shared_ptr< DataSourceInfo > DataSourceInfoPtr