All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
AggregationDialog.cpp
Go to the documentation of this file.
1 /* Copyright (C) 2011-2012 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/AggregationDialog.cpp
22 
23  \brief A dialog for aggregation operation
24 */
25 
26 // TerraLib
27 #include "../../common/progress/ProgressManager.h"
28 #include "../../common/Translator.h"
29 #include "../../common/STLUtils.h"
30 #include "../../dataaccess/dataset/DataSetType.h"
31 #include "../../dataaccess/datasource/DataSourceCapabilities.h"
32 #include "../../dataaccess/datasource/DataSourceInfo.h"
33 #include "../../dataaccess/datasource/DataSourceInfoManager.h"
34 #include "../../dataaccess/datasource/DataSourceManager.h"
35 #include "../../dataaccess/datasource/DataSourceFactory.h"
36 #include "../../dataaccess/utils/Utils.h"
37 #include "../../qt/af/Utils.h"
38 #include "../../qt/widgets/datasource/selector/DataSourceSelectorDialog.h"
39 #include "../qt/widgets/layer/utils/DataSet2Layer.h"
40 #include "../../qt/widgets/progress/ProgressViewerDialog.h"
41 #include "../../datatype/Enums.h"
42 #include "../../datatype/Property.h"
43 #include "../../maptools/AbstractLayer.h"
44 #include "../../statistics/core/Utils.h"
45 #include "../Config.h"
46 #include "../Exception.h"
47 #include "Aggregation.h"
48 #include "AggregationDialog.h"
49 #include "ui_AggregationDialogForm.h"
50 #include "VectorProcessingConfig.h"
51 #include "Utils.h"
52 
53 // Qt
54 #include <QtCore/QList>
55 #include <QtGui/QFileDialog>
56 #include <QtGui/QListWidget>
57 #include <QtGui/QListWidgetItem>
58 #include <QtGui/QMessageBox>
59 #include <QtGui/QTreeWidget>
60 
61 // Boost
62 #include <boost/algorithm/string.hpp>
63 #include <boost/filesystem.hpp>
64 #include <boost/uuid/random_generator.hpp>
65 #include <boost/uuid/uuid_io.hpp>
66 
67 te::vp::AggregationDialog::AggregationDialog(QWidget* parent, Qt::WindowFlags f)
68  : QDialog(parent, f),
69  m_ui(new Ui::AggregationDialogForm),
70  m_layers(std::list<te::map::AbstractLayerPtr>()),
71  m_selectedLayer(0),
72  m_toFile(false)
73 {
74 // add controls
75  m_ui->setupUi(this);
76 
77  m_ui->m_outputStatisticsGroupBox->setVisible(false);
78 
79 // add icons
80  m_ui->m_imgLabel->setPixmap(QIcon::fromTheme(VP_IMAGES"/vp-aggregation-hint").pixmap(112,48));
81  m_ui->m_targetDatasourceToolButton->setIcon(QIcon::fromTheme("datasource"));
82 
85 
86  connect(m_ui->m_layersComboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(onLayerComboBoxChanged(int)));
87  connect(m_ui->m_filterLineEdit, SIGNAL(textChanged(const QString&)), this, SLOT(onFilterLineEditTextChanged(const QString&)));
88  connect(m_ui->m_calcStatCheckBox, SIGNAL(toggled(bool)), this, SLOT(onCalculateStatistics(bool)));
89  connect(m_ui->m_outputListWidget, SIGNAL(itemClicked(QListWidgetItem *)), this, SLOT(onOutputListWidgetClicked(QListWidgetItem *)));
90  connect(m_ui->m_selectAllComboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(onSelectAllComboBoxChanged(int)));
91  connect(m_ui->m_rejectAllComboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(onRejectAllComboBoxChanged(int)));
92  connect(m_ui->m_targetDatasourceToolButton, SIGNAL(pressed()), this, SLOT(onTargetDatasourceToolButtonPressed()));
93  connect(m_ui->m_targetFileToolButton, SIGNAL(pressed()), this, SLOT(onTargetFileToolButtonPressed()));
94 
95  //connect(m_ui->m_helpPushButton, SIGNAL(clicked()), this, SLOT(onHelpPushButtonClicked()));
96  connect(m_ui->m_okPushButton, SIGNAL(clicked()), this, SLOT(onOkPushButtonClicked()));
97  connect(m_ui->m_cancelPushButton, SIGNAL(clicked()), this, SLOT(onCancelPushButtonClicked()));
98 
99  m_ui->m_helpPushButton->setNameSpace("dpi.inpe.br.plugins");
100  m_ui->m_helpPushButton->setPageReference("plugins/vp/vp_aggregation.html");
101 
103  m_ui->m_newLayerNameLineEdit->setEnabled(true);
104 }
105 
107 {
108 }
109 
110 void te::vp::AggregationDialog::setLayers(std::list<te::map::AbstractLayerPtr> layers)
111 {
112  m_layers = layers;
113 
114  std::list<te::map::AbstractLayerPtr>::iterator it = m_layers.begin();
115 
116  while(it != m_layers.end())
117  {
118  std::auto_ptr<te::da::DataSetType> dsType = it->get()->getSchema();
119  if(dsType->hasGeom())
120  m_ui->m_layersComboBox->addItem(QString(it->get()->getTitle().c_str()), QVariant(it->get()->getId().c_str()));
121  ++it;
122  }
123 }
124 
125 std::map<te::dt::Property*, std::vector<te::stat::StatisticalSummary> > te::vp::AggregationDialog::getStatisticalSummary()
126 {
127  std::map<te::dt::Property*, std::vector<te::stat::StatisticalSummary> > outputStatisticalSummary;
128 
129  QList<QListWidgetItem*> itemList = m_ui->m_outputListWidget->selectedItems();
130 
131  te::stat::StatisticalSummary enumStatisticalSummary;
132  std::map<std::string, std::vector<te::stat::StatisticalSummary> > propname_stat;
133  std::map<std::string, std::vector<te::stat::StatisticalSummary> >::iterator it;
134 
135  for(int i = 0; i < itemList.size(); ++i)
136  {
137  std::vector<std::string> tokens;
138  std::string pname;
139  std::string auxItem = itemList[i]->text().toStdString();
140 
141  boost::split(tokens, auxItem, boost::is_any_of(":"));
142  if(tokens[0] != "")
143  {
144  pname = tokens[0];
145  pname.erase(pname.end() - 1);
146  enumStatisticalSummary = (te::stat::StatisticalSummary)itemList[i]->data(Qt::UserRole).toInt();
147  it = propname_stat.find(pname);
148  if (it != propname_stat.end())
149  it->second.push_back(enumStatisticalSummary);
150  else
151  {
152  std::vector<te::stat::StatisticalSummary> nvec;
153  nvec.push_back(enumStatisticalSummary);
154  propname_stat.insert(std::make_pair(pname, nvec));
155  }
156  }
157  }
158 
159  it = propname_stat.begin();
160  while (it != propname_stat.end())
161  {
162  te::dt::Property* prop = getSelectedPropertyByName(it->first);
163  outputStatisticalSummary.insert(std::make_pair(prop,it->second));
164  ++it;
165  }
166 
167  return outputStatisticalSummary;
168 }
169 
171 {
172  te::dt::Property* selProperty;
173 
174  if(propertyName == "")
175  return 0;
176 
177  for(std::size_t i = 0; i < m_properties.size(); ++i)
178  {
179  if(propertyName == m_properties[i]->getName())
180  {
181  selProperty = m_properties[i];
182  return selProperty;
183  }
184  }
185  return 0;
186 }
187 
188 std::vector<te::dt::Property*> te::vp::AggregationDialog::getSelectedProperties()
189 {
190  std::vector<te::dt::Property*> selProperties;
191 
192  for(std::size_t i = 0; i != m_ui->m_propertieslistWidget->count(); ++i)
193  {
194  if(m_ui->m_propertieslistWidget->isItemSelected(m_ui->m_propertieslistWidget->item(i)))
195  {
196  selProperties.push_back(m_properties[i]);
197  }
198  }
199 
200  return selProperties;
201 }
202 
204 {
205  return m_layer;
206 }
207 
209 {
210  m_ui->m_selectAllComboBox->addItem("");
211  m_ui->m_selectAllComboBox->addItem(QString(te::stat::GetStatSummaryFullName(te::stat::MIN_VALUE).c_str()), te::stat::MIN_VALUE);
212  m_ui->m_selectAllComboBox->addItem(QString(te::stat::GetStatSummaryFullName(te::stat::MAX_VALUE).c_str()), te::stat::MAX_VALUE);
213  m_ui->m_selectAllComboBox->addItem(QString(te::stat::GetStatSummaryFullName(te::stat::MEAN).c_str()), te::stat::MEAN);
214  m_ui->m_selectAllComboBox->addItem(QString(te::stat::GetStatSummaryFullName(te::stat::SUM).c_str()), te::stat::SUM);
215  m_ui->m_selectAllComboBox->addItem(QString(te::stat::GetStatSummaryFullName(te::stat::COUNT).c_str()), te::stat::COUNT);
216  m_ui->m_selectAllComboBox->addItem(QString(te::stat::GetStatSummaryFullName(te::stat::VALID_COUNT).c_str()), te::stat::VALID_COUNT);
217  m_ui->m_selectAllComboBox->addItem(QString(te::stat::GetStatSummaryFullName(te::stat::STANDARD_DEVIATION).c_str()), te::stat::STANDARD_DEVIATION);
218  m_ui->m_selectAllComboBox->addItem(QString(te::stat::GetStatSummaryFullName(te::stat::VARIANCE).c_str()), te::stat::VARIANCE);
219  m_ui->m_selectAllComboBox->addItem(QString(te::stat::GetStatSummaryFullName(te::stat::SKEWNESS).c_str()), te::stat::SKEWNESS);
220  m_ui->m_selectAllComboBox->addItem(QString(te::stat::GetStatSummaryFullName(te::stat::KURTOSIS).c_str()), te::stat::KURTOSIS);
221  m_ui->m_selectAllComboBox->addItem(QString(te::stat::GetStatSummaryFullName(te::stat::AMPLITUDE).c_str()), te::stat::AMPLITUDE);
222  m_ui->m_selectAllComboBox->addItem(QString(te::stat::GetStatSummaryFullName(te::stat::MEDIAN).c_str()), te::stat::MEDIAN);
223  m_ui->m_selectAllComboBox->addItem(QString(te::stat::GetStatSummaryFullName(te::stat::VAR_COEFF).c_str()), te::stat::VAR_COEFF);
224  m_ui->m_selectAllComboBox->addItem(QString(te::stat::GetStatSummaryFullName(te::stat::MODE).c_str()), te::stat::MODE);
225 
226  m_ui->m_rejectAllComboBox->addItem("");
227  m_ui->m_rejectAllComboBox->addItem(QString(te::stat::GetStatSummaryFullName(te::stat::MIN_VALUE).c_str()), te::stat::MIN_VALUE);
228  m_ui->m_rejectAllComboBox->addItem(QString(te::stat::GetStatSummaryFullName(te::stat::MAX_VALUE).c_str()), te::stat::MAX_VALUE);
229  m_ui->m_rejectAllComboBox->addItem(QString(te::stat::GetStatSummaryFullName(te::stat::MEAN).c_str()), te::stat::MEAN);
230  m_ui->m_rejectAllComboBox->addItem(QString(te::stat::GetStatSummaryFullName(te::stat::SUM).c_str()), te::stat::SUM);
231  m_ui->m_rejectAllComboBox->addItem(QString(te::stat::GetStatSummaryFullName(te::stat::COUNT).c_str()), te::stat::COUNT);
232  m_ui->m_rejectAllComboBox->addItem(QString(te::stat::GetStatSummaryFullName(te::stat::VALID_COUNT).c_str()), te::stat::VALID_COUNT);
233  m_ui->m_rejectAllComboBox->addItem(QString(te::stat::GetStatSummaryFullName(te::stat::STANDARD_DEVIATION).c_str()), te::stat::STANDARD_DEVIATION);
234  m_ui->m_rejectAllComboBox->addItem(QString(te::stat::GetStatSummaryFullName(te::stat::VARIANCE).c_str()), te::stat::VARIANCE);
235  m_ui->m_rejectAllComboBox->addItem(QString(te::stat::GetStatSummaryFullName(te::stat::SKEWNESS).c_str()), te::stat::SKEWNESS);
236  m_ui->m_rejectAllComboBox->addItem(QString(te::stat::GetStatSummaryFullName(te::stat::KURTOSIS).c_str()), te::stat::KURTOSIS);
237  m_ui->m_rejectAllComboBox->addItem(QString(te::stat::GetStatSummaryFullName(te::stat::AMPLITUDE).c_str()), te::stat::AMPLITUDE);
238  m_ui->m_rejectAllComboBox->addItem(QString(te::stat::GetStatSummaryFullName(te::stat::MEDIAN).c_str()), te::stat::MEDIAN);
239  m_ui->m_rejectAllComboBox->addItem(QString(te::stat::GetStatSummaryFullName(te::stat::VAR_COEFF).c_str()), te::stat::VAR_COEFF);
240  m_ui->m_rejectAllComboBox->addItem(QString(te::stat::GetStatSummaryFullName(te::stat::MODE).c_str()), te::stat::MODE);
241 }
242 
244 {
245  m_StatisticalSummaryMap.insert(StaticalSummaryMap::value_type(te::stat::MIN_VALUE, te::stat::GetStatSummaryFullName(te::stat::MIN_VALUE)));
246  m_StatisticalSummaryMap.insert(StaticalSummaryMap::value_type(te::stat::MAX_VALUE, te::stat::GetStatSummaryFullName(te::stat::MAX_VALUE)));
247  m_StatisticalSummaryMap.insert(StaticalSummaryMap::value_type(te::stat::MEAN, te::stat::GetStatSummaryFullName(te::stat::MEAN)));
248  m_StatisticalSummaryMap.insert(StaticalSummaryMap::value_type(te::stat::SUM, te::stat::GetStatSummaryFullName(te::stat::SUM)));
249  m_StatisticalSummaryMap.insert(StaticalSummaryMap::value_type(te::stat::COUNT, te::stat::GetStatSummaryFullName(te::stat::COUNT)));
250  m_StatisticalSummaryMap.insert(StaticalSummaryMap::value_type(te::stat::VALID_COUNT, te::stat::GetStatSummaryFullName(te::stat::VALID_COUNT)));
251  m_StatisticalSummaryMap.insert(StaticalSummaryMap::value_type(te::stat::STANDARD_DEVIATION, te::stat::GetStatSummaryFullName(te::stat::STANDARD_DEVIATION)));
252  m_StatisticalSummaryMap.insert(StaticalSummaryMap::value_type(te::stat::VARIANCE, te::stat::GetStatSummaryFullName(te::stat::VARIANCE)));
253  m_StatisticalSummaryMap.insert(StaticalSummaryMap::value_type(te::stat::SKEWNESS, te::stat::GetStatSummaryFullName(te::stat::SKEWNESS)));
254  m_StatisticalSummaryMap.insert(StaticalSummaryMap::value_type(te::stat::KURTOSIS, te::stat::GetStatSummaryFullName(te::stat::KURTOSIS)));
255  m_StatisticalSummaryMap.insert(StaticalSummaryMap::value_type(te::stat::AMPLITUDE, te::stat::GetStatSummaryFullName(te::stat::AMPLITUDE)));
256  m_StatisticalSummaryMap.insert(StaticalSummaryMap::value_type(te::stat::MEDIAN, te::stat::GetStatSummaryFullName(te::stat::MEDIAN)));
257  m_StatisticalSummaryMap.insert(StaticalSummaryMap::value_type(te::stat::VAR_COEFF, te::stat::GetStatSummaryFullName(te::stat::VAR_COEFF)));
258  m_StatisticalSummaryMap.insert(StaticalSummaryMap::value_type(te::stat::MODE, te::stat::GetStatSummaryFullName(te::stat::MODE)));
259 }
260 
261 void te::vp::AggregationDialog::setFunctionsByLayer(std::vector<te::dt::Property*> properties)
262 {
263  QStringList propertyList;
264  int propertyType;
265 
266  m_ui->m_selectAllComboBox->setCurrentIndex(0);
267  m_ui->m_rejectAllComboBox->setCurrentIndex(0);
268  m_ui->m_outputListWidget->clear();
269 
270  te::map::DataSetLayer* dsLayer = dynamic_cast<te::map::DataSetLayer*>(m_selectedLayer.get());
271  te::da::DataSourcePtr dataSource = te::da::GetDataSource(dsLayer->getDataSourceId(), true);
272  const te::da::DataSourceCapabilities dsCapabilities = dataSource->getCapabilities();
273 
274  if(dsCapabilities.supportsPreparedQueryAPI() && dsCapabilities.getQueryCapabilities().supportsSpatialSQLDialect())
275  {
276  for(size_t i=0; i < properties.size(); ++i)
277  {
278  propertyType = properties[i]->getType();
279  if(propertyType != te::dt::GEOMETRY_TYPE)
280  {
281  if(propertyType == te::dt::STRING_TYPE)
282  {
283  QListWidgetItem* item = new QListWidgetItem(QString(properties[i]->getName().c_str()) + " : " + m_StatisticalSummaryMap[te::stat::MIN_VALUE].c_str());
284  item->setData(Qt::UserRole, QVariant(te::stat::MIN_VALUE));
285  m_ui->m_outputListWidget->addItem(item);
286 
287  item = new QListWidgetItem(QString(properties[i]->getName().c_str()) + " : " + m_StatisticalSummaryMap[te::stat::MAX_VALUE].c_str());
288  item->setData(Qt::UserRole, QVariant(te::stat::MAX_VALUE));
289  m_ui->m_outputListWidget->addItem(item);
290 
291  item = new QListWidgetItem(QString(properties[i]->getName().c_str()) + " : " + m_StatisticalSummaryMap[te::stat::COUNT].c_str());
292  item->setData(Qt::UserRole, QVariant(te::stat::COUNT));
293  m_ui->m_outputListWidget->addItem(item);
294 
295  item = new QListWidgetItem(QString(properties[i]->getName().c_str()) + " : " + m_StatisticalSummaryMap[te::stat::VALID_COUNT].c_str());
296  item->setData(Qt::UserRole, QVariant(te::stat::VALID_COUNT));
297  m_ui->m_outputListWidget->addItem(item);
298 
299  item = new QListWidgetItem("");
300  m_ui->m_outputListWidget->addItem(item);
301  }
302  else
303  {
304  QListWidgetItem* item = new QListWidgetItem(QString(properties[i]->getName().c_str()) + " : " + m_StatisticalSummaryMap[te::stat::MIN_VALUE].c_str());
305  item->setData(Qt::UserRole, QVariant(te::stat::MIN_VALUE));
306  m_ui->m_outputListWidget->addItem(item);
307 
308  item = new QListWidgetItem(QString(properties[i]->getName().c_str()) + " : " + m_StatisticalSummaryMap[te::stat::MAX_VALUE].c_str());
309  item->setData(Qt::UserRole, QVariant(te::stat::MAX_VALUE));
310  m_ui->m_outputListWidget->addItem(item);
311 
312  item = new QListWidgetItem(QString(properties[i]->getName().c_str()) + " : " + m_StatisticalSummaryMap[te::stat::MEAN].c_str());
313  item->setData(Qt::UserRole, QVariant(te::stat::MEAN));
314  m_ui->m_outputListWidget->addItem(item);
315 
316  item = new QListWidgetItem(QString(properties[i]->getName().c_str()) + " : " + m_StatisticalSummaryMap[te::stat::SUM].c_str());
317  item->setData(Qt::UserRole, QVariant(te::stat::SUM));
318  m_ui->m_outputListWidget->addItem(item);
319 
320  item = new QListWidgetItem(QString(properties[i]->getName().c_str()) + " : " + m_StatisticalSummaryMap[te::stat::COUNT].c_str());
321  item->setData(Qt::UserRole, QVariant(te::stat::COUNT));
322  m_ui->m_outputListWidget->addItem(item);
323 
324  item = new QListWidgetItem(QString(properties[i]->getName().c_str()) + " : " + m_StatisticalSummaryMap[te::stat::VALID_COUNT].c_str());
325  item->setData(Qt::UserRole, QVariant(te::stat::VALID_COUNT));
326  m_ui->m_outputListWidget->addItem(item);
327 
328  item = new QListWidgetItem(QString(properties[i]->getName().c_str()) + " : " + m_StatisticalSummaryMap[te::stat::STANDARD_DEVIATION].c_str());
329  item->setData(Qt::UserRole, QVariant(te::stat::STANDARD_DEVIATION));
330  m_ui->m_outputListWidget->addItem(item);
331 
332  item = new QListWidgetItem(QString(properties[i]->getName().c_str()) + " : " + m_StatisticalSummaryMap[te::stat::VARIANCE].c_str());
333  item->setData(Qt::UserRole, QVariant(te::stat::VARIANCE));
334  m_ui->m_outputListWidget->addItem(item);
335 
336  item = new QListWidgetItem(QString(properties[i]->getName().c_str()) + " : " + m_StatisticalSummaryMap[te::stat::AMPLITUDE].c_str());
337  item->setData(Qt::UserRole, QVariant(te::stat::AMPLITUDE));
338  m_ui->m_outputListWidget->addItem(item);
339 
340  item = new QListWidgetItem("");
341  m_ui->m_outputListWidget->addItem(item);
342  }
343  }
344  }
345  }
346  else
347  {
348  for(size_t i=0; i < properties.size(); ++i)
349  {
350  propertyType = properties[i]->getType();
351  if(propertyType != te::dt::GEOMETRY_TYPE)
352  {
353  if(propertyType == te::dt::STRING_TYPE)
354  {
355  QListWidgetItem* item = new QListWidgetItem(QString(properties[i]->getName().c_str()) + " : " + m_StatisticalSummaryMap[te::stat::MIN_VALUE].c_str());
356  item->setData(Qt::UserRole, QVariant(te::stat::MIN_VALUE));
357  m_ui->m_outputListWidget->addItem(item);
358 
359  item = new QListWidgetItem(QString(properties[i]->getName().c_str()) + " : " + m_StatisticalSummaryMap[te::stat::MAX_VALUE].c_str());
360  item->setData(Qt::UserRole, QVariant(te::stat::MAX_VALUE));
361  m_ui->m_outputListWidget->addItem(item);
362 
363  item = new QListWidgetItem(QString(properties[i]->getName().c_str()) + " : " + m_StatisticalSummaryMap[te::stat::COUNT].c_str());
364  item->setData(Qt::UserRole, QVariant(te::stat::COUNT));
365  m_ui->m_outputListWidget->addItem(item);
366 
367  item = new QListWidgetItem(QString(properties[i]->getName().c_str()) + " : " + m_StatisticalSummaryMap[te::stat::VALID_COUNT].c_str());
368  item->setData(Qt::UserRole, QVariant(te::stat::VALID_COUNT));
369  m_ui->m_outputListWidget->addItem(item);
370 
371  item = new QListWidgetItem("");
372  m_ui->m_outputListWidget->addItem(item);
373  }
374  else
375  {
376  QListWidgetItem* item = new QListWidgetItem(QString(properties[i]->getName().c_str()) + " : " + m_StatisticalSummaryMap[te::stat::MIN_VALUE].c_str());
377  item->setData(Qt::UserRole, QVariant(te::stat::MIN_VALUE));
378  m_ui->m_outputListWidget->addItem(item);
379 
380  item = new QListWidgetItem(QString(properties[i]->getName().c_str()) + " : " + m_StatisticalSummaryMap[te::stat::MAX_VALUE].c_str());
381  item->setData(Qt::UserRole, QVariant(te::stat::MAX_VALUE));
382  m_ui->m_outputListWidget->addItem(item);
383 
384  item = new QListWidgetItem(QString(properties[i]->getName().c_str()) + " : " + m_StatisticalSummaryMap[te::stat::MEAN].c_str());
385  item->setData(Qt::UserRole, QVariant(te::stat::MEAN));
386  m_ui->m_outputListWidget->addItem(item);
387 
388  item = new QListWidgetItem(QString(properties[i]->getName().c_str()) + " : " + m_StatisticalSummaryMap[te::stat::SUM].c_str());
389  item->setData(Qt::UserRole, QVariant(te::stat::SUM));
390  m_ui->m_outputListWidget->addItem(item);
391 
392  item = new QListWidgetItem(QString(properties[i]->getName().c_str()) + " : " + m_StatisticalSummaryMap[te::stat::COUNT].c_str());
393  item->setData(Qt::UserRole, QVariant(te::stat::COUNT));
394  m_ui->m_outputListWidget->addItem(item);
395 
396  item = new QListWidgetItem(QString(properties[i]->getName().c_str()) + " : " + m_StatisticalSummaryMap[te::stat::VALID_COUNT].c_str());
397  item->setData(Qt::UserRole, QVariant(te::stat::VALID_COUNT));
398  m_ui->m_outputListWidget->addItem(item);
399 
400  item = new QListWidgetItem(QString(properties[i]->getName().c_str()) + " : " + m_StatisticalSummaryMap[te::stat::STANDARD_DEVIATION].c_str());
401  item->setData(Qt::UserRole, QVariant(te::stat::STANDARD_DEVIATION));
402  m_ui->m_outputListWidget->addItem(item);
403 
404  item = new QListWidgetItem(QString(properties[i]->getName().c_str()) + " : " + m_StatisticalSummaryMap[te::stat::VARIANCE].c_str());
405  item->setData(Qt::UserRole, QVariant(te::stat::VARIANCE));
406  m_ui->m_outputListWidget->addItem(item);
407 
408  item = new QListWidgetItem(QString(properties[i]->getName().c_str()) + " : " + m_StatisticalSummaryMap[te::stat::SKEWNESS].c_str());
409  item->setData(Qt::UserRole, QVariant(te::stat::SKEWNESS));
410  m_ui->m_outputListWidget->addItem(item);
411 
412  item = new QListWidgetItem(QString(properties[i]->getName().c_str()) + " : " + m_StatisticalSummaryMap[te::stat::KURTOSIS].c_str());
413  item->setData(Qt::UserRole, QVariant(te::stat::KURTOSIS));
414  m_ui->m_outputListWidget->addItem(item);
415 
416  item = new QListWidgetItem(QString(properties[i]->getName().c_str()) + " : " + m_StatisticalSummaryMap[te::stat::AMPLITUDE].c_str());
417  item->setData(Qt::UserRole, QVariant(te::stat::AMPLITUDE));
418  m_ui->m_outputListWidget->addItem(item);
419 
420  item = new QListWidgetItem(QString(properties[i]->getName().c_str()) + " : " + m_StatisticalSummaryMap[te::stat::MEDIAN].c_str());
421  item->setData(Qt::UserRole, QVariant(te::stat::MEDIAN));
422  m_ui->m_outputListWidget->addItem(item);
423 
424  item = new QListWidgetItem(QString(properties[i]->getName().c_str()) + " : " + m_StatisticalSummaryMap[te::stat::VAR_COEFF].c_str());
425  item->setData(Qt::UserRole, QVariant(te::stat::VAR_COEFF));
426  m_ui->m_outputListWidget->addItem(item);
427 
428  item = new QListWidgetItem(QString(properties[i]->getName().c_str()) + " : " + m_StatisticalSummaryMap[te::stat::MODE].c_str());
429  item->setData(Qt::UserRole, QVariant(te::stat::MODE));
430  m_ui->m_outputListWidget->addItem(item);
431 
432  item = new QListWidgetItem("");
433  m_ui->m_outputListWidget->addItem(item);
434  }
435  }
436  }
437  }
438  int lastRow = m_ui->m_outputListWidget->count() - 1;
439  delete m_ui->m_outputListWidget->item(lastRow);
440 }
441 
443 {
444  std::list<te::map::AbstractLayerPtr>::iterator it = m_layers.begin();
445 
446  std::string layerID = m_ui->m_layersComboBox->itemData(index, Qt::UserRole).toString().toStdString();
447 
448  m_ui->m_propertieslistWidget->clear();
449 
450  while(it != m_layers.end())
451  {
452  if(layerID == it->get()->getId().c_str())
453  {
454  std::size_t type;
455  te::map::AbstractLayerPtr selectedLayer = it->get();
456  m_selectedLayer = selectedLayer;
457  std::auto_ptr<const te::map::LayerSchema> schema(selectedLayer->getSchema());
458 
459  if(schema->size() == 0)
460  return;
461 
462  te::common::FreeContents(m_properties);
463  m_properties.clear();
464 
465  const std::vector<te::dt::Property*>& properties = schema->getProperties();
466 
467  te::common::Clone(properties, m_properties);
468 
469  setFunctionsByLayer(m_properties);
470 
471  for(size_t i = 0; i < m_properties.size(); ++i)
472  {
473  type = m_properties[i]->getType();
474 
475  if(type != te::dt::GEOMETRY_TYPE)
476  m_ui->m_propertieslistWidget->addItem(m_properties[i]->getName().c_str());
477  }
478 
479  return;
480  }
481  ++it;
482  }
483 }
484 
486 {
487  m_ui->m_outputListWidget->reset();
488  m_ui->m_outputStatisticsGroupBox->setVisible(visible);
489 }
490 
492 {
493  std::list<te::map::AbstractLayerPtr> filteredLayers = te::vp::GetFilteredLayers(text.toStdString(), m_layers);
494 
495  m_ui->m_layersComboBox->clear();
496 
497  m_ui->m_selectAllComboBox->setCurrentIndex(0);
498  m_ui->m_rejectAllComboBox->setCurrentIndex(0);
499  m_ui->m_outputListWidget->clear();
500 
501  if(text.isEmpty())
502  filteredLayers = m_layers;
503 
504  std::list<te::map::AbstractLayerPtr>::iterator it = filteredLayers.begin();
505 
506  while(it != filteredLayers.end())
507  {
508  if(it->get()->getSchema()->hasGeom())
509  m_ui->m_layersComboBox->addItem(QString(it->get()->getTitle().c_str()), QVariant(it->get()->getId().c_str()));
510  ++it;
511  }
512 }
513 
515 {
516  QString text = m_ui->m_selectAllComboBox->itemText(index);
517  Qt::MatchFlags flag = Qt::MatchEndsWith; //The search term matches the end of the item.
518 
519  if(text.isEmpty())
520  return;
521 
522  QList<QListWidgetItem *> listFound;
523  listFound = m_ui->m_outputListWidget->findItems(text, flag);
524 
525  for(int i=0; i < listFound.size(); ++i)
526  listFound.at(i)->setSelected(true);
527 
528  m_ui->m_rejectAllComboBox->setCurrentIndex(0);
529 }
530 
532 {
533  QString text = m_ui->m_selectAllComboBox->itemText(index);
534  Qt::MatchFlags flag = Qt::MatchEndsWith; //The search term matches the end of the item.
535 
536  if(text=="")
537  return;
538 
539  QList<QListWidgetItem *> listFound;
540  listFound = m_ui->m_outputListWidget->findItems(text, flag);
541 
542  for(int i=0; i < listFound.size(); ++i)
543  listFound.at(i)->setSelected(false);
544 
545  m_ui->m_selectAllComboBox->setCurrentIndex(0);
546 }
547 
549 {
550  if(item->text().isEmpty())
551  {
552  item->setSelected(false);
553  }
554 }
555 
557 {
558  m_ui->m_newLayerNameLineEdit->clear();
559  m_ui->m_newLayerNameLineEdit->setEnabled(true);
561  dlg.exec();
562 
563  std::list<te::da::DataSourceInfoPtr> dsPtrList = dlg.getSelecteds();
564 
565  if(dsPtrList.size() <= 0)
566  return;
567 
568  std::list<te::da::DataSourceInfoPtr>::iterator it = dsPtrList.begin();
569 
570  m_ui->m_repositoryLineEdit->setText(QString(it->get()->getTitle().c_str()));
571 
572  m_outputDatasource = *it;
573 
574  m_toFile = false;
575 }
576 
578 {
579  m_ui->m_newLayerNameLineEdit->clear();
580  m_ui->m_repositoryLineEdit->clear();
581 
582  QString fileName = QFileDialog::getSaveFileName(this, tr("Save as..."),
583  QString(), tr("Shapefile (*.shp *.SHP);;"),0, QFileDialog::DontConfirmOverwrite);
584 
585  if (fileName.isEmpty())
586  return;
587 
588  boost::filesystem::path outfile(fileName.toStdString());
589  std::string aux = outfile.leaf().string();
590  m_ui->m_newLayerNameLineEdit->setText(aux.c_str());
591  aux = outfile.string();
592  m_ui->m_repositoryLineEdit->setText(aux.c_str());
593 
594  m_toFile = true;
595  m_ui->m_newLayerNameLineEdit->setEnabled(false);
596 }
597 
599 {
600  QMessageBox::information(this, "Help", "Under development");
601 }
602 
604 {
605  if(m_ui->m_layersComboBox->count() == 0)
606  {
607  QMessageBox::information(this, "Aggregation", "Select an input layer.");
608  return;
609  }
610 
611  te::map::DataSetLayer* dsLayer = dynamic_cast<te::map::DataSetLayer*>(m_selectedLayer.get());
612  if(!dsLayer)
613  {
614  QMessageBox::information(this, "Aggregation", "Can not execute this operation on this type of layer.");
615  return;
616  }
617 
618  te::da::DataSourcePtr inDataSource = te::da::GetDataSource(dsLayer->getDataSourceId(), true);
619  if (!inDataSource.get())
620  {
621  QMessageBox::information(this, "Aggregation", "The selected input data source can not be accessed.");
622  return;
623  }
624 
625  std::vector<te::dt::Property*> selProperties = getSelectedProperties();
626  if(selProperties.empty())
627  {
628  QMessageBox::information(this, "Aggregation", "Select at least one grouping attribute.");
629  return;
630  }
631 
632  std::string outputdataset = m_ui->m_newLayerNameLineEdit->text().toStdString();
633 
634  if(m_ui->m_repositoryLineEdit->text().isEmpty())
635  {
636  QMessageBox::information(this, "Aggregation", "Define a repository for the result.");
637  return;
638  }
639 
640  if(m_ui->m_newLayerNameLineEdit->text().isEmpty())
641  {
642  QMessageBox::information(this, "Aggregation", "Define a name for the resulting layer.");
643  return;
644  }
645 
646  //progress
648  int id = te::common::ProgressManager::getInstance().addViewer(&v);
649 
650  try
651  {
652  std::map<te::dt::Property*, std::vector<te::stat::StatisticalSummary> > outputStatisticalSummary = getStatisticalSummary();
653 
654  bool res;
655 
656  if (m_toFile)
657  {
658  boost::filesystem::path uri(m_ui->m_repositoryLineEdit->text().toStdString());
659 
660  if (boost::filesystem::exists(uri))
661  {
662  QMessageBox::information(this, "Aggregation", "Output file already exists. Remove it or select a new name and try again.");
663  return;
664  }
665 
666  std::size_t idx = outputdataset.find(".");
667  if (idx != std::string::npos)
668  outputdataset=outputdataset.substr(0,idx);
669 
670  std::map<std::string, std::string> dsinfo;
671  dsinfo["URI"] = uri.string();
672 
673  std::auto_ptr<te::da::DataSource> dsOGR = te::da::DataSourceFactory::make("OGR");
674  dsOGR->setConnectionInfo(dsinfo);
675  dsOGR->open();
676  if (dsOGR->dataSetExists(outputdataset))
677  {
678  QMessageBox::information(this, "Aggregation", "There is already a dataset with the requested name in the output data source. Remove it or select a new name and try again.");
679  return;
680  }
681 
682  this->setCursor(Qt::WaitCursor);
683  res = te::vp::Aggregation(dsLayer->getDataSetName(),inDataSource.get(), selProperties, outputStatisticalSummary, outputdataset, dsOGR.get());
684 
685  if (!res)
686  {
687  this->setCursor(Qt::ArrowCursor);
688  dsOGR->close();
689  QMessageBox::information(this, "Aggregation", "Error: could not generate the aggregation.");
690  reject();
691  }
692  dsOGR->close();
693 
694  // let's include the new datasource in the managers
695  boost::uuids::basic_random_generator<boost::mt19937> gen;
696  boost::uuids::uuid u = gen();
697  std::string id = boost::uuids::to_string(u);
698 
700  ds->setConnInfo(dsinfo);
701  ds->setTitle(uri.stem().string());
702  ds->setAccessDriver("OGR");
703  ds->setType("OGR");
704  ds->setDescription(uri.string());
705  ds->setId(id);
706 
707  te::da::DataSourcePtr newds = te::da::DataSourceManager::getInstance().get(id, "OGR", ds->getConnInfo());
708  newds->open();
710  m_outputDatasource = ds;
711  }
712  else
713  {
714  te::da::DataSourcePtr aux = te::da::GetDataSource(m_outputDatasource->getId());
715  if (!aux)
716  {
717  QMessageBox::information(this, "Aggregation", "The selected output datasource can not be accessed.");
718  return;
719  }
720 
721  if (aux->dataSetExists(outputdataset))
722  {
723  QMessageBox::information(this, "Aggregation", "Dataset already exists. Remove it or select a new name and try again.");
724  return;
725  }
726  this->setCursor(Qt::WaitCursor);
727  res = te::vp::Aggregation(dsLayer->getDataSetName(),inDataSource.get(), selProperties, outputStatisticalSummary, outputdataset, aux.get());
728  if (!res)
729  {
730  this->setCursor(Qt::ArrowCursor);
731  QMessageBox::information(this, "Aggregation", "Error: could not generate the aggregation.");
732  reject();
733  }
734  }
735 
736  // creating a layer for the result
737  te::da::DataSourcePtr outDataSource = te::da::GetDataSource(m_outputDatasource->getId());
738 
739  te::qt::widgets::DataSet2Layer converter(m_outputDatasource->getId());
740 
741  te::da::DataSetTypePtr dt(outDataSource->getDataSetType(outputdataset).release());
742  m_layer = converter(dt);
743  }
744  catch(const std::exception& e)
745  {
746  this->setCursor(Qt::ArrowCursor);
747  QMessageBox::information(this, "Aggregation", e.what());
748  te::common::ProgressManager::getInstance().removeViewer(id);
749  return;
750  }
751 
752  te::common::ProgressManager::getInstance().removeViewer(id);
753  this->setCursor(Qt::ArrowCursor);
754  accept();
755 }
756 
758 {
759  reject();
760 }
te::map::AbstractLayerPtr getLayer()
Get the generated layer.
A layer with reference to a dataset.
Definition: DataSetLayer.h:47
const std::string & getDataSetName() const
A dialog for selecting a data source.
A dialog aggregation operation.
Total number of values.
Definition: Enums.h:45
std::map< te::dt::Property *, std::vector< te::stat::StatisticalSummary > > getStatisticalSummary()
Get the Grouping Functions Type based on selected QListWidgetItem.
void onRejectAllComboBoxChanged(int index)
TEVPEXPORT bool Aggregation(const std::string &inDataset, te::da::DataSource *inDatasource, const std::vector< te::dt::Property * > &groupingProperties, const std::map< te::dt::Property *, std::vector< te::stat::StatisticalSummary > > &statisticalSummary, const std::string &outDataset, te::da::DataSource *outDatasource)
Executes the Aggregation Geographical Operation and persists the result as a dataset in a given outpu...
TESTATEXPORT std::string GetStatSummaryFullName(const int &e)
Get the statistical parameter full name ffrom its enumerator.
Definition: Utils.cpp:85
TEDATAACCESSEXPORT DataSourcePtr GetDataSource(const std::string &datasourceId, const bool opened=true)
Search for a data source with the informed id in the DataSourceManager.
Definition: Utils.cpp:258
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
Standard deviation.
Definition: Enums.h:47
std::list< te::map::AbstractLayerPtr > GetFilteredLayers(std::string text, std::list< te::map::AbstractLayerPtr > layers)
Get a list of AbstractLayer filtered by the name;.
Definition: Utils.cpp:46
A class that represents a data source component.
void setLayers(std::list< te::map::AbstractLayerPtr > layers)
Set the layer that can be used.
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
Coefficient variation.
Definition: Enums.h:53
void onCalculateStatistics(bool visible)
const std::list< te::da::DataSourceInfoPtr > & getSelecteds() const
StatisticalSummary
Define grouping functions type.
Definition: Enums.h:39
static std::auto_ptr< DataSource > make(const std::string &dsType)
const std::string & getDataSourceId() const
AggregationDialog(QWidget *parent=0, Qt::WindowFlags f=0)
Mean.
Definition: Enums.h:43
A class that represents the known capabilities of a specific data source, i.e. this class informs all...
Mode.
Definition: Enums.h:54
void setFunctionsByLayer(std::vector< te::dt::Property * > properties)
Set Grouping Functions Type for &#39;m_outputListWidget&#39; based on Selected Layer.
void setStatisticalSummaryMap()
Map Statistical Summary Type enum for an intuitive name.
Aggregation Vector Processing functions.
Total not null values.
Definition: Enums.h:46
void onFilterLineEditTextChanged(const QString &text)
Utility functions for the data access module.
void onSelectAllComboBoxChanged(int index)
std::vector< te::dt::Property * > getSelectedProperties()
Get the selected properties based on selected QListWidgetItem.
Amplitude.
Definition: Enums.h:51
Maximum value.
Definition: Enums.h:42
boost::shared_ptr< DataSource > DataSourcePtr
Definition: DataSource.h:1395
te::da::DataSourceInfoPtr m_outputDatasource
DataSource information.
void onLayerComboBoxChanged(int index)
Median.
Definition: Enums.h:52
boost::shared_ptr< DataSetType > DataSetTypePtr
Definition: DataSetType.h:653
It models a property definition.
Definition: Property.h:59
Skewness.
Definition: Enums.h:49
Kurtosis.
Definition: Enums.h:50
Variance.
Definition: Enums.h:48
boost::intrusive_ptr< AbstractLayer > AbstractLayerPtr
void onOutputListWidgetClicked(QListWidgetItem *item)
static T & getInstance()
It returns a reference to the singleton instance.
Definition: Singleton.h:120
std::auto_ptr< Ui::AggregationDialogForm > m_ui
boost::shared_ptr< DataSourceInfo > DataSourceInfoPtr
Sum of values.
Definition: Enums.h:44
void setStatisticalSummary()
Set Statistical Summary Type for combobox &#39;m_selectAllComboBox&#39; and &#39;m_rejectAllComboBox&#39; based on a ...
te::dt::Property * getSelectedPropertyByName(std::string propertyName)
Get the selected property based on selected QListWidgetItem using the name of property.
Minimum value.
Definition: Enums.h:41