DissolveDialog.cpp
Go to the documentation of this file.
1 /* Copyright (C) 2008 National Institute For Space Research (INPE) - Brazil.
2 
3  This file is part of the TerraLib - a Framework for building GIS enabled applications.
4 
5  TerraLib is free software: you can redistribute it and/or modify
6  it under the terms of the GNU Lesser General Public License as published by
7  the Free Software Foundation, either version 3 of the License,
8  or (at your option) any later version.
9 
10  TerraLib is distributed in the hope that it will be useful,
11  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  GNU Lesser General Public License for more details.
14 
15  You should have received a copy of the GNU Lesser General Public License
16  along with TerraLib. See COPYING. If not, write to
17  TerraLib Team at <terralib-team@terralib.org>.
18  */
19 
20 /*!
21  \file terralib/vp/DissolveDialog.cpp
22 
23  \brief A dialog for dissolve operation
24 */
25 
26 // TerraLib
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"
32 
33 
34 #include "../../dataaccess/dataset/DataSet.h"
35 #include "../../dataaccess/dataset/DataSetType.h"
36 
37 #include "../../dataaccess/datasource/DataSourceCapabilities.h"
38 #include "../../dataaccess/datasource/DataSourceFactory.h"
39 #include "../../dataaccess/datasource/DataSourceInfoManager.h"
40 #include "../../dataaccess/datasource/DataSourceManager.h"
41 
42 #include "../../dataaccess/utils/Utils.h"
43 
44 #include "../../datatype/Property.h"
45 #include "../../datatype/SimpleData.h"
46 
47 #include "../../geometry/GeometryProperty.h"
48 
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"
53 
54 #include "../../statistics/core/Utils.h"
55 
56 #include "../Config.h"
57 #include "../Exception.h"
58 #include "../ComplexData.h"
59 #include "../Dissolve.h"
60 #include "../Utils.h"
61 
62 #include "DissolveDialog.h"
63 #include "ui_DissolveDialogForm.h"
64 #include "Utils.h"
65 
66 // Qt
67 #include <QFileDialog>
68 #include <QListWidgetItem>
69 #include <QMessageBox>
70 #include <QString>
71 
72 // Boost
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>
77 
79  : QDialog(parent, f),
80  m_ui(new Ui::DissolveDialogForm),
81  m_layers(std::list<te::map::AbstractLayerPtr>()),
82  m_inputLayer(nullptr),
83  m_toFile(false)
84 {
85 // add controls
86  m_ui->setupUi(this);
87 
88  m_ui->m_objectTypeGroupBox->setVisible(false);
89  m_ui->m_statisticalSummatyGroupBox->setVisible(false);
90  this->onMultiGeometryChecked(false);
91 
92 // add icons
93  m_ui->m_imgLabel->setPixmap(QIcon::fromTheme("vp-dissolve-hint").pixmap(112,48));
94  m_ui->m_targetDatasourceToolButton->setIcon(QIcon::fromTheme("datasource"));
95 
96  QSize iconSize(96, 48);
97 
98  m_ui->m_singleRadioButton->setIconSize(iconSize);
99  m_ui->m_singleRadioButton->setIcon(QIcon::fromTheme("vp-single-objects"));
100 
101  m_ui->m_multiRadioButton->setIconSize(iconSize);
102  m_ui->m_multiRadioButton->setIcon(QIcon::fromTheme("vp-multi-objects"));
103 
104  this->setStatisticalSummary();
105  this->setStatisticalSummaryMap();
106 
107  connect(m_ui->m_layersComboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(onLayerComboBoxChanged(int)));
108  connect(m_ui->m_filterLineEdit, SIGNAL(textChanged(const QString&)), this, SLOT(onFilterLineEditTextChanged(const QString&)));
109  connect(m_ui->m_calcStatCheckBox, SIGNAL(toggled(bool)), this, SLOT(onAdvanced(bool)));
110  connect(m_ui->m_multiRadioButton, SIGNAL(toggled(bool)), this, SLOT(onMultiGeometryChecked(bool)));
111  connect(m_ui->m_outputListWidget, SIGNAL(itemClicked(QListWidgetItem *)), this, SLOT(onOutputListWidgetClicked(QListWidgetItem *)));
112  connect(m_ui->m_selectAllComboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(onSelectAllComboBoxChanged(int)));
113  connect(m_ui->m_rejectAllComboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(onRejectAllComboBoxChanged(int)));
114  connect(m_ui->m_targetDatasourceToolButton, SIGNAL(pressed()), this, SLOT(onTargetDatasourceToolButtonPressed()));
115  connect(m_ui->m_targetFileToolButton, SIGNAL(pressed()), this, SLOT(onTargetFileToolButtonPressed()));
116 
117  connect(m_ui->m_okPushButton, SIGNAL(clicked()), this, SLOT(onOkPushButtonClicked()));
118  connect(m_ui->m_cancelPushButton, SIGNAL(clicked()), this, SLOT(onCancelPushButtonClicked()));
119 
120  m_ui->m_helpPushButton->setNameSpace("dpi.inpe.br.plugins");
121  m_ui->m_helpPushButton->setPageReference("plugins/vp/vp_dissolve.html");
122 
124  m_ui->m_newLayerNameLineEdit->setEnabled(true);
125 }
126 
128 
129 void te::vp::DissolveDialog::setLayers(std::list<te::map::AbstractLayerPtr> layers)
130 {
131  m_layers = layers;
132  std::list<te::map::AbstractLayerPtr>::iterator it = m_layers.begin();
133 
134  while (it != m_layers.end())
135  {
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()));
139  ++it;
140  }
141 }
142 
143 std::map<te::dt::Property*, std::vector<te::stat::StatisticalSummary> > te::vp::DissolveDialog::getStatisticalSummary()
144 {
145  std::map<te::dt::Property*, std::vector<te::stat::StatisticalSummary> > outputStatisticalSummary;
146 
147  QList<QListWidgetItem*> itemList = m_ui->m_outputListWidget->selectedItems();
148 
149  te::stat::StatisticalSummary enumStatisticalSummary;
150  std::map<std::string, std::vector<te::stat::StatisticalSummary> > propname_stat;
151  std::map<std::string, std::vector<te::stat::StatisticalSummary> >::iterator it;
152 
153  for(int i = 0; i < itemList.size(); ++i)
154  {
155  std::vector<std::string> tokens;
156  std::string pname;
157  std::string auxItem = itemList[i]->text().toUtf8().data();
158 
159  boost::split(tokens, auxItem, boost::is_any_of(":"));
160  if(tokens[0] != "")
161  {
162  pname = tokens[0];
163  pname.erase(pname.end() - 1);
164  enumStatisticalSummary = (te::stat::StatisticalSummary)itemList[i]->data(Qt::UserRole).toInt();
165  it = propname_stat.find(pname);
166  if (it != propname_stat.end())
167  it->second.push_back(enumStatisticalSummary);
168  else
169  {
170  std::vector<te::stat::StatisticalSummary> nvec;
171  nvec.push_back(enumStatisticalSummary);
172  propname_stat.insert(std::make_pair(pname, nvec));
173  }
174  }
175  }
176 
177  it = propname_stat.begin();
178  while (it != propname_stat.end())
179  {
180  te::dt::Property* prop = getSelectedPropertyByName(it->first);
181  outputStatisticalSummary.insert(std::make_pair(prop,it->second));
182  ++it;
183  }
184 
185  return outputStatisticalSummary;
186 }
187 
189 {
190  te::dt::Property* selProperty;
191  if(propertyName == "")
192  return nullptr;
193 
194  for(std::size_t i = 0; i < m_properties.size(); ++i)
195  {
196  if(propertyName == m_properties[i]->getName())
197  {
198  selProperty = m_properties[i];
199  return selProperty;
200  }
201  }
202  return nullptr;
203 }
204 
206 {
207  std::vector<std::string> selectedPropertyNames;
208 
209  for(int i = 0; i != m_ui->m_propertieslistWidget->count(); ++i)
210  {
211  QListWidgetItem* item = m_ui->m_propertieslistWidget->item(i);
212 
213  if(m_ui->m_propertieslistWidget->isItemSelected(item))
214  {
215  std::string name = item->text().toUtf8().data();
216  selectedPropertyNames.push_back(name);
217  }
218  }
219 
220  return selectedPropertyNames;
221 }
222 
224 {
225  if (m_ui->m_multiRadioButton->isChecked())
226  return true;
227 
228  return false;
229 }
230 
232 {
233  return m_layer;
234 }
235 
236 std::vector<std::string> te::vp::DissolveDialog::getWarnings()
237 {
238  return m_warnings;
239 }
240 
242 {
243  m_ui->m_selectAllComboBox->addItem("");
244  m_ui->m_selectAllComboBox->addItem(QString(te::stat::GetStatSummaryFullName(te::stat::MIN_VALUE).c_str()), te::stat::MIN_VALUE);
245  m_ui->m_selectAllComboBox->addItem(QString(te::stat::GetStatSummaryFullName(te::stat::MAX_VALUE).c_str()), te::stat::MAX_VALUE);
246  m_ui->m_selectAllComboBox->addItem(QString(te::stat::GetStatSummaryFullName(te::stat::MEAN).c_str()), te::stat::MEAN);
247  m_ui->m_selectAllComboBox->addItem(QString(te::stat::GetStatSummaryFullName(te::stat::SUM).c_str()), te::stat::SUM);
248  m_ui->m_selectAllComboBox->addItem(QString(te::stat::GetStatSummaryFullName(te::stat::COUNT).c_str()), te::stat::COUNT);
249  m_ui->m_selectAllComboBox->addItem(QString(te::stat::GetStatSummaryFullName(te::stat::VALID_COUNT).c_str()), te::stat::VALID_COUNT);
251  m_ui->m_selectAllComboBox->addItem(QString(te::stat::GetStatSummaryFullName(te::stat::VARIANCE).c_str()), te::stat::VARIANCE);
252  m_ui->m_selectAllComboBox->addItem(QString(te::stat::GetStatSummaryFullName(te::stat::SKEWNESS).c_str()), te::stat::SKEWNESS);
253  m_ui->m_selectAllComboBox->addItem(QString(te::stat::GetStatSummaryFullName(te::stat::KURTOSIS).c_str()), te::stat::KURTOSIS);
254  m_ui->m_selectAllComboBox->addItem(QString(te::stat::GetStatSummaryFullName(te::stat::AMPLITUDE).c_str()), te::stat::AMPLITUDE);
255  m_ui->m_selectAllComboBox->addItem(QString(te::stat::GetStatSummaryFullName(te::stat::MEDIAN).c_str()), te::stat::MEDIAN);
256  m_ui->m_selectAllComboBox->addItem(QString(te::stat::GetStatSummaryFullName(te::stat::VAR_COEFF).c_str()), te::stat::VAR_COEFF);
257  m_ui->m_selectAllComboBox->addItem(QString(te::stat::GetStatSummaryFullName(te::stat::MODE).c_str()), te::stat::MODE);
258 
259  m_ui->m_rejectAllComboBox->addItem("");
260  m_ui->m_rejectAllComboBox->addItem(QString(te::stat::GetStatSummaryFullName(te::stat::MIN_VALUE).c_str()), te::stat::MIN_VALUE);
261  m_ui->m_rejectAllComboBox->addItem(QString(te::stat::GetStatSummaryFullName(te::stat::MAX_VALUE).c_str()), te::stat::MAX_VALUE);
262  m_ui->m_rejectAllComboBox->addItem(QString(te::stat::GetStatSummaryFullName(te::stat::MEAN).c_str()), te::stat::MEAN);
263  m_ui->m_rejectAllComboBox->addItem(QString(te::stat::GetStatSummaryFullName(te::stat::SUM).c_str()), te::stat::SUM);
264  m_ui->m_rejectAllComboBox->addItem(QString(te::stat::GetStatSummaryFullName(te::stat::COUNT).c_str()), te::stat::COUNT);
265  m_ui->m_rejectAllComboBox->addItem(QString(te::stat::GetStatSummaryFullName(te::stat::VALID_COUNT).c_str()), te::stat::VALID_COUNT);
267  m_ui->m_rejectAllComboBox->addItem(QString(te::stat::GetStatSummaryFullName(te::stat::VARIANCE).c_str()), te::stat::VARIANCE);
268  m_ui->m_rejectAllComboBox->addItem(QString(te::stat::GetStatSummaryFullName(te::stat::SKEWNESS).c_str()), te::stat::SKEWNESS);
269  m_ui->m_rejectAllComboBox->addItem(QString(te::stat::GetStatSummaryFullName(te::stat::KURTOSIS).c_str()), te::stat::KURTOSIS);
270  m_ui->m_rejectAllComboBox->addItem(QString(te::stat::GetStatSummaryFullName(te::stat::AMPLITUDE).c_str()), te::stat::AMPLITUDE);
271  m_ui->m_rejectAllComboBox->addItem(QString(te::stat::GetStatSummaryFullName(te::stat::MEDIAN).c_str()), te::stat::MEDIAN);
272  m_ui->m_rejectAllComboBox->addItem(QString(te::stat::GetStatSummaryFullName(te::stat::VAR_COEFF).c_str()), te::stat::VAR_COEFF);
273  m_ui->m_rejectAllComboBox->addItem(QString(te::stat::GetStatSummaryFullName(te::stat::MODE).c_str()), te::stat::MODE);
274 }
275 
277 {
292 }
293 
294 void te::vp::DissolveDialog::setFunctionsByLayer(std::vector<te::dt::Property*> properties)
295 {
296  int propertyType;
297 
298  m_ui->m_selectAllComboBox->setCurrentIndex(0);
299  m_ui->m_rejectAllComboBox->setCurrentIndex(0);
300  m_ui->m_outputListWidget->clear();
301 
302  te::map::DataSetLayer* dsLayer = dynamic_cast<te::map::DataSetLayer*>(m_inputLayer.get());
303  te::da::DataSourcePtr dataSource = te::da::GetDataSource(dsLayer->getDataSourceId(), true);
304  const te::da::DataSourceCapabilities dsCapabilities = dataSource->getCapabilities();
305 
306  for(size_t i=0; i < properties.size(); ++i)
307  {
308  propertyType = properties[i]->getType();
309  if (propertyType == te::dt::GEOMETRY_TYPE)
310  continue;
311 
312  if(propertyType == te::dt::STRING_TYPE)
313  {
314  QListWidgetItem* item = new QListWidgetItem(QString(properties[i]->getName().c_str()) + " : " + m_StatisticalSummaryMap[te::stat::MIN_VALUE].c_str());
315  item->setData(Qt::UserRole, QVariant(te::stat::MIN_VALUE));
316  m_ui->m_outputListWidget->addItem(item);
317 
318  item = new QListWidgetItem(QString(properties[i]->getName().c_str()) + " : " + m_StatisticalSummaryMap[te::stat::MAX_VALUE].c_str());
319  item->setData(Qt::UserRole, QVariant(te::stat::MAX_VALUE));
320  m_ui->m_outputListWidget->addItem(item);
321 
322  item = new QListWidgetItem(QString(properties[i]->getName().c_str()) + " : " + m_StatisticalSummaryMap[te::stat::COUNT].c_str());
323  item->setData(Qt::UserRole, QVariant(te::stat::COUNT));
324  m_ui->m_outputListWidget->addItem(item);
325 
326  item = new QListWidgetItem(QString(properties[i]->getName().c_str()) + " : " + m_StatisticalSummaryMap[te::stat::VALID_COUNT].c_str());
327  item->setData(Qt::UserRole, QVariant(te::stat::VALID_COUNT));
328  m_ui->m_outputListWidget->addItem(item);
329 
330  item = new QListWidgetItem("");
331  m_ui->m_outputListWidget->addItem(item);
332  }
333  else
334  {
335  QListWidgetItem* item = new QListWidgetItem(QString(properties[i]->getName().c_str()) + " : " + m_StatisticalSummaryMap[te::stat::MIN_VALUE].c_str());
336  item->setData(Qt::UserRole, QVariant(te::stat::MIN_VALUE));
337  m_ui->m_outputListWidget->addItem(item);
338 
339  item = new QListWidgetItem(QString(properties[i]->getName().c_str()) + " : " + m_StatisticalSummaryMap[te::stat::MAX_VALUE].c_str());
340  item->setData(Qt::UserRole, QVariant(te::stat::MAX_VALUE));
341  m_ui->m_outputListWidget->addItem(item);
342 
343  item = new QListWidgetItem(QString(properties[i]->getName().c_str()) + " : " + m_StatisticalSummaryMap[te::stat::MEAN].c_str());
344  item->setData(Qt::UserRole, QVariant(te::stat::MEAN));
345  m_ui->m_outputListWidget->addItem(item);
346 
347  item = new QListWidgetItem(QString(properties[i]->getName().c_str()) + " : " + m_StatisticalSummaryMap[te::stat::SUM].c_str());
348  item->setData(Qt::UserRole, QVariant(te::stat::SUM));
349  m_ui->m_outputListWidget->addItem(item);
350 
351  item = new QListWidgetItem(QString(properties[i]->getName().c_str()) + " : " + m_StatisticalSummaryMap[te::stat::COUNT].c_str());
352  item->setData(Qt::UserRole, QVariant(te::stat::COUNT));
353  m_ui->m_outputListWidget->addItem(item);
354 
355  item = new QListWidgetItem(QString(properties[i]->getName().c_str()) + " : " + m_StatisticalSummaryMap[te::stat::VALID_COUNT].c_str());
356  item->setData(Qt::UserRole, QVariant(te::stat::VALID_COUNT));
357  m_ui->m_outputListWidget->addItem(item);
358 
359  item = new QListWidgetItem(QString(properties[i]->getName().c_str()) + " : " + m_StatisticalSummaryMap[te::stat::STANDARD_DEVIATION].c_str());
360  item->setData(Qt::UserRole, QVariant(te::stat::STANDARD_DEVIATION));
361  m_ui->m_outputListWidget->addItem(item);
362 
363  item = new QListWidgetItem(QString(properties[i]->getName().c_str()) + " : " + m_StatisticalSummaryMap[te::stat::VARIANCE].c_str());
364  item->setData(Qt::UserRole, QVariant(te::stat::VARIANCE));
365  m_ui->m_outputListWidget->addItem(item);
366 
367  item = new QListWidgetItem(QString(properties[i]->getName().c_str()) + " : " + m_StatisticalSummaryMap[te::stat::AMPLITUDE].c_str());
368  item->setData(Qt::UserRole, QVariant(te::stat::AMPLITUDE));
369  m_ui->m_outputListWidget->addItem(item);
370 
371 // Does not implemented for Query Operation.
372  if (!dsCapabilities.supportsPreparedQueryAPI())
373  {
374  item = new QListWidgetItem(QString(properties[i]->getName().c_str()) + " : " + m_StatisticalSummaryMap[te::stat::SKEWNESS].c_str());
375  item->setData(Qt::UserRole, QVariant(te::stat::SKEWNESS));
376  m_ui->m_outputListWidget->addItem(item);
377 
378  item = new QListWidgetItem(QString(properties[i]->getName().c_str()) + " : " + m_StatisticalSummaryMap[te::stat::KURTOSIS].c_str());
379  item->setData(Qt::UserRole, QVariant(te::stat::KURTOSIS));
380  m_ui->m_outputListWidget->addItem(item);
381 
382  item = new QListWidgetItem(QString(properties[i]->getName().c_str()) + " : " + m_StatisticalSummaryMap[te::stat::MEDIAN].c_str());
383  item->setData(Qt::UserRole, QVariant(te::stat::MEDIAN));
384  m_ui->m_outputListWidget->addItem(item);
385 
386  item = new QListWidgetItem(QString(properties[i]->getName().c_str()) + " : " + m_StatisticalSummaryMap[te::stat::VAR_COEFF].c_str());
387  item->setData(Qt::UserRole, QVariant(te::stat::VAR_COEFF));
388  m_ui->m_outputListWidget->addItem(item);
389 
390  item = new QListWidgetItem(QString(properties[i]->getName().c_str()) + " : " + m_StatisticalSummaryMap[te::stat::MODE].c_str());
391  item->setData(Qt::UserRole, QVariant(te::stat::MODE));
392  m_ui->m_outputListWidget->addItem(item);
393  }
394 
395  item = new QListWidgetItem("");
396  m_ui->m_outputListWidget->addItem(item);
397  }
398  }
399 
400  int lastRow = m_ui->m_outputListWidget->count() - 1;
401  delete m_ui->m_outputListWidget->item(lastRow);
402 }
403 
405 {
406  std::list<te::map::AbstractLayerPtr>::iterator it = m_layers.begin();
407 
408  std::string layerID = m_ui->m_layersComboBox->itemData(index, Qt::UserRole).toString().toUtf8().data();
409 
410  m_ui->m_propertieslistWidget->clear();
411 
412  while(it != m_layers.end())
413  {
414  if(layerID == it->get()->getId())
415  {
416  std::size_t type;
417  te::map::AbstractLayerPtr selectedLayer = it->get();
418  m_inputLayer = selectedLayer;
419  std::unique_ptr<const te::map::LayerSchema> schema(selectedLayer->getSchema());
420 
421  if(schema->size() == 0)
422  return;
423 
425  m_properties.clear();
426 
427  const std::vector<te::dt::Property*>& properties = schema->getProperties();
428 
429  te::common::Clone(properties, m_properties);
430 
432 
433  for(size_t i = 0; i < m_properties.size(); ++i)
434  {
435  type = m_properties[i]->getType();
436 
437  if(type != te::dt::GEOMETRY_TYPE)
438  m_ui->m_propertieslistWidget->addItem(m_properties[i]->getName().c_str());
439  }
440 
441  return;
442  }
443  ++it;
444  }
445 }
446 
448 {
449  m_ui->m_outputListWidget->reset();
450  m_ui->m_objectTypeGroupBox->setVisible(visible);
451  m_ui->m_statisticalSummatyGroupBox->setVisible(visible);
452 }
453 
455 {
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);
460 
461  if (!checked)
462  {
463  m_ui->m_selectAllComboBox->setCurrentIndex(0);
464  m_ui->m_rejectAllComboBox->setCurrentIndex(0);
465  m_ui->m_outputListWidget->clearSelection();
466  }
467 }
468 
470 {
471  QList<QListWidgetItem*> allItems;
472  int count = m_ui->m_propertieslistWidget->count();
473  for(int index = 0; index < count; ++index)
474  {
475  allItems.push_back(m_ui->m_propertieslistWidget->item(index));
476  }
477 
478  QList<QListWidgetItem*> filteredItems = m_ui->m_propertieslistWidget->findItems(text, Qt::MatchContains | Qt::MatchRecursive);
479 
480  for(int i = 0; i < allItems.size(); ++i)
481  {
482  QListWidgetItem* item = allItems.at(i);
483  bool hide = filteredItems.indexOf(item) == -1;
484  item->setHidden(hide);
485  }
486 
487  m_ui->m_propertieslistWidget->update();
488 }
489 
491 {
492  QString text = m_ui->m_selectAllComboBox->itemText(index);
493  Qt::MatchFlags flag = Qt::MatchEndsWith; //The search term matches the end of the item.
494 
495  if(text.isEmpty())
496  return;
497 
498  QList<QListWidgetItem *> listFound;
499  listFound = m_ui->m_outputListWidget->findItems(text, flag);
500 
501  for(int i=0; i < listFound.size(); ++i)
502  listFound.at(i)->setSelected(true);
503 
504  m_ui->m_rejectAllComboBox->setCurrentIndex(0);
505 }
506 
508 {
509  QString text = m_ui->m_selectAllComboBox->itemText(index);
510  Qt::MatchFlags flag = Qt::MatchEndsWith; //The search term matches the end of the item.
511 
512  if(text=="")
513  return;
514 
515  QList<QListWidgetItem *> listFound;
516  listFound = m_ui->m_outputListWidget->findItems(text, flag);
517 
518  for(int i=0; i < listFound.size(); ++i)
519  listFound.at(i)->setSelected(false);
520 
521  m_ui->m_selectAllComboBox->setCurrentIndex(0);
522 }
523 
525 {
526  if(item->text().isEmpty())
527  {
528  item->setSelected(false);
529  }
530 }
531 
533 {
534  m_ui->m_newLayerNameLineEdit->clear();
535  m_ui->m_newLayerNameLineEdit->setEnabled(true);
537  dlg.exec();
538 
539  std::list<te::da::DataSourceInfoPtr> dsPtrList = dlg.getSelecteds();
540 
541  if(dsPtrList.empty())
542  return;
543 
544  std::list<te::da::DataSourceInfoPtr>::iterator it = dsPtrList.begin();
545 
546  m_ui->m_repositoryLineEdit->setText(QString(it->get()->getTitle().c_str()));
547 
548  m_outputDatasource = *it;
549 
550  m_toFile = false;
551 }
552 
554 {
555  m_ui->m_newLayerNameLineEdit->clear();
556  m_ui->m_repositoryLineEdit->clear();
557 
559 
560  try {
561  fileDialog.exec();
562  }
563  catch (te::common::Exception& ex) {
564  QMessageBox::warning(this, tr("File information"), ex.what());
565  return;
566  }
567 
568  m_ui->m_repositoryLineEdit->setText(fileDialog.getPath().c_str());
569  m_ui->m_newLayerNameLineEdit->setText(fileDialog.getFileName().c_str());
570 
571  m_toFile = true;
572  m_ui->m_newLayerNameLineEdit->setEnabled(false);
573 }
574 
576 {
577 // Validate Input Layer.
578  if (m_ui->m_layersComboBox->count() == 0)
579  {
580  QMessageBox::information(this, tr("Dissolve"), tr("Select an input layer."));
581  return;
582  }
583 
584 // Validate DataSource.
585  te::da::DataSourcePtr inputDataSource = te::da::GetDataSource(m_inputLayer->getDataSourceId(), true);
586  if (!inputDataSource.get())
587  {
588  QMessageBox::information(this, tr("Dissolve"), tr("The selected input data source can not be accessed."));
589  return;
590  }
591 
592 // Verify selected properties to do Dissolve.
593  std::vector<std::string> selProperties = getSelectedPropertyNames();
594  if (selProperties.empty())
595  {
596  QMessageBox::information(this, tr("Dissolve"), tr("Select at least one grouping attribute."));
597  return;
598  }
599 
600 // Set specific parameters.
601  std::map<std::string, te::dt::AbstractData*> specificParams;
602  specificParams["DISSOLVE"] = new te::vp::ComplexData<std::vector<std::string> >(selProperties);
603 
604  specificParams["IS_COLLECTION"] = new te::dt::SimpleData<bool, te::dt::BOOLEAN_TYPE>(this->isCollection());
605 
606 
607  std::map<te::dt::Property*, std::vector<te::stat::StatisticalSummary> > outputStatisticalSummary = getStatisticalSummary();
608  specificParams["SUMMARY"] = new te::vp::ComplexData<std::map<te::dt::Property*, std::vector<te::stat::StatisticalSummary> > >(outputStatisticalSummary);
609 
610 
611 // Validade output repository.
612  if (m_ui->m_repositoryLineEdit->text().isEmpty())
613  {
614  QMessageBox::information(this, tr("Dissolve"), tr("Define a repository for the result."));
615  return;
616  }
617 
618  std::string outputdataset = m_ui->m_newLayerNameLineEdit->text().toUtf8().data();
619 
620  if (outputdataset.empty())
621  {
622  QMessageBox::information(this, tr("Dissolve"), tr("Define a name for the resulting layer."));
623  return;
624  }
625 
626 // Verify if "Input Only Selected objects" is checked.
627  bool inputIsChecked = false;
628 
629  if (m_ui->m_onlySelectedCheckBox->isChecked())
630  inputIsChecked = true;
631 
632  try
633  {
635  this->setCursor(Qt::WaitCursor);
636 
637 // Declare the input parameters
638  te::vp::InputParams structInputParams;
639 
640 // Set the inputLayer parameters
641  structInputParams.m_inputDataSource = inputDataSource;
642  structInputParams.m_inputDataSetType = m_inputLayer->getSchema().release();
643 
645 
646  int inputSRID = 0;
647 
648  if (!geomInputProp)
649  {
650  this->setCursor(Qt::ArrowCursor);
651  QMessageBox::information(this, tr("Dissolve"), tr("Problem to get geometry property of input layer."));
652 
653  return;
654  }
655 
656  inputSRID = m_inputLayer->getSRID();
657 
658 // Select a strategy based on the capabilities of the input datasource
659  const te::da::DataSourceCapabilities inputDSCapabilities = inputDataSource->getCapabilities();
660 
661  bool isQuery = false;
662 
663  te::da::Select* inputSelect = nullptr;
664 
665  if (inputDSCapabilities.getQueryCapabilities().supportsSpatialSQLDialect())
666  {
667  isQuery = true;
668 
669 // Get Select Query using AbstractLayerPtr to process by spatial database.
670  inputSelect = te::vp::GetSelectQueryFromLayer(m_inputLayer, inputIsChecked, inputSRID);
671 
672  if (inputSelect)
673  structInputParams.m_inputQuery = inputSelect;
674  }
675  else
676  {
677 // Get DataSet and DataSetType using AbstractLayerPtr to process by memory, using GEOS.
678  te::vp::DataStruct inputData = te::vp::GetDataStructFromLayer(m_inputLayer, inputIsChecked, inputSRID);
679 
680  if (inputData.m_dataSet)
681  structInputParams.m_inputDataSet = inputData.m_dataSet;
682 
683  if (inputData.m_dataSetType)
684  structInputParams.m_inputDataSetType = inputData.m_dataSetType;
685  }
686 
687  m_inputParams.push_back(structInputParams);
688 
689 
690 // Return of operation result.
691  bool res = true;
692 
693  if (m_toFile)
694  {
695  boost::filesystem::path uri(m_ui->m_repositoryLineEdit->text().toUtf8().data());
696 
697  if (te::core::FileSystem::exists(uri.string()))
698  {
699  this->setCursor(Qt::ArrowCursor);
700  QMessageBox::information(this, tr("Dissolve"), tr("Output file already exists. Remove it and try again. "));
701 
702  return;
703  }
704 
705  std::size_t idx = outputdataset.find(".");
706  if (idx != std::string::npos)
707  outputdataset = outputdataset.substr(0, idx);
708 
709  te::da::DataSourcePtr dsOGR = te::vp::CreateOGRDataSource(m_ui->m_repositoryLineEdit->text().toUtf8().data());
710 
711  dsOGR->open();
712 
713 // Set parameters (Input/Output).
717  m_params->setOutputDataSetName(outputdataset);
718  m_params->setOutputSRID(inputSRID);
719  m_params->setSpecificParams(specificParams);
720 
721  te::vp::Dissolve dissolve;
722 
723  if (isQuery)
724  {
725  res = dissolve.executeQuery(m_params);
726  }
727  else
728  {
729  res = dissolve.executeMemory(m_params);
730  }
731 
732  if (!res)
733  {
734  dsOGR->close();
735 
736  this->setCursor(Qt::ArrowCursor);
737  QMessageBox::information(this, tr("Dissolve"), tr("Error: could not generate the dissolve."));
738 
739  reject();
740  }
741 
743 
744  if (!m_outputDatasource)
745  {
746  this->setCursor(Qt::ArrowCursor);
747  QMessageBox::information(this, tr("Dissolve"), tr("The output data source can not be accessed."));
748 
749  return;
750  }
751 
753 
754  delete m_params;
755  }
756  else
757  {
759  if (!aux.get())
760  {
761  this->setCursor(Qt::ArrowCursor);
762  QMessageBox::information(this, tr("Dissolve"), tr("The output data source can not be accessed."));
763 
764  return;
765  }
766 
767  std::string name = te::common::Convert2LCase(outputdataset);
768 
769  if (aux->dataSetExists(name))
770  {
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."));
773 
774  return;
775  }
776 
777 // Set parameters (Input/Output).
781  m_params->setOutputDataSetName(outputdataset);
782  m_params->setOutputSRID(inputSRID);
783  m_params->setSpecificParams(specificParams);
784 
785  te::vp::Dissolve dissolve;
786 
787 // Select a strategy based on the capabilities of the input datasource
788  if (isQuery)
789  {
790  res = dissolve.executeQuery(m_params);
791  }
792  else
793  {
794  res = dissolve.executeMemory(m_params);
795  }
796 
798 
799  delete m_params;
800 
801  if (!res)
802  {
803  this->setCursor(Qt::ArrowCursor);
804  QMessageBox::information(this, tr("Dissolve"), tr("Error: could not generate the dissolve."));
805  reject();
806  }
807  }
808 
809 // creating a layer for the result
811 
813 
814  te::da::DataSetTypePtr dt(outDataSource->getDataSetType(outputdataset).release());
815  m_layer = converter(dt);
816  }
817  catch(const std::exception& e)
818  {
819  this->setCursor(Qt::ArrowCursor);
820 
821  QMessageBox::information(this, "Dissolve", e.what());
822 
823  std::string str = "Vector Processing - Dissolve - ";
824  str += e.what();
825  TE_LOG_ERROR(str);
826 
827  return;
828  }
829 
830  this->setCursor(Qt::ArrowCursor);
831 
832  accept();
833 }
834 
836 {
837  reject();
838 }
839 
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)
Geometric property.
A structure to hold the input parameters of vector processing.
Definition: InputParams.h:50
te::vp::AlgorithmParams * m_params
Algorithm parameters.
Defines a component for choose a file.
Definition: FileDialog.h:52
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.
Definition: FileSystem.cpp:142
te::da::Select * GetSelectQueryFromLayer(te::map::AbstractLayerPtr layer, bool onlySelectedObjects, int srid=0)
boost::shared_ptr< DataSetType > DataSetTypePtr
Definition: DataSetType.h:653
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.
Definition: StringUtils.h:202
const std::vector< std::string > & getWarnings()
void onFilterLineEditTextChanged(const QString &text)
Total number of values.
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 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...
te::da::DataSourcePtr m_inputDataSource
Is Required.
Definition: InputParams.h:81
te::da::Select * m_inputQuery
Is required for operations in spatial database.
Definition: InputParams.h:85
void setOutputDataSource(te::da::DataSourcePtr outputDataSource)
const QueryCapabilities & getQueryCapabilities() const
It models a property definition.
Definition: Property.h:59
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.
Definition: ComplexData.h:52
static DataSourceInfoManager & getInstance()
It returns a reference to the singleton instance.
bool executeMemory(te::vp::AlgorithmParams *mainParams)
void exec()
This method will open the dialog of file selection and populate the class members with the chosen fil...
Definition: FileDialog.cpp:54
URI C++ Library.
Definition: Attributes.h:37
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
te::da::DataSetType * m_inputDataSetType
Is required.
Definition: InputParams.h:82
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.
Definition: Select.h:65
std::vector< te::vp::InputParams > m_inputParams
A vector of input parameters.
std::string getPath()
This method will return the chosen path.
Definition: FileDialog.cpp:103
void setFunctionsByLayer(std::vector< te::dt::Property * > properties)
Set Grouping Functions Type for &#39;m_outputListWidget&#39; based on Selected Layer.
te::da::DataSet * m_inputDataSet
Is required for operations in memory.
Definition: InputParams.h:84
const std::list< te::da::DataSourceInfoPtr > & getSelecteds() const
bool isCollection()
Verify if the output result is a collection or single geometry.
void setStatisticalSummary()
Set Statistical Summary Type for combobox &#39;m_selectAllComboBox&#39; and &#39;m_rejectAllComboBox&#39; based on a ...
A dialog for selecting a data source.
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...
Definition: Logger.h:337
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.
Definition: DataSetLayer.h:47
std::string getFileName()
This method will return the file name.
Definition: FileDialog.cpp:113
std::unique_ptr< Ui::DissolveDialogForm > m_ui
DialogForm.
StatisticalSummary
Define grouping functions type.
A template for atomic data types (integers, floats, strings and others).
Definition: SimpleData.h:59
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.
Definition: STLUtils.h:237
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...
Definition: BoostUtils.h:55
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