27 #include "../../core/filesystem/FileSystem.h" 28 #include "../../core/logger/Logger.h" 29 #include "../../core/translator/Translator.h" 30 #include "../../common/progress/ProgressManager.h" 31 #include "../../common/StringUtils.h" 32 #include "../../dataaccess/dataset/DataSetType.h" 33 #include "../../dataaccess/dataset/ObjectIdSet.h" 34 #include "../../dataaccess/datasource/DataSourceCapabilities.h" 35 #include "../../dataaccess/datasource/DataSourceInfo.h" 36 #include "../../dataaccess/datasource/DataSourceInfoManager.h" 37 #include "../../dataaccess/datasource/DataSourceManager.h" 38 #include "../../dataaccess/datasource/DataSourceFactory.h" 39 #include "../../dataaccess/query/And.h" 40 #include "../../dataaccess/query/Expression.h" 41 #include "../../dataaccess/query/In.h" 42 #include "../../dataaccess/query/Where.h" 43 #include "../../dataaccess/utils/Utils.h" 44 #include "../../datatype/Property.h" 45 #include "../../maptools/QueryLayer.h" 46 #include "../../qt/widgets/datasource/selector/DataSourceSelectorDialog.h" 47 #include "../../qt/widgets/layer/utils/DataSet2Layer.h" 48 #include "../../qt/widgets/progress/ProgressViewerDialog.h" 49 #include "../../qt/widgets/utils/DoubleListWidget.h" 50 #include "../../qt/widgets/utils/FileDialog.h" 51 #include "../../srs/Config.h" 52 #include "../Exception.h" 53 #include "../IntersectionMemory.h" 54 #include "../IntersectionOp.h" 55 #include "../IntersectionQuery.h" 57 #include "ui_IntersectionDialogForm.h" 61 #include <QFileDialog> 62 #include <QGridLayout> 63 #include <QMessageBox> 64 #include <QTreeWidget> 67 #include <boost/filesystem.hpp> 68 #include <boost/uuid/random_generator.hpp> 69 #include <boost/uuid/uuid_io.hpp> 74 te::vp::IntersectionDialog::IntersectionDialog(
QWidget* parent, Qt::WindowFlags f)
76 m_ui(new
Ui::IntersectionDialogForm),
82 m_ui->m_imgLabel->setPixmap(QIcon::fromTheme(
"vp-intersection-hint").pixmap(48,48));
83 m_ui->m_targetDatasourceToolButton->setIcon(QIcon::fromTheme(
"datasource"));
87 m_doubleListWidget->setLeftLabel(
"");
88 m_doubleListWidget->setRightLabel(
"");
90 QGridLayout* layout =
new QGridLayout(m_ui->m_attrSelectionGroupBox);
91 layout->addWidget(m_doubleListWidget.get());
92 layout->setContentsMargins(0, 0, 0, 0);
94 connect(m_ui->m_firstLayerComboBox, SIGNAL(currentIndexChanged(
int)),
this, SLOT(onFirstLayerComboBoxChanged(
int)));
95 connect(m_ui->m_secondLayerComboBox, SIGNAL(currentIndexChanged(
int)),
this, SLOT(onSecondLayerComboBoxChanged(
int)));
96 connect(m_ui->m_okPushButton, SIGNAL(clicked()),
this, SLOT(onOkPushButtonClicked()));
97 connect(m_ui->m_targetDatasourceToolButton, SIGNAL(pressed()),
this, SLOT(onTargetDatasourceToolButtonPressed()));
98 connect(m_ui->m_targetFileToolButton, SIGNAL(pressed()),
this, SLOT(onTargetFileToolButtonPressed()));
100 m_ui->m_helpPushButton->setNameSpace(
"dpi.inpe.br.plugins");
101 m_ui->m_helpPushButton->setPageReference(
"plugins/vp/vp_intersection.html");
108 std::list<te::map::AbstractLayerPtr>::iterator it = layers.begin();
110 while (it != layers.end())
112 std::unique_ptr<te::da::DataSetType> dsType = it->get()->getSchema();
113 if (dsType->hasGeom())
130 std::list<te::map::AbstractLayerPtr>::iterator it =
m_layers.begin();
136 m_ui->m_firstLayerComboBox->addItem(QString(it->get()->getTitle().c_str()), QVariant::fromValue(*it));
142 QVariant varLayer =
m_ui->m_firstLayerComboBox->itemData(
m_ui->m_firstLayerComboBox->currentIndex(), Qt::UserRole);
150 int currIndex =
m_ui->m_firstLayerComboBox->currentIndex();
152 std::list<te::map::AbstractLayerPtr>::iterator it =
m_layers.begin();
158 m_ui->m_secondLayerComboBox->addItem(QString(it->get()->getTitle().c_str()), QVariant::fromValue(*it));
162 m_ui->m_secondLayerComboBox->removeItem(currIndex);
166 QVariant varLayer =
m_ui->m_secondLayerComboBox->itemData(
m_ui->m_secondLayerComboBox->currentIndex(), Qt::UserRole);
179 QVariant varLayer =
m_ui->m_firstLayerComboBox->itemData(index, Qt::UserRole);
182 m_ui->m_secondLayerComboBox->clear();
193 QVariant varLayer =
m_ui->m_secondLayerComboBox->itemData(index, Qt::UserRole);
203 std::vector<std::string> inputValues;
204 std::vector<int> inputIds;
206 std::unique_ptr<te::da::DataSetType> firstSchema;
207 std::unique_ptr<te::da::DataSetType> secondSchema;
219 std::vector<te::dt::Property*> firstProps = firstSchema->getProperties();
220 for (std::size_t i = 0; i < firstProps.size(); ++i)
225 inputIds.push_back(1);
229 std::vector<te::dt::Property*> secondProps = secondSchema->getProperties();
230 for (std::size_t i = 0; i < secondProps.size(); ++i)
235 inputIds.push_back(2);
246 std::vector<std::pair<int, std::string> > attributes;
248 for (std::size_t i = 0; i < outValues.size(); ++i)
250 std::vector<std::string> tok;
254 attribute.first = outIds[i];
255 attribute.second = tok[1];
257 attributes.push_back(attribute);
265 if(
m_ui->m_firstLayerComboBox->currentText().isEmpty())
267 QMessageBox::warning(
this,
TE_TR(
"Intersection"),
TE_TR(
"Select a first input layer."));
272 if(
m_ui->m_firstSelectedCheckBox->isChecked())
277 QMessageBox::information(
this,
"Intersection",
"Select the layer objects to perform the intersection operation.");
283 if (!firstDataSource.get())
285 QMessageBox::information(
this,
"Intersection",
"The selected first input data source can not be accessed.");
289 if(
m_ui->m_secondLayerComboBox->currentText().isEmpty())
291 QMessageBox::warning(
this,
TE_TR(
"Intersection"),
TE_TR(
"Select a second input layer."));
296 if(
m_ui->m_secondSelectedCheckBox->isChecked())
301 QMessageBox::information(
this,
"Intersection",
"Select the layer objects to perform the intersection operation.");
307 if (!secondDataSource.get())
309 QMessageBox::information(
this,
"Intersection",
"The selected second input data source can not be accessed.");
313 if(
m_ui->m_repositoryLineEdit->text().isEmpty())
315 QMessageBox::warning(
this,
TE_TR(
"Intersection"),
TE_TR(
"Select a repository for the resulting layer."));
319 if(
m_ui->m_newLayerNameLineEdit->text().isEmpty())
321 QMessageBox::warning(
this,
TE_TR(
"Intersection"),
TE_TR(
"Define a name for the resulting layer."));
328 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);
329 if (ret == QMessageBox::No)
349 QMessageBox::information(
this,
"Intersection",
"Can not execute this operation on this type of first layer.");
363 QMessageBox::information(
this,
"Intersection",
"Can not execute this operation on this type of second layer.");
372 std::string outputdataset =
m_ui->m_newLayerNameLineEdit->text().toUtf8().data();
377 boost::filesystem::path uri(
m_ui->m_repositoryLineEdit->text().toUtf8().data());
381 QMessageBox::information(
this,
"Intersection",
"Output file already exists. Remove it and try again. ");
385 std::size_t idx = outputdataset.find(
".");
386 if(idx != std::string::npos)
387 outputdataset = outputdataset.substr(0, idx);
389 std::string dsinfo(
"file://");
390 dsinfo += uri.string();
394 if(dsOGR->dataSetExists(outputdataset))
396 QMessageBox::information(
this,
"Intersection",
"Output file already exists. Remove it or select a new name and try again.");
406 this->setCursor(Qt::WaitCursor);
416 (firstDataSource->getId() == secondDataSource->getId()) &&
430 std::string firstName;
431 std::string secondName;
433 if (firstDataSetLayer)
437 else if (firstQueryLayer)
439 firstName = firstQueryLayer->
getTitle();
443 if (secondDataSetLayer)
447 else if (secondQueryLayer)
449 secondName = secondQueryLayer->
getTitle();
453 if (firstQueryLayer && (firstOidSet !=
nullptr))
471 if (secondQueryLayer && (secondOidSet !=
nullptr))
491 firstOidSet, secondOidSet);
493 intersectionOp->
setOutput(dsOGR, outputdataset);
499 res = intersectionOp->
run();
504 QMessageBox::information(
this,
"Intersection",
"Error: could not generate the intersection.");
509 delete intersectionOp;
512 boost::uuids::basic_random_generator<boost::mt19937> gen;
513 boost::uuids::uuid u = gen();
514 std::string
id = boost::uuids::to_string(u);
517 ds->setConnInfo(dsinfo);
518 ds->setTitle(uri.stem().string());
519 ds->setAccessDriver(
"OGR");
521 ds->setDescription(uri.string());
534 QMessageBox::information(
this,
"Intersection",
"The output data source can not be accessed.");
537 if (aux->dataSetExists(outputdataset))
539 QMessageBox::information(
this,
"Intersection",
"Dataset already exists. Remove it or select a new name and try again. ");
549 this->setCursor(Qt::WaitCursor);
559 (firstDataSource->getId() == secondDataSource->getId()) &&
569 intersectionOp->
setInput(firstDataSource,
573 std::move(firstConverter),
578 std::move(secondConverter),
582 intersectionOp->
setOutput(aux, outputdataset);
588 res = intersectionOp->
run();
590 delete intersectionOp;
594 this->setCursor(Qt::ArrowCursor);
595 QMessageBox::information(
this,
"Intersection",
"Error: could not generate the intersection.");
608 catch(
const std::exception& e)
610 this->setCursor(Qt::ArrowCursor);
611 QMessageBox::warning(
this,
TE_TR(
"Intersection"), e.what());
613 #ifdef TERRALIB_LOGGER_ENABLED 614 std::string str =
"Intersection - ";
617 #endif //TERRALIB_LOGGER_ENABLED 622 this->setCursor(Qt::ArrowCursor);
628 m_ui->m_newLayerNameLineEdit->clear();
629 m_ui->m_newLayerNameLineEdit->setEnabled(
true);
633 std::list<te::da::DataSourceInfoPtr> dsPtrList = dlg.
getSelecteds();
635 if(dsPtrList.empty())
638 std::list<te::da::DataSourceInfoPtr>::iterator it = dsPtrList.begin();
640 m_ui->m_repositoryLineEdit->setText(QString(it->get()->getTitle().c_str()));
649 m_ui->m_newLayerNameLineEdit->clear();
650 m_ui->m_repositoryLineEdit->clear();
658 QMessageBox::warning(
this, tr(
"File information"), ex.
what());
662 m_ui->m_repositoryLineEdit->setText(fileDialog.
getPath().c_str());
663 m_ui->m_newLayerNameLineEdit->setText(fileDialog.
getFileName().c_str());
666 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()
std::list< te::map::AbstractLayerPtr > m_layers
First layer selected.
static std::unique_ptr< DataSource > make(const std::string &driver, const te::core::URI &connInfo)
void setLayers(std::list< te::map::AbstractLayerPtr > layers)
Set the layer that can be used.
std::vector< std::pair< int, std::string > > getSelectedProperties()
std::unique_ptr< te::qt::widgets::DoubleListWidget > m_doubleListWidget
void onTargetDatasourceToolButtonPressed()
static bool exists(const std::string &path)
Checks if a given path in UTF-8 exists.
boost::shared_ptr< DataSetType > DataSetTypePtr
boost::shared_ptr< DataSource > DataSourcePtr
TEDATAACCESSEXPORT void AssociateDataSetTypeConverterSRID(DataSetTypeConverter *converter, const int &inputSRID, const int &outputSRID=TE_UNKNOWN_SRS)
#define TE_UNKNOWN_SRS
A numeric value to represent a unknown SRS identification in TerraLib.
virtual const std::string & getTitle() const
It returns the layer title.
void setInput(te::da::DataSourcePtr inFirstDsrc, std::string inFirstDsetName, std::unique_ptr< te::da::DataSetTypeConverter > firstConverter, te::da::DataSourcePtr inSecondDsrc, std::string inSecondDsetName, std::unique_ptr< te::da::DataSetTypeConverter > secondConverter, const te::da::ObjectIdSet *firstOidSet=0, const te::da::ObjectIdSet *secondOidSet=0)
virtual const char * what() const
It outputs the exception message.
#define TE_CORE_LOG_DEBUG(channel, message)
Use this tag in order to log a message to a specified logger with the DEBUG level.
virtual Expression * clone() const =0
It creates a new copy of this expression.
A class that represents the known capabilities of a specific data source, i.e. this class informs all...
A layer resulting from a query.
static te::dt::Date ds(2010, 01, 01)
virtual bool paramsAreValid()
#define TE_TR(message)
It marks a string in order to get translated.
const QueryCapabilities & getQueryCapabilities() const
Q_DECLARE_METATYPE(te::map::AbstractLayerPtr) te
Boolean logic operator: AND.
This is an abstract class that models a query expression.
An converter for DataSetType.
void Tokenize(const std::string &str, std::vector< std::string > &tokens, const std::string &delimiters=" ")
It tokenizes a given string with a delimiter of your own choice.
void setWhere(Where *w)
It sets the filter codition.
void updateFirstLayerComboBox()
static DataSourceManager & getInstance()
It returns a reference to the singleton instance.
void setParams(const std::vector< std::pair< int, std::string > > &attributeVec)
This class represents a set of unique ids created in the same context. i.e. from the same data set...
static te::dt::TimeDuration dt(20, 30, 50, 11)
te::map::AbstractLayerPtr getLayer()
void onTargetFileToolButtonPressed()
te::map::AbstractLayerPtr m_secondSelectedLayer
Second layer selected.
A class that can be used to model a filter expression that can be applied to a query.
Expression * getExp() const
te::da::Select * getQuery() const
bool supportsSpatialSQLDialect() const
void setOutput(te::da::DataSourcePtr outDsrc, std::string dsname)
A dialog intersection operation.
Utility functions for the data access module.
te::map::AbstractLayerPtr m_layerResult
Generated Layer.
This class is designed to declare objects to be thrown as exceptions by TerraLib. ...
A Select models a query to be used when retrieving data from a DataSource.
void updateSecondLayerComboBox()
Where * getWhere() const
It returns the filter condition.
const std::string & getDataSetName() const
A class that represents a data source component.
Expression * getExpressionByInClause(const std::string source="") const
A layer with reference to a dataset.
void onSecondLayerComboBoxChanged(int index)
void updateDoubleListWidget()
te::da::DataSourceInfoPtr m_outputDatasource
DataSource information.
boost::intrusive_ptr< AbstractLayer > AbstractLayerPtr
void onFirstLayerComboBoxChanged(int index)
std::unique_ptr< Ui::IntersectionDialogForm > m_ui
boost::shared_ptr< DataSourceInfo > DataSourceInfoPtr
te::map::AbstractLayerPtr m_firstSelectedLayer
First layer selected.