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/DoubleListWidget.h" 53 #include "../../qt/widgets/utils/FileDialog.h" 55 #include "../ComplexData.h" 56 #include "../Exception.h" 57 #include "../Difference.h" 61 #include "ui_DifferenceDialogForm.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> 77 te::vp::DifferenceDialog::DifferenceDialog(
QWidget* parent, Qt::WindowFlags f)
79 m_ui(new
Ui::DifferenceDialogForm),
85 m_ui->m_imgLabel->setPixmap(QIcon::fromTheme(
"vp-difference-hint").pixmap(112, 48));
86 m_ui->m_targetDatasourceToolButton->setIcon(QIcon::fromTheme(
"datasource"));
90 m_doubleListWidget->setLeftLabel(
"");
91 m_doubleListWidget->setRightLabel(
"");
93 QGridLayout* layout =
new QGridLayout(m_ui->m_specificParamsTabWidget->widget(0));
94 layout->addWidget(m_doubleListWidget.get());
95 layout->setContentsMargins(0, 0, 0, 0);
97 QSize iconSize(96, 48);
99 m_ui->m_singleRadioButton->setIconSize(iconSize);
100 m_ui->m_singleRadioButton->setIcon(QIcon::fromTheme(
"vp-single-objects"));
102 m_ui->m_multiRadioButton->setIconSize(iconSize);
103 m_ui->m_multiRadioButton->setIcon(QIcon::fromTheme(
"vp-multi-objects"));
105 connect(m_ui->m_inputLayerComboBox, SIGNAL(currentIndexChanged(
int)),
this, SLOT(onInputLayerComboBoxChanged(
int)));
106 connect(m_ui->m_differenceLayerComboBox, SIGNAL(currentIndexChanged(
int)),
this, SLOT(onDifferenceLayerComboBoxChanged(
int)));
107 connect(m_ui->m_targetDatasourceToolButton, SIGNAL(pressed()),
this, SLOT(onTargetDatasourceToolButtonPressed()));
108 connect(m_ui->m_targetFileToolButton, SIGNAL(pressed()),
this, SLOT(onTargetFileToolButtonPressed()));
109 connect(m_ui->m_okPushButton, SIGNAL(clicked()),
this, SLOT(onOkPushButtonClicked()));
110 connect(m_ui->m_cancelPushButton, SIGNAL(clicked()),
this, SLOT(onCancelPushButtonClicked()));
112 m_ui->m_helpPushButton->setNameSpace(
"dpi.inpe.br.plugins");
113 m_ui->m_helpPushButton->setPageReference(
"plugins/vp/vp_difference.html");
120 std::list<te::map::AbstractLayerPtr>::iterator it = layers.begin();
122 while (it != layers.end())
124 std::unique_ptr<te::da::DataSetType> dsType = it->get()->getSchema();
125 if (dsType->hasGeom())
148 std::vector<std::string> result;
150 for (std::size_t i = 0; i < outVec.size(); ++i)
152 std::vector<std::string> tok;
155 result.push_back(tok[1]);
163 if (
m_ui->m_singleRadioButton->isChecked())
171 std::list<te::map::AbstractLayerPtr>::iterator it =
m_layers.begin();
177 m_ui->m_inputLayerComboBox->addItem(QString(it->get()->getTitle().c_str()), QVariant::fromValue(*it));
183 QVariant varLayer =
m_ui->m_inputLayerComboBox->itemData(
m_ui->m_inputLayerComboBox->currentIndex(), Qt::UserRole);
191 int currIndex =
m_ui->m_inputLayerComboBox->currentIndex();
193 std::list<te::map::AbstractLayerPtr>::iterator it =
m_layers.begin();
199 m_ui->m_differenceLayerComboBox->addItem(QString(it->get()->getTitle().c_str()), QVariant::fromValue(*it));
203 m_ui->m_differenceLayerComboBox->removeItem(currIndex);
207 QVariant varLayer =
m_ui->m_differenceLayerComboBox->itemData(
m_ui->m_differenceLayerComboBox->currentIndex(), Qt::UserRole);
215 std::vector<std::string> inputValues;
217 std::unique_ptr<te::da::DataSetType> inputSchema;
224 std::vector<te::dt::Property*> inputProps = inputSchema->getProperties();
225 for (std::size_t i = 0; i < inputProps.size(); ++i)
229 std::string name = inputSchema->getTitle();
232 name = inputSchema->getName();
234 inputValues.push_back(name +
": " + inputProps[i]->getName());
243 QVariant varLayer =
m_ui->m_inputLayerComboBox->itemData(index, Qt::UserRole);
246 m_ui->m_differenceLayerComboBox->clear();
258 QVariant varLayer =
m_ui->m_differenceLayerComboBox->itemData(index, Qt::UserRole);
266 m_ui->m_newLayerNameLineEdit->clear();
267 m_ui->m_newLayerNameLineEdit->setEnabled(
true);
271 std::list<te::da::DataSourceInfoPtr> dsPtrList = dlg.
getSelecteds();
273 if (dsPtrList.empty())
276 std::list<te::da::DataSourceInfoPtr>::iterator it = dsPtrList.begin();
278 m_ui->m_repositoryLineEdit->setText(QString(it->get()->getTitle().c_str()));
287 m_ui->m_newLayerNameLineEdit->clear();
288 m_ui->m_repositoryLineEdit->clear();
297 QMessageBox::warning(
this, tr(
"File information"), ex.
what());
301 m_ui->m_repositoryLineEdit->setText(fileDialog.
getPath().c_str());
302 m_ui->m_newLayerNameLineEdit->setText(fileDialog.
getFileName().c_str());
305 m_ui->m_newLayerNameLineEdit->setEnabled(
false);
311 if (
m_ui->m_inputLayerComboBox->currentText().isEmpty())
313 QMessageBox::warning(
this,
TE_TR(
"Difference"),
TE_TR(
"Select an input layer."));
319 if (!inputDataSource.get())
321 QMessageBox::information(
this,
"Difference",
"The selected input data source can not be accessed.");
327 if (
m_ui->m_differenceLayerComboBox->currentText().isEmpty())
329 QMessageBox::warning(
this,
TE_TR(
"Difference"),
TE_TR(
"Select a layer to do the difference."));
335 if (!differenceDataSource.get())
337 QMessageBox::information(
this,
"Difference",
"The selected difference data source can not be accessed.");
343 std::map<std::string, te::dt::AbstractData*> specificParams;
345 if (!attributesVec.empty())
355 if(
m_ui->m_repositoryLineEdit->text().isEmpty())
357 QMessageBox::warning(
this, tr(
"Difference"), tr(
"Select a repository for the resulting layer."));
361 if(
m_ui->m_newLayerNameLineEdit->text().isEmpty())
363 QMessageBox::warning(
this, tr(
"Difference"), tr(
"Define a name for the resulting layer."));
370 int ret = QMessageBox::question(
this,
"Difference",
"The two layers have incompatible SRS. The result might be incorrect. Do you wish to continue?", QMessageBox::No, QMessageBox::Yes);
371 if (ret == QMessageBox::No)
376 bool inputIsChecked =
false;
378 if (
m_ui->m_inputOnlySelectedCheckBox->isChecked())
379 inputIsChecked =
true;
383 bool differenceIsChecked =
false;
385 if (
m_ui->m_diffOnlySelectedCheckBox->isChecked())
386 differenceIsChecked =
true;
415 QMessageBox::information(
this,
"Difference",
"Problem to get geometry property of input layer.");
426 int differenceSRID = 0;
430 QMessageBox::information(
this,
"Difference",
"Problem to get geometry property of difference layer.");
443 bool isQuery =
false;
450 (inputDataSource->getId() == differenceDataSource->getId()) &&
462 if (differenceSelect)
493 std::string outputdataset =
m_ui->m_newLayerNameLineEdit->text().toUtf8().data();
500 boost::filesystem::path uri(
m_ui->m_repositoryLineEdit->text().toUtf8().data());
504 QMessageBox::information(
this,
"Difference",
"Output file already exists. Remove it and try again. ");
509 std::size_t idx = outputdataset.find(
".");
510 if(idx != std::string::npos)
511 outputdataset = outputdataset.substr(0, idx);
513 std::string dsinfo(
"file://");
514 dsinfo += uri.string();
520 this->setCursor(Qt::WaitCursor);
544 QMessageBox::information(
this,
"Difference",
"Error: could not generate the difference.");
546 this->setCursor(Qt::ArrowCursor);
552 boost::uuids::basic_random_generator<boost::mt19937> gen;
553 boost::uuids::uuid u = gen();
554 std::string ds_id = boost::uuids::to_string(u);
557 ds->setConnInfo(dsinfo);
558 ds->setTitle(uri.stem().string());
559 ds->setAccessDriver(
"OGR");
561 ds->setDescription(uri.string());
571 QMessageBox::information(
this,
"Difference",
"The output data source can not be accessed.");
573 this->setCursor(Qt::ArrowCursor);
585 QMessageBox::information(
this,
"Difference",
"The output data source can not be accessed.");
592 if (aux->dataSetExists(name))
594 QMessageBox::information(
this,
"Difference",
"Dataset already exists. Remove it or select a new name and try again.");
599 this->setCursor(Qt::WaitCursor);
623 this->setCursor(Qt::ArrowCursor);
624 QMessageBox::information(
this,
"Difference",
"Error: could not generate the difference.");
637 catch(
const std::exception& e)
639 this->setCursor(Qt::ArrowCursor);
640 QMessageBox::warning(
this, tr(
"Difference"), e.what());
642 std::string str =
"Vector Processing - Difference - ";
649 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
static bool exists(const std::string &path)
Checks if a given path in UTF-8 exists.
te::da::Select * GetSelectQueryFromLayer(te::map::AbstractLayerPtr layer, bool onlySelectedObjects, int srid=0)
boost::shared_ptr< DataSetType > DataSetTypePtr
te::map::AbstractLayerPtr m_inputSelectedLayer
Input layer selected.
void updateDifferenceLayerComboBox()
DataStruct GetDataStructFromLayer(te::map::AbstractLayerPtr layer, bool onlySelectedObjects, int srid=0)
void onDifferenceLayerComboBoxChanged(int index)
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.
te::map::AbstractLayerPtr getLayer()
void onOkPushButtonClicked()
Q_DECLARE_METATYPE(te::map::AbstractLayerPtr) te
te::map::AbstractLayerPtr m_layerResult
Generated Layer.
virtual const char * what() const
It outputs the exception message.
std::vector< std::string > getSelectedProperties()
void onInputLayerComboBoxChanged(int index)
te::da::DataSourceInfoPtr m_outputDatasource
DataSource information.
void setOutputDataSetName(const std::string &outputDataSetName)
A class that represents the known capabilities of a specific data source, i.e. this class informs all...
static te::dt::Date ds(2010, 01, 01)
#define TE_TR(message)
It marks a string in order to get translated.
void setOutputDataSource(te::da::DataSourcePtr outputDataSource)
const QueryCapabilities & getQueryCapabilities() const
std::list< te::map::AbstractLayerPtr > m_layers
The vector layers in Layer Explorer.
Get a list of AbstractLayer filtered by the name;.
bool executeQuery(te::vp::AlgorithmParams *mainParams)
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.
te::vp::AlgorithmParams * m_params
Algorithm parameters.
std::vector< te::vp::InputParams > m_inputParams
A vector of input parameters.
A template for complex data types.
int getSRID() const
It returns the spatial reference system identifier associated to this property.
static DataSourceManager & getInstance()
It returns a reference to the singleton instance.
void updateInputLayerComboBox()
std::unique_ptr< Ui::DifferenceDialogForm > m_ui
static te::dt::TimeDuration dt(20, 30, 50, 11)
void onTargetDatasourceToolButtonPressed()
void onCancelPushButtonClicked()
bool supportsSpatialSQLDialect() const
std::unique_ptr< te::qt::widgets::DoubleListWidget > m_doubleListWidget
Utility functions for the data access module.
te::gm::Geometry * difference(te::gm::Geometry *g1, te::gm::Geometry *g2)
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.
te::map::AbstractLayerPtr m_differenceSelectedLayer
Difference layer selected.
#define TE_LOG_ERROR(message)
Use this tag in order to log a message to the TerraLib default logger with the ERROR level...
bool executeMemory(te::vp::AlgorithmParams *mainParams)
void updateDoubleListWidget()
A class that represents a data source component.
void setInputParams(const std::vector< te::vp::InputParams > &setInputParams)
bool m_toFile
The result is in a file?
A template for atomic data types (integers, floats, strings and others).
void setLayers(std::list< te::map::AbstractLayerPtr > layers)
Set the layer that can be used.
TEDATAACCESSEXPORT te::gm::GeometryProperty * GetFirstGeomProperty(const DataSetType *dt)
void onTargetFileToolButtonPressed()
boost::intrusive_ptr< AbstractLayer > AbstractLayerPtr
void setSpecificParams(const std::map< std::string, te::dt::AbstractData * > &specificParams)
Difference operation dialog.
te::da::DataSet * m_dataSet
boost::shared_ptr< DataSourceInfo > DataSourceInfoPtr