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"));
79 m_ui->m_helpPushButton->setNameSpace(
"dpi.inpe.br.plugins");
80 m_ui->m_helpPushButton->setPageReference(
"plugins/vp/vp_intersection.html");
91 std::list<te::map::AbstractLayerPtr>::iterator it = m_layers.begin();
93 while(it != m_layers.end())
95 std::auto_ptr<te::da::DataSetType> dsType = it->get()->getSchema();
97 m_ui->m_firstLayerComboBox->addItem(QString(it->get()->getTitle().c_str()), QVariant(it->get()->getId().c_str()));
104 return m_layerResult;
109 std::list<te::map::AbstractLayerPtr>::iterator it = m_layers.begin();
110 std::string layerID = m_ui->m_firstLayerComboBox->itemData(index, Qt::UserRole).toString().toStdString();
112 m_ui->m_secondLayerComboBox->clear();
113 while(it != m_layers.end())
115 if(layerID != it->get()->getId().c_str())
117 std::auto_ptr<te::da::DataSetType> dsType = it->get()->getSchema();
118 if(dsType->hasGeom())
119 m_ui->m_secondLayerComboBox->addItem(QString(it->get()->getTitle().c_str()), QVariant(it->get()->getId().c_str()));
124 m_firstSelectedLayer = selectedLayer;
133 std::list<te::map::AbstractLayerPtr>::iterator it = m_layers.begin();
134 std::string layerID = m_ui->m_secondLayerComboBox->itemData(index, Qt::UserRole).toString().toStdString();
136 while(it != m_layers.end())
138 if(layerID == it->get()->getId().c_str())
141 m_secondSelectedLayer = selectedLayer;
150 std::vector<int> inSRID;
152 if(m_ui->m_firstLayerComboBox->currentText().isEmpty())
154 QMessageBox::warning(
this,
TE_TR(
"Intersection"),
TE_TR(
"Select a first input layer."));
159 if(!firstDataSetLayer)
161 QMessageBox::information(
this,
"Intersection",
"Can not execute this operation on this type of first layer.");
165 inSRID.push_back(firstDataSetLayer->
getSRID());
168 if(m_ui->m_firstSelectedCheckBox->isChecked())
173 QMessageBox::information(
this,
"Intersection",
"Select the layer objects to perform the intersection operation.");
179 if (!firstDataSource.get())
181 QMessageBox::information(
this,
"Intersection",
"The selected first input data source can not be accessed.");
185 if(m_ui->m_secondLayerComboBox->currentText().isEmpty())
187 QMessageBox::warning(
this,
TE_TR(
"Intersection"),
TE_TR(
"Select a second input layer."));
192 if(!secondDataSetLayer)
194 QMessageBox::information(
this,
"Intersection",
"Can not execute this operation on this type of second layer.");
198 inSRID.push_back(secondDataSetLayer->
getSRID());
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.");
277 std::auto_ptr<te::da::DataSetTypeConverter> secondConverter(
new te::da::DataSetTypeConverter(secondDataSetLayer->
getSchema().get(), dsOGR->getCapabilities(), dsOGR->getEncoding()));
280 this->setCursor(Qt::WaitCursor);
290 (firstDataSource->getId() == secondDataSource->getId()))
300 secondDataSource, secondDataSetLayer->
getDataSetName(), secondConverter,
301 firstOidSet, secondOidSet);
302 intersectionOp->
setOutput(dsOGR, outputdataset);
303 intersectionOp->
setParams(copyInputColumns);
308 res = intersectionOp->
run();
313 QMessageBox::information(
this,
"Intersection",
"Error: could not generate the intersection.");
318 delete intersectionOp;
321 boost::uuids::basic_random_generator<boost::mt19937> gen;
322 boost::uuids::uuid u = gen();
323 std::string
id = boost::uuids::to_string(u);
326 ds->setConnInfo(dsinfo);
327 ds->setTitle(uri.stem().string());
328 ds->setAccessDriver(
"OGR");
330 ds->setDescription(uri.string());
336 m_outputDatasource = ds;
343 QMessageBox::information(
this,
"Intersection",
"The output data source can not be accessed.");
346 if (aux->dataSetExists(outputdataset))
348 QMessageBox::information(
this,
"Intersection",
"Dataset already exists. Remove it or select a new name and try again. ");
358 this->setCursor(Qt::WaitCursor);
368 (firstDataSource->getId() == secondDataSource->getId()) &&
379 secondDataSource, secondDataSetLayer->
getDataSetName(), secondConverter,
380 firstOidSet, secondOidSet);
381 intersectionOp->
setOutput(aux, outputdataset);
382 intersectionOp->
setParams(copyInputColumns);
387 res = intersectionOp->
run();
389 delete intersectionOp;
393 this->setCursor(Qt::ArrowCursor);
394 QMessageBox::information(
this,
"Intersection",
"Error: could not generate the intersection.");
405 m_layerResult = converter(dt);
407 catch(
const std::exception& e)
409 this->setCursor(Qt::ArrowCursor);
410 QMessageBox::warning(
this,
TE_TR(
"Intersection"), e.what());
412 #ifdef TERRALIB_LOGGER_ENABLED
413 std::string str =
"Intersection - ";
415 te::common::Logger::logDebug(
"vp", str.c_str());
416 #endif //TERRALIB_LOGGER_ENABLED
423 this->setCursor(Qt::ArrowCursor);
429 m_ui->m_newLayerNameLineEdit->clear();
430 m_ui->m_newLayerNameLineEdit->setEnabled(
true);
434 std::list<te::da::DataSourceInfoPtr> dsPtrList = dlg.
getSelecteds();
436 if(dsPtrList.empty())
439 std::list<te::da::DataSourceInfoPtr>::iterator it = dsPtrList.begin();
441 m_ui->m_repositoryLineEdit->setText(QString(it->get()->getTitle().c_str()));
443 m_outputDatasource = *it;
450 m_ui->m_newLayerNameLineEdit->clear();
451 m_ui->m_repositoryLineEdit->clear();
453 QString fileName = QFileDialog::getSaveFileName(
this, tr(
"Save as..."),
454 QString(), tr(
"Shapefile (*.shp *.SHP);;"),0, QFileDialog::DontConfirmOverwrite);
456 if (fileName.isEmpty())
459 boost::filesystem::path outfile(fileName.toStdString());
460 std::string aux = outfile.leaf().string();
461 m_ui->m_newLayerNameLineEdit->setText(aux.c_str());
462 aux = outfile.string();
463 m_ui->m_repositoryLineEdit->setText(aux.c_str());
466 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.
std::auto_ptr< Ui::IntersectionDialogForm > m_ui
void onTargetDatasourceToolButtonPressed()
boost::shared_ptr< DataSetType > DataSetTypePtr
boost::shared_ptr< DataSource > DataSourcePtr
TEDATAACCESSEXPORT void AssociateDataSetTypeConverterSRID(DataSetTypeConverter *converter, const int &inputSRID, const int &outputSRID=TE_UNKNOWN_SRS)
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
An converter for DataSetType.
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)
A dialog intersection operation.
void setInput(te::da::DataSourcePtr inFirstDsrc, std::string inFirstDsetName, std::auto_ptr< te::da::DataSetTypeConverter > firstConverter, te::da::DataSourcePtr inSecondDsrc, std::string inSecondDsetName, std::auto_ptr< te::da::DataSetTypeConverter > secondConverter, const te::da::ObjectIdSet *firstOidSet=0, const te::da::ObjectIdSet *secondOidSet=0)
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.
void setParams(const bool ©InputColumns)
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