27 #include "../../core/filesystem/FileSystem.h" 28 #include "../../core/logger/Logger.h" 29 #include "../../core/translator/Translator.h" 30 #include "../../common/STLUtils.h" 31 #include "../../common/StringUtils.h" 34 #include "../../dataaccess/dataset/DataSet.h" 35 #include "../../dataaccess/dataset/DataSetType.h" 37 #include "../../dataaccess/datasource/DataSourceCapabilities.h" 38 #include "../../dataaccess/datasource/DataSourceFactory.h" 39 #include "../../dataaccess/datasource/DataSourceInfoManager.h" 40 #include "../../dataaccess/datasource/DataSourceManager.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/FileDialog.h" 54 #include "../../statistics/core/Utils.h" 56 #include "../Config.h" 57 #include "../Exception.h" 58 #include "../ComplexData.h" 59 #include "../Dissolve.h" 63 #include "ui_DissolveDialogForm.h" 67 #include <QFileDialog> 68 #include <QListWidgetItem> 69 #include <QMessageBox> 73 #include <boost/algorithm/string.hpp> 74 #include <boost/filesystem.hpp> 75 #include <boost/uuid/random_generator.hpp> 76 #include <boost/uuid/uuid_io.hpp> 80 m_ui(new
Ui::DissolveDialogForm),
82 m_inputLayer(nullptr),
88 m_ui->m_objectTypeGroupBox->setVisible(
false);
89 m_ui->m_statisticalSummatyGroupBox->setVisible(
false);
93 m_ui->m_imgLabel->setPixmap(QIcon::fromTheme(
"vp-dissolve-hint").pixmap(112,48));
94 m_ui->m_targetDatasourceToolButton->setIcon(QIcon::fromTheme(
"datasource"));
96 QSize iconSize(96, 48);
98 m_ui->m_singleRadioButton->setIconSize(iconSize);
99 m_ui->m_singleRadioButton->setIcon(QIcon::fromTheme(
"vp-single-objects"));
101 m_ui->m_multiRadioButton->setIconSize(iconSize);
102 m_ui->m_multiRadioButton->setIcon(QIcon::fromTheme(
"vp-multi-objects"));
109 connect(
m_ui->m_calcStatCheckBox, SIGNAL(toggled(
bool)),
this, SLOT(
onAdvanced(
bool)));
120 m_ui->m_helpPushButton->setNameSpace(
"dpi.inpe.br.plugins");
121 m_ui->m_helpPushButton->setPageReference(
"plugins/vp/vp_dissolve.html");
124 m_ui->m_newLayerNameLineEdit->setEnabled(
true);
132 std::list<te::map::AbstractLayerPtr>::iterator it =
m_layers.begin();
136 std::unique_ptr<te::da::DataSetType> dsType = it->get()->getSchema();
137 if (dsType->hasGeom())
138 m_ui->m_layersComboBox->addItem(QString(it->get()->getTitle().c_str()), QVariant(it->get()->getId().c_str()));
145 std::map<te::dt::Property*, std::vector<te::stat::StatisticalSummary> > outputStatisticalSummary;
147 QList<QListWidgetItem*> itemList =
m_ui->m_outputListWidget->selectedItems();
150 std::map<std::string, std::vector<te::stat::StatisticalSummary> > propname_stat;
151 std::map<std::string, std::vector<te::stat::StatisticalSummary> >::iterator it;
153 for(
int i = 0; i < itemList.size(); ++i)
155 std::vector<std::string> tokens;
157 std::string auxItem = itemList[i]->text().toUtf8().data();
159 boost::split(tokens, auxItem, boost::is_any_of(
":"));
163 pname.erase(pname.end() - 1);
165 it = propname_stat.find(pname);
166 if (it != propname_stat.end())
167 it->second.push_back(enumStatisticalSummary);
170 std::vector<te::stat::StatisticalSummary> nvec;
171 nvec.push_back(enumStatisticalSummary);
172 propname_stat.insert(std::make_pair(pname, nvec));
177 it = propname_stat.begin();
178 while (it != propname_stat.end())
181 outputStatisticalSummary.insert(std::make_pair(prop,it->second));
185 return outputStatisticalSummary;
191 if(propertyName ==
"")
207 std::vector<std::string> selectedPropertyNames;
209 for(
int i = 0; i !=
m_ui->m_propertieslistWidget->count(); ++i)
211 QListWidgetItem* item =
m_ui->m_propertieslistWidget->item(i);
213 if(
m_ui->m_propertieslistWidget->isItemSelected(item))
215 std::string name = item->text().toUtf8().data();
216 selectedPropertyNames.push_back(name);
220 return selectedPropertyNames;
225 if (
m_ui->m_multiRadioButton->isChecked())
243 m_ui->m_selectAllComboBox->addItem(
"");
259 m_ui->m_rejectAllComboBox->addItem(
"");
298 m_ui->m_selectAllComboBox->setCurrentIndex(0);
299 m_ui->m_rejectAllComboBox->setCurrentIndex(0);
300 m_ui->m_outputListWidget->clear();
306 for(
size_t i=0; i < properties.size(); ++i)
308 propertyType = properties[i]->getType();
316 m_ui->m_outputListWidget->addItem(item);
320 m_ui->m_outputListWidget->addItem(item);
324 m_ui->m_outputListWidget->addItem(item);
328 m_ui->m_outputListWidget->addItem(item);
330 item =
new QListWidgetItem(
"");
331 m_ui->m_outputListWidget->addItem(item);
337 m_ui->m_outputListWidget->addItem(item);
341 m_ui->m_outputListWidget->addItem(item);
345 m_ui->m_outputListWidget->addItem(item);
349 m_ui->m_outputListWidget->addItem(item);
353 m_ui->m_outputListWidget->addItem(item);
357 m_ui->m_outputListWidget->addItem(item);
361 m_ui->m_outputListWidget->addItem(item);
365 m_ui->m_outputListWidget->addItem(item);
369 m_ui->m_outputListWidget->addItem(item);
372 if (!dsCapabilities.supportsPreparedQueryAPI())
376 m_ui->m_outputListWidget->addItem(item);
380 m_ui->m_outputListWidget->addItem(item);
384 m_ui->m_outputListWidget->addItem(item);
388 m_ui->m_outputListWidget->addItem(item);
392 m_ui->m_outputListWidget->addItem(item);
395 item =
new QListWidgetItem(
"");
396 m_ui->m_outputListWidget->addItem(item);
400 int lastRow =
m_ui->m_outputListWidget->count() - 1;
401 delete m_ui->m_outputListWidget->item(lastRow);
406 std::list<te::map::AbstractLayerPtr>::iterator it =
m_layers.begin();
408 std::string layerID =
m_ui->m_layersComboBox->itemData(index, Qt::UserRole).toString().toUtf8().data();
410 m_ui->m_propertieslistWidget->clear();
414 if(layerID == it->get()->getId())
419 std::unique_ptr<const te::map::LayerSchema> schema(selectedLayer->getSchema());
421 if(schema->size() == 0)
427 const std::vector<te::dt::Property*>& properties = schema->getProperties();
449 m_ui->m_outputListWidget->reset();
450 m_ui->m_objectTypeGroupBox->setVisible(visible);
451 m_ui->m_statisticalSummatyGroupBox->setVisible(visible);
456 m_ui->m_statisticalSummatyGroupBox->setEnabled(checked);
457 m_ui->m_selectAllComboBox->setEnabled(checked);
458 m_ui->m_rejectAllComboBox->setEnabled(checked);
459 m_ui->m_outputListWidget->setEnabled(checked);
463 m_ui->m_selectAllComboBox->setCurrentIndex(0);
464 m_ui->m_rejectAllComboBox->setCurrentIndex(0);
465 m_ui->m_outputListWidget->clearSelection();
471 QList<QListWidgetItem*> allItems;
472 int count =
m_ui->m_propertieslistWidget->count();
473 for(
int index = 0; index < count; ++index)
475 allItems.push_back(
m_ui->m_propertieslistWidget->item(index));
478 QList<QListWidgetItem*> filteredItems =
m_ui->m_propertieslistWidget->findItems(text, Qt::MatchContains | Qt::MatchRecursive);
480 for(
int i = 0; i < allItems.size(); ++i)
482 QListWidgetItem* item = allItems.at(i);
483 bool hide = filteredItems.indexOf(item) == -1;
484 item->setHidden(hide);
487 m_ui->m_propertieslistWidget->update();
492 QString text =
m_ui->m_selectAllComboBox->itemText(index);
493 Qt::MatchFlags flag = Qt::MatchEndsWith;
498 QList<QListWidgetItem *> listFound;
499 listFound =
m_ui->m_outputListWidget->findItems(text, flag);
501 for(
int i=0; i < listFound.size(); ++i)
502 listFound.at(i)->setSelected(
true);
504 m_ui->m_rejectAllComboBox->setCurrentIndex(0);
509 QString text =
m_ui->m_selectAllComboBox->itemText(index);
510 Qt::MatchFlags flag = Qt::MatchEndsWith;
515 QList<QListWidgetItem *> listFound;
516 listFound =
m_ui->m_outputListWidget->findItems(text, flag);
518 for(
int i=0; i < listFound.size(); ++i)
519 listFound.at(i)->setSelected(
false);
521 m_ui->m_selectAllComboBox->setCurrentIndex(0);
526 if(item->text().isEmpty())
528 item->setSelected(
false);
534 m_ui->m_newLayerNameLineEdit->clear();
535 m_ui->m_newLayerNameLineEdit->setEnabled(
true);
539 std::list<te::da::DataSourceInfoPtr> dsPtrList = dlg.
getSelecteds();
541 if(dsPtrList.empty())
544 std::list<te::da::DataSourceInfoPtr>::iterator it = dsPtrList.begin();
546 m_ui->m_repositoryLineEdit->setText(QString(it->get()->getTitle().c_str()));
555 m_ui->m_newLayerNameLineEdit->clear();
556 m_ui->m_repositoryLineEdit->clear();
564 QMessageBox::warning(
this, tr(
"File information"), ex.
what());
568 m_ui->m_repositoryLineEdit->setText(fileDialog.
getPath().c_str());
569 m_ui->m_newLayerNameLineEdit->setText(fileDialog.
getFileName().c_str());
572 m_ui->m_newLayerNameLineEdit->setEnabled(
false);
578 if (
m_ui->m_layersComboBox->count() == 0)
580 QMessageBox::information(
this, tr(
"Dissolve"), tr(
"Select an input layer."));
586 if (!inputDataSource.get())
588 QMessageBox::information(
this, tr(
"Dissolve"), tr(
"The selected input data source can not be accessed."));
594 if (selProperties.empty())
596 QMessageBox::information(
this, tr(
"Dissolve"), tr(
"Select at least one grouping attribute."));
601 std::map<std::string, te::dt::AbstractData*> specificParams;
607 std::map<te::dt::Property*, std::vector<te::stat::StatisticalSummary> > outputStatisticalSummary =
getStatisticalSummary();
612 if (
m_ui->m_repositoryLineEdit->text().isEmpty())
614 QMessageBox::information(
this, tr(
"Dissolve"), tr(
"Define a repository for the result."));
618 std::string outputdataset =
m_ui->m_newLayerNameLineEdit->text().toUtf8().data();
620 if (outputdataset.empty())
622 QMessageBox::information(
this, tr(
"Dissolve"), tr(
"Define a name for the resulting layer."));
627 bool inputIsChecked =
false;
629 if (
m_ui->m_onlySelectedCheckBox->isChecked())
630 inputIsChecked =
true;
635 this->setCursor(Qt::WaitCursor);
650 this->setCursor(Qt::ArrowCursor);
651 QMessageBox::information(
this, tr(
"Dissolve"), tr(
"Problem to get geometry property of input layer."));
661 bool isQuery =
false;
695 boost::filesystem::path uri(
m_ui->m_repositoryLineEdit->text().toUtf8().data());
699 this->setCursor(Qt::ArrowCursor);
700 QMessageBox::information(
this, tr(
"Dissolve"), tr(
"Output file already exists. Remove it and try again. "));
705 std::size_t idx = outputdataset.find(
".");
706 if (idx != std::string::npos)
707 outputdataset = outputdataset.substr(0, idx);
736 this->setCursor(Qt::ArrowCursor);
737 QMessageBox::information(
this, tr(
"Dissolve"), tr(
"Error: could not generate the dissolve."));
746 this->setCursor(Qt::ArrowCursor);
747 QMessageBox::information(
this, tr(
"Dissolve"), tr(
"The output data source can not be accessed."));
761 this->setCursor(Qt::ArrowCursor);
762 QMessageBox::information(
this, tr(
"Dissolve"), tr(
"The output data source can not be accessed."));
769 if (aux->dataSetExists(name))
771 this->setCursor(Qt::ArrowCursor);
772 QMessageBox::information(
this, tr(
"Dissolve"), tr(
"Dataset already exists. Remove it or select a new name and try again."));
803 this->setCursor(Qt::ArrowCursor);
804 QMessageBox::information(
this, tr(
"Dissolve"), tr(
"Error: could not generate the dissolve."));
817 catch(
const std::exception& e)
819 this->setCursor(Qt::ArrowCursor);
821 QMessageBox::information(
this,
"Dissolve", e.what());
823 std::string str =
"Vector Processing - Dissolve - ";
830 this->setCursor(Qt::ArrowCursor);
void onTargetFileToolButtonPressed()
TEDATAACCESSEXPORT DataSourcePtr GetDataSource(const std::string &datasourceId, const bool opened=true)
Search for a data source with the informed id in the DataSourceManager.
void setOutputSRID(const int &outputSRID)
te::vp::AlgorithmParams * m_params
Algorithm parameters.
te::da::DataSetType * m_dataSetType
te::map::AbstractLayerPtr m_inputLayer
Layer used for dissolve.
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
TEVPEXPORT te::da::DataSourcePtr CreateOGRDataSource(std::string repository)
DataStruct GetDataStructFromLayer(te::map::AbstractLayerPtr layer, bool onlySelectedObjects, int srid=0)
boost::shared_ptr< DataSource > DataSourcePtr
std::string Convert2LCase(const std::string &value)
It converts a string to lower case.
const std::vector< std::string > & getWarnings()
void onFilterLineEditTextChanged(const QString &text)
virtual const char * what() const
It outputs the exception message.
void onTargetDatasourceToolButtonPressed()
bool executeQuery(te::vp::AlgorithmParams *mainParams)
void setStatisticalSummaryMap()
Map Statistical Summary Type enum for an intuitive name.
std::vector< std::string > m_warnings
Warnings during the operation.
void onCancelPushButtonClicked()
void onAdvanced(bool visible)
DissolveDialog(QWidget *parent=0, Qt::WindowFlags f=0)
void setOutputDataSetName(const std::string &outputDataSetName)
A class that represents the known capabilities of a specific data source, i.e. this class informs all...
void setOutputDataSource(te::da::DataSourcePtr outputDataSource)
const QueryCapabilities & getQueryCapabilities() const
It models a property definition.
std::vector< std::string > getWarnings()
Get warning messages.
void setLayers(std::list< te::map::AbstractLayerPtr > layers)
Set the layer that can be used.
Get a list of AbstractLayer filtered by the name;.
void onRejectAllComboBoxChanged(int index)
A template for complex data types.
static DataSourceInfoManager & getInstance()
It returns a reference to the singleton instance.
bool executeMemory(te::vp::AlgorithmParams *mainParams)
static te::dt::TimeDuration dt(20, 30, 50, 11)
te::map::AbstractLayerPtr m_layer
Generated Layer.
void onOutputListWidgetClicked(QListWidgetItem *item)
TESTATEXPORT std::string GetStatSummaryFullName(const int &e)
Get the statistical parameter full name ffrom its enumerator.
bool supportsSpatialSQLDialect() const
std::list< te::map::AbstractLayerPtr > m_layers
List of layers.
Utility functions for the data access module.
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.
std::vector< te::vp::InputParams > m_inputParams
A vector of input parameters.
void setFunctionsByLayer(std::vector< te::dt::Property * > properties)
Set Grouping Functions Type for 'm_outputListWidget' based on Selected Layer.
bool isCollection()
Verify if the output result is a collection or single geometry.
void setStatisticalSummary()
Set Statistical Summary Type for combobox 'm_selectAllComboBox' and 'm_rejectAllComboBox' based on a ...
void onLayerComboBoxChanged(int index)
#define TE_LOG_ERROR(message)
Use this tag in order to log a message to the TerraLib default logger with the ERROR level...
void setInputParams(const std::vector< te::vp::InputParams > &setInputParams)
std::map< te::dt::Property *, std::vector< te::stat::StatisticalSummary > > getStatisticalSummary()
Get the Grouping Functions Type based on selected QListWidgetItem.
bool m_toFile
The output file is in a file.
void onSelectAllComboBoxChanged(int index)
A layer with reference to a dataset.
std::unique_ptr< Ui::DissolveDialogForm > m_ui
DialogForm.
StatisticalSummary
Define grouping functions type.
A template for atomic data types (integers, floats, strings and others).
void onMultiGeometryChecked(bool checked)
A dialog dissolve operation.
TEDATAACCESSEXPORT te::gm::GeometryProperty * GetFirstGeomProperty(const DataSetType *dt)
te::dt::Property * getSelectedPropertyByName(std::string propertyName)
Get the selected property based on selected QListWidgetItem using the name of property.
StaticalSummaryMap m_StatisticalSummaryMap
Maping of Statistical Summary enum.
void Clone(const std::vector< T * > &src, std::vector< T * > &dst)
This function can be applied to a vector of pointers.
std::vector< te::dt::Property * > m_properties
Properties related to the selected Layer.
boost::intrusive_ptr< AbstractLayer > AbstractLayerPtr
void FreeContents(boost::unordered_map< K, V * > &m)
This function can be applied to a map of pointers. It will delete each pointer in the map...
void onOkPushButtonClicked()
void setSpecificParams(const std::map< std::string, te::dt::AbstractData * > &specificParams)
virtual const std::string & getDataSourceId() const
te::map::AbstractLayerPtr getLayer()
Get the generated layer.
te::da::DataSet * m_dataSet
te::da::DataSourceInfoPtr m_outputDatasource
DataSource information.
std::vector< std::string > getSelectedPropertyNames()
Get the selected properties based on selected QListWidgetItem.
boost::shared_ptr< DataSourceInfo > DataSourceInfoPtr