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" 33 #include "../../dataaccess/dataset/DataSet.h" 34 #include "../../dataaccess/dataset/DataSetType.h" 36 #include "../../dataaccess/datasource/DataSourceCapabilities.h" 37 #include "../../dataaccess/datasource/DataSourceInfo.h" 38 #include "../../dataaccess/datasource/DataSourceInfoManager.h" 39 #include "../../dataaccess/datasource/DataSourceManager.h" 40 #include "../../dataaccess/datasource/DataSourceFactory.h" 42 #include "../../dataaccess/utils/Utils.h" 44 #include "../../datatype/Property.h" 45 #include "../../datatype/SimpleData.h" 47 #include "../../geometry/GeometryProperty.h" 49 #include "../../qt/widgets/datasource/selector/DataSourceSelectorDialog.h" 50 #include "../../qt/widgets/layer/utils/DataSet2Layer.h" 51 #include "../../qt/widgets/progress/ProgressViewerDialog.h" 52 #include "../../qt/widgets/utils/DoubleInputListWidget.h" 53 #include "../../qt/widgets/utils/FileDialog.h" 55 #include "../ComplexData.h" 56 #include "../Exception.h" 57 #include "../Identity.h" 61 #include "ui_IdentityDialogForm.h" 65 #include <QFileDialog> 66 #include <QGridLayout> 67 #include <QMessageBox> 70 #include <boost/filesystem.hpp> 71 #include <boost/uuid/random_generator.hpp> 72 #include <boost/uuid/uuid_io.hpp> 76 te::vp::IdentityDialog::IdentityDialog(
QWidget* parent, Qt::WindowFlags f)
78 m_ui(new
Ui::IdentityDialogForm),
84 m_ui->m_imgLabel->setPixmap(
85 QIcon::fromTheme(
"vp-identity-hint").pixmap(112, 48));
86 m_ui->m_targetDatasourceToolButton->setIcon(QIcon::fromTheme(
"datasource"));
90 m_ui->m_inputSelectionGroupBox));
91 m_inputDoubleInputListWidget->setFirstLayerLabel(
"");
92 m_inputDoubleInputListWidget->setSecondLayerLabel(
"");
93 m_inputDoubleInputListWidget->setOutputLabel(
"Output attributes");
95 QGridLayout* inputLayout =
new QGridLayout(m_ui->m_inputSelectionGroupBox);
96 inputLayout->addWidget(m_inputDoubleInputListWidget.get());
97 inputLayout->setContentsMargins(0, 0, 0, 0);
99 connect(m_ui->m_inputLayerComboBox, SIGNAL(currentIndexChanged(
int)),
this,
100 SLOT(onInputLayerComboBoxChanged(
int)));
101 connect(m_ui->m_intersectionLayerComboBox, SIGNAL(currentIndexChanged(
int)),
102 this, SLOT(onIntersectionLayerComboBoxChanged(
int)));
103 connect(m_ui->m_targetDatasourceToolButton, SIGNAL(pressed()),
this,
104 SLOT(onTargetDatasourceToolButtonPressed()));
105 connect(m_ui->m_targetFileToolButton, SIGNAL(pressed()),
this,
106 SLOT(onTargetFileToolButtonPressed()));
107 connect(m_ui->m_okPushButton, SIGNAL(clicked()),
this,
108 SLOT(onOkPushButtonClicked()));
109 connect(m_ui->m_cancelPushButton, SIGNAL(clicked()),
this,
110 SLOT(onCancelPushButtonClicked()));
112 m_ui->m_helpPushButton->setNameSpace(
"dpi.inpe.br.plugins");
113 m_ui->m_helpPushButton->setPageReference(
"plugins/vp/vp_identity.html");
119 std::list<te::map::AbstractLayerPtr> layers)
121 std::list<te::map::AbstractLayerPtr>::iterator it = layers.begin();
123 while (it != layers.end())
125 std::unique_ptr<te::da::DataSetType> dsType = it->get()->getSchema();
126 if (dsType->hasGeom())
151 std::map<int, std::vector<std::string> >
154 std::map<int, std::vector<std::string> > propertiesMap;
156 std::vector<std::string> propertiesName =
159 std::vector<int> layerIds =
162 if(propertiesName.size() != layerIds.size())
163 return propertiesMap;
165 std::vector<std::string> inputProperties;
166 std::vector<std::string> intersectionProperties;
168 for (std::size_t i = 0; i < layerIds.size(); ++i)
171 inputProperties.push_back(propertiesName[i]);
173 intersectionProperties.push_back(propertiesName[i]);
176 if(!inputProperties.empty())
177 propertiesMap.insert(
178 std::pair<
int, std::vector<std::string> >(0, inputProperties));
180 if(!intersectionProperties.empty())
181 propertiesMap.insert(
182 std::pair<
int, std::vector<std::string> >(1, intersectionProperties));
184 return propertiesMap;
189 std::list<te::map::AbstractLayerPtr>::iterator it =
m_layers.begin();
191 disconnect(
m_ui->m_inputLayerComboBox, SIGNAL(currentIndexChanged(
int)),
this,
196 m_ui->m_inputLayerComboBox->addItem(QString(it->get()->getTitle().c_str()),
197 QVariant::fromValue(*it));
201 connect(
m_ui->m_inputLayerComboBox, SIGNAL(currentIndexChanged(
int)),
this,
204 QVariant varLayer =
m_ui->m_inputLayerComboBox->itemData(
205 m_ui->m_inputLayerComboBox->currentIndex(), Qt::UserRole);
213 int currIndex =
m_ui->m_inputLayerComboBox->currentIndex();
215 std::list<te::map::AbstractLayerPtr>::iterator it =
m_layers.begin();
217 disconnect(
m_ui->m_intersectionLayerComboBox,
218 SIGNAL(currentIndexChanged(
int)),
this,
223 m_ui->m_intersectionLayerComboBox->addItem(
224 QString(it->get()->getTitle().c_str()), QVariant::fromValue(*it));
228 m_ui->m_intersectionLayerComboBox->removeItem(currIndex);
230 connect(
m_ui->m_intersectionLayerComboBox, SIGNAL(currentIndexChanged(
int)),
233 QVariant varLayer =
m_ui->m_intersectionLayerComboBox->itemData(
234 m_ui->m_intersectionLayerComboBox->currentIndex(), Qt::UserRole);
242 std::vector<std::string> values;
244 std::unique_ptr<te::da::DataSetType> inputSchema;
245 std::unique_ptr<te::da::DataSetType> intersectionSchema;
247 std::vector<te::dt::Property*> inputProps;
248 std::vector<te::dt::Property*> intersectionProps;
250 std::string inputName;
251 std::string intersectionName;
256 inputProps = inputSchema->getProperties();
259 QString::fromUtf8(inputName.c_str()));
264 intersectionProps = intersectionSchema->getProperties();
267 QString::fromUtf8(intersectionName.c_str()));
271 for (std::size_t i = 0; i < inputProps.size(); ++i)
274 values.push_back(inputProps[i]->getName());
279 for (std::size_t i = 0; i < intersectionProps.size(); ++i)
282 values.push_back(intersectionProps[i]->getName());
289 QVariant varLayer =
m_ui->m_inputLayerComboBox->itemData(index, Qt::UserRole);
292 m_ui->m_intersectionLayerComboBox->clear();
305 m_ui->m_intersectionLayerComboBox->itemData(index, Qt::UserRole);
317 m_ui->m_newLayerNameLineEdit->clear();
318 m_ui->m_newLayerNameLineEdit->setEnabled(
true);
322 std::list<te::da::DataSourceInfoPtr> dsPtrList = dlg.
getSelecteds();
324 if (dsPtrList.empty())
327 std::list<te::da::DataSourceInfoPtr>::iterator it = dsPtrList.begin();
329 m_ui->m_repositoryLineEdit->setText(QString(it->get()->getTitle().c_str()));
338 m_ui->m_newLayerNameLineEdit->clear();
339 m_ui->m_repositoryLineEdit->clear();
347 QMessageBox::warning(
this, tr(
"File information"), ex.
what());
351 m_ui->m_repositoryLineEdit->setText(fileDialog.
getPath().c_str());
352 m_ui->m_newLayerNameLineEdit->setText(fileDialog.
getFileName().c_str());
355 m_ui->m_newLayerNameLineEdit->setEnabled(
false);
361 if (
m_ui->m_inputLayerComboBox->currentText().isEmpty())
363 QMessageBox::warning(
this, tr(
"Identity"),
364 tr(
"Select an input layer."));
371 if (!inputDataSource.get())
373 QMessageBox::information(
375 "The selected input data source can not be accessed.");
380 if (
m_ui->m_intersectionLayerComboBox->currentText().isEmpty())
382 QMessageBox::warning(
this, tr(
"Identity"),
383 tr(
"Select a layer to execute the operation."));
390 if (!intersectionDataSource.get())
392 QMessageBox::information(
394 "The selected intersection data source can not be accessed.");
399 std::map<int, std::vector<std::string> > attributesMap =
402 std::map<std::string, te::dt::AbstractData*> specificParams;
404 if (!attributesMap.empty())
406 std::map<int, std::vector<std::string> >::iterator it;
408 it = attributesMap.find(0);
409 if(it != attributesMap.end())
411 std::unique_ptr<te::da::DataSetType> inputSchema =
414 specificParams[inputSchema->getName()] =
418 it = attributesMap.find(1);
419 if(it != attributesMap.end())
421 std::unique_ptr<te::da::DataSetType> intersectionSchema =
424 specificParams[intersectionSchema->getName()] =
430 if(
m_ui->m_repositoryLineEdit->text().isEmpty())
432 QMessageBox::warning(
this, tr(
"Identity"),
433 tr(
"Select a repository for the resulting layer."));
437 if(
m_ui->m_newLayerNameLineEdit->text().isEmpty())
439 QMessageBox::warning(
this, tr(
"Identity"),
440 tr(
"Define a name for the resulting layer."));
447 int ret = QMessageBox::question(
448 this, tr(
"Identity"),
449 tr(
"The two layers have incompatible SRS. The result might be " 450 "incorrect. Do you wish to continue?"),
451 QMessageBox::No, QMessageBox::Yes);
452 if (ret == QMessageBox::No)
457 bool inputIsChecked =
false;
459 if (
m_ui->m_inputOnlySelectedCheckBox->isChecked())
460 inputIsChecked =
true;
463 bool intersectionIsChecked =
false;
465 if (
m_ui->m_diffOnlySelectedCheckBox->isChecked())
466 intersectionIsChecked =
true;
517 std::string outputdataset =
518 m_ui->m_newLayerNameLineEdit->text().toUtf8().data();
525 boost::filesystem::path uri(
526 m_ui->m_repositoryLineEdit->text().toUtf8().data());
530 QMessageBox::information(
531 this, tr(
"Identity"),
532 tr(
"Output file already exists. Remove it and try again. "));
537 std::size_t idx = outputdataset.find(
".");
538 if(idx != std::string::npos)
539 outputdataset = outputdataset.substr(0, idx);
541 std::string dsinfo(
"file://");
542 dsinfo += uri.string();
549 this->setCursor(Qt::WaitCursor);
568 QMessageBox::information(
569 this, tr(
"Identity"),
570 tr(
"Error: could not generate the difference."));
576 boost::uuids::basic_random_generator<boost::mt19937> gen;
577 boost::uuids::uuid u = gen();
578 std::string ds_id = boost::uuids::to_string(u);
581 ds->setConnInfo(dsinfo);
582 ds->setTitle(uri.stem().string());
583 ds->setAccessDriver(
"OGR");
585 ds->setDescription(uri.string());
598 QMessageBox::information(
599 this, tr(
"Identity"),
600 tr(
"The output data source can not be accessed."));
612 QMessageBox::information(
613 this, tr(
"Identity"),
614 tr(
"The output data source can not be accessed."));
621 if (aux->dataSetExists(name))
623 QMessageBox::information(
this, tr(
"Identity"),
624 tr(
"Dataset already exists. Remove it or " 625 "select a new name and try again."));
630 this->setCursor(Qt::WaitCursor);
647 this->setCursor(Qt::ArrowCursor);
648 QMessageBox::information(
this, tr(
"Identity"),
649 tr(
"Error: could not generate the identity."));
661 outDataSource->getDataSetType(outputdataset).release());
665 catch(
const std::exception& e)
667 this->setCursor(Qt::ArrowCursor);
668 QMessageBox::warning(
this, tr(
"Identity"), e.what());
670 std::string str =
"Vector Processing - Identity - ";
677 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.
static std::unique_ptr< DataSource > make(const std::string &driver, const te::core::URI &connInfo)
te::da::DataSetType * m_dataSetType
void setLayers(std::list< te::map::AbstractLayerPtr > layers)
Set the layer that can be used.
static bool exists(const std::string &path)
Checks if a given path in UTF-8 exists.
bool m_toFile
The result is in a file?
boost::shared_ptr< DataSetType > DataSetTypePtr
DataStruct GetDataStructFromLayer(te::map::AbstractLayerPtr layer, bool onlySelectedObjects, int srid=0)
te::da::DataSourceInfoPtr m_outputDatasource
DataSource information.
boost::shared_ptr< DataSource > DataSourcePtr
std::string Convert2LCase(const std::string &value)
It converts a string to lower case.
#define TE_UNKNOWN_SRS
A numeric value to represent a unknown SRS identification in TerraLib.
virtual const char * what() const
It outputs the exception message.
std::list< te::map::AbstractLayerPtr > m_layers
The vector layers in Layer Explorer.
void setOutputDataSetName(const std::string &outputDataSetName)
static te::dt::Date ds(2010, 01, 01)
std::vector< std::string > getWarnings()
void setOutputDataSource(te::da::DataSourcePtr outputDataSource)
void onIntersectionLayerComboBoxChanged(int index)
te::map::AbstractLayerPtr getLayer()
Q_DECLARE_METATYPE(te::map::AbstractLayerPtr) te
Get a list of AbstractLayer filtered by the name;.
std::unique_ptr< Ui::IdentityDialogForm > m_ui
void onCancelPushButtonClicked()
bool executeMemory(te::vp::AlgorithmParams *mainParams)
A template for complex data types.
static DataSourceManager & getInstance()
It returns a reference to the singleton instance.
static te::dt::TimeDuration dt(20, 30, 50, 11)
void updateIntersectionLayerComboBox()
Utility functions for the data access module.
te::map::AbstractLayerPtr m_inputSelectedLayer
Input layer selected.
This class is designed to declare objects to be thrown as exceptions by TerraLib. ...
te::map::AbstractLayerPtr m_intersectionSelectedLayer
Identity layer selected.
te::vp::AlgorithmParams * m_params
Algorithm parameters.
#define TE_LOG_ERROR(message)
Use this tag in order to log a message to the TerraLib default logger with the ERROR level...
A class that represents a data source component.
std::vector< te::vp::InputParams > m_inputParams
A vector of input parameters.
void setInputParams(const std::vector< te::vp::InputParams > &setInputParams)
te::map::AbstractLayerPtr m_layerResult
Generated Layer.
void updateDoubleListWidget()
std::vector< std::string > m_warnings
Warnings during the operation.
std::unique_ptr< te::qt::widgets::DoubleInputListWidget > m_inputDoubleInputListWidget
boost::intrusive_ptr< AbstractLayer > AbstractLayerPtr
void onTargetFileToolButtonPressed()
void onTargetDatasourceToolButtonPressed()
void setSpecificParams(const std::map< std::string, te::dt::AbstractData * > &specificParams)
void onOkPushButtonClicked()
void updateInputLayerComboBox()
void onInputLayerComboBoxChanged(int index)
te::da::DataSet * m_dataSet
boost::shared_ptr< DataSourceInfo > DataSourceInfoPtr
std::map< int, std::vector< std::string > > getSelectedProperties()
Identity operation dialog.