RasterizationWizardPage.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 // Boost
21 #include <boost/property_tree/ptree.hpp>
22 
23 //Terralib
24 #include "../../../color/ColorBar.h"
25 #include "../../../common/Globals.h"
26 #include "../../../common/STLUtils.h"
27 #include "../../../core/translator/Translator.h"
28 #include "../../../dataaccess/dataset/DataSet.h"
29 #include "../../../dataaccess/datasource/DataSourceManager.h"
30 #include "../../../dataaccess/query_h.h"
31 #include "../../../dataaccess/utils/Utils.h"
32 #include "../../../maptools/GroupingAlgorithms.h"
33 #include "../../../maptools/Utils.h"
34 #include "../../../se.h"
35 #include "../../../se/SymbolizerColorFinder.h"
36 #include "../../../se/Utils.h"
37 #include "../../../srs/SpatialReferenceSystemManager.h"
38 #include "../../widgets/utils/FileDialog.h"
39 #include "../../widgets/datasource/selector/DataSourceSelectorDialog.h"
40 #include "../colorbar/ColorBar.h"
41 #include "../colorbar/ColorCatalogWidget.h"
42 #include "../se/LineSymbolizerWidget.h"
43 #include "../se/PointSymbolizerWidget.h"
44 #include "../se/PolygonSymbolizerWidget.h"
45 #include "../se/SymbologyPreview.h"
47 #include "ui_RasterizationWizardPageForm.h"
48 
49 // Qt
50 #include <QDialogButtonBox>
51 #include <QFileDialog>
52 #include <QMessageBox>
53 #include <QPainter>
54 
55 // Boost
56 #include <boost/algorithm/string.hpp>
57 #include <boost/filesystem.hpp>
58 #include <boost/lexical_cast.hpp>
59 #include <boost/property_tree/json_parser.hpp>
60 
61 //#define MAX_SLICES 200
62 //#define PRECISION 15
63 #define NO_TITLE "No Value"
64 
66  : QWizardPage(parent),
67  m_cb(nullptr),
68  m_colorBar(nullptr),
69  m_toFile(true),
70  m_manual(false)
71 {
72  m_ui.reset(new Ui::RasterizationWizardPageForm);
73 
74  m_ui->setupUi(this);
75 
76  m_ui->m_tableWidget->resizeColumnsToContents();
77 
78  m_ui->m_precSpinBox->setValue(6);
79 
80  QGridLayout* l = new QGridLayout(m_ui->m_colorBarWidget);
81  l->setContentsMargins(0, 0, 0, 0);
82  m_colorBar = new te::qt::widgets::ColorCatalogWidget(m_ui->m_colorBarWidget);
83  l->addWidget(m_colorBar);
84 
85 //configure page
86  this->setTitle(tr("Rasterization"));
87  this->setSubTitle(tr("Define the rasterization parameters."));
88 
89  //connects
90  connect(m_colorBar, SIGNAL(colorBarChanged()), this, SLOT(onColorBarChanged()));
91  connect(m_ui->m_attrComboBox, SIGNAL(activated(int)), this, SLOT(onAttrComboBoxActivated(int)));
92  connect(m_ui->m_applyPushButton, SIGNAL(clicked()), this, SLOT(onApplyPushButtonClicked()));
93  connect(m_ui->m_tableWidget, SIGNAL(itemDoubleClicked(QTableWidgetItem*)), this, SLOT(onTableWidgetItemDoubleClicked(QTableWidgetItem*)));
94  connect(m_ui->m_loadPushButton, SIGNAL(clicked()), this, SLOT(onLoadPushButtonClicked()));
95  connect(m_ui->m_savePushButton, SIGNAL(clicked()), this, SLOT(onSavePushButtonClicked()));
96  connect(m_ui->m_selectAllPushButton, SIGNAL(clicked()), this, SLOT(onSelectAllPushButtonClicked()));
97  connect(m_ui->m_unselectAllPushButton, SIGNAL(clicked()), this, SLOT(onUnselectAllPushButtonClicked()));
98  connect(m_ui->m_targetFileToolButton, SIGNAL(pressed()), this, SLOT(onTargetFileToolButtonPressed()));
99 
100  connect(m_ui->m_resXLineEdit, SIGNAL(editingFinished()), this, SLOT(onResXLineEditEditingFinished()));
101  connect(m_ui->m_resYLineEdit, SIGNAL(editingFinished()), this, SLOT(onResYLineEditEditingFinished()));
102 }
103 
105 {
107  m_legend.clear();
108 }
109 
111 {
112  if (!layer)
113  return;
114 
115  m_layer = layer;
116 
117  listAttributes();
118 
119  m_ui->m_layerLineEdit->setText(m_layer->getTitle().c_str());
120 
121  int srid = m_layer->getSRID();
122  std::string sridName = te::srs::SpatialReferenceSystemManager::getInstance().getName(srid);
123 
124  m_ui->m_layerSRIDLabel->setText(sridName.c_str());
125 }
126 
127 std::vector<std::string> te::qt::widgets::RasterizationWizardPage::getDistinctClasses(const std::string& attrName)
128 {
129  std::string dsId = m_layer->getDataSourceId();
130 
131  std::unique_ptr<te::da::DataSetType> dst = m_layer->getSchema();
132 
134 
135  te::da::FromItem* t = new te::da::DataSetName(dst->getName());
136  te::da::From* from = new te::da::From;
137  from->push_back(t);
138 
140  te::da::Expression* propName = new te::da::PropertyName(attrName);
141  dist->push_back(propName);
142 
143  te::da::OrderByItem* obi = new te::da::OrderByItem(propName);
144 
145  te::da::OrderBy* order = new te::da::OrderBy;
146  order->push_back(obi);
147 
148  te::da::Select* select = new te::da::Select();
149  select->setDistinct(dist);
150  select->setFrom(from);
151  select->setOrderBy(order);
152 
153  std::unique_ptr<te::da::DataSet> result = source->query(select);
154 
155  result->moveBeforeFirst();
156 
157  std::vector<std::string> classes;
158 
159  while (result->moveNext())
160  {
161  std::string className = result->getValue(attrName)->toString();
162 
163  classes.push_back(className);
164  }
165 
166  return classes;
167 
168 
169 }
170 
172 {
173  if (m_manual)
174  {
175  int reply = QMessageBox::question(this, tr("Edit Legend"), tr("Manual changes will be lost. Continue?"), QMessageBox::Yes | QMessageBox::Cancel);
176 
177  if (reply != QMessageBox::Yes)
178  return;
179  }
180 
181  int prec = m_ui->m_precSpinBox->value();
182 
183  std::string attr = m_ui->m_attrComboBox->currentText().toUtf8().data();
184  int attrIdx = m_ui->m_attrComboBox->currentIndex();
185  int attrType = m_ui->m_attrComboBox->itemData(attrIdx).toInt();
186 
188  m_legend.clear();
189 
190  std::string mean;
191 
192  int nullValues = 0;
193 
194  bool update = false;
195 
196  std::vector<std::string> vec;
197 
198  getDataAsString(vec, attr, nullValues);
199 
200  try
201  {
202  te::map::GroupingByUniqueValues("raster", vec, attrType, m_legend, prec);
203  }
204  catch (const std::exception& e)
205  {
206  QMessageBox::warning(this, tr("Rasterization"), QString::fromUtf8(e.what()));
207  return;
208  }
209 
210  buildSymbolizer(mean);
211 
212  createStringNullGroupingItem(nullValues);
213 
214  updateUi(update);
215 
216  m_manual = false;
217 
218  emit applyPushButtonClicked();
219 }
220 
222  int /*idx*/)
223 {
224 
225 }
226 
228 {
229  if (m_layer.get())
230  {
231  buildSymbolizer();
232 
233  updateUi();
234  }
235 }
236 
238  QTableWidgetItem* /*item*/)
239 {
240 
241 }
242 
244  QTableWidgetItem* /*item*/)
245 {
246  int curRow = m_ui->m_tableWidget->currentRow();
247  int curCol = m_ui->m_tableWidget->currentColumn();
248 
249  if (curCol == 4)
250  {
251  te::se::Rule* rule = m_legend[curRow];
252 
253  std::vector<te::se::Symbolizer*> symbVec = rule->getSymbolizers();
254 
255  QDialog* dialog = new QDialog(this);
256  QBoxLayout* layout = new QBoxLayout(QBoxLayout::TopToBottom, dialog);
257 
258  QDialogButtonBox* bbox = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel, Qt::Horizontal, dialog);
259 
260  QWidget* symbWidget = nullptr;
261 
262  if (symbVec[0]->getType() == "PolygonSymbolizer")
263  {
264  symbWidget = new te::qt::widgets::PolygonSymbolizerWidget(dialog);
266  polygonSymbolizerWidget->setSymbolizer((te::se::PolygonSymbolizer*)symbVec[0]);
267  }
268  else if (symbVec[0]->getType() == "LineSymbolizer")
269  {
270  symbWidget = new te::qt::widgets::LineSymbolizerWidget(dialog);
272  lineSymbolizerWidget->setSymbolizer((te::se::LineSymbolizer*)symbVec[0]);
273  }
274  else if (symbVec[0]->getType() == "PointSymbolizer")
275  {
276  symbWidget = new te::qt::widgets::PointSymbolizerWidget(dialog);
278  pointSymbolizerWidget->setSymbolizer((te::se::PointSymbolizer*)symbVec[0]);
279  }
280 
281  layout->addWidget(symbWidget);
282  layout->addWidget(bbox);
283 
284  connect(bbox, SIGNAL(accepted()), dialog, SLOT(accept()));
285  connect(bbox, SIGNAL(rejected()), dialog, SLOT(reject()));
286 
287  if (dialog->exec() == QDialog::Rejected)
288  {
289  delete dialog;
290  return;
291  }
292 
293  if (symbVec[0]->getType() == "PolygonSymbolizer")
294  {
295  symbVec.clear();
297  symbVec.push_back(polygonSymbolizerWidget->getSymbolizer());
298  }
299  else if (symbVec[0]->getType() == "LineSymbolizer")
300  {
301  symbVec.clear();
303  symbVec.push_back(lineSymbolizerWidget->getSymbolizer());
304  }
305  else if (symbVec[0]->getType() == "PointSymbolizer")
306  {
307  symbVec.clear();
309  symbVec.push_back(pointSymbolizerWidget->getSymbolizer());
310  }
311 
312  rule->setSymbolizers(symbVec);
313 
314  QPixmap pix = te::qt::widgets::SymbologyPreview::build(symbVec, QSize(24, 24));
315  QIcon icon(pix);
316 
317  QTableWidgetItem* newItem = new QTableWidgetItem(icon, "");
318  newItem->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled);
319 
320  m_ui->m_tableWidget->setItem(curRow, 0, newItem);
321 
322  delete dialog;
323 
324  m_manual = true;
325 
326  updateUi(true);
327 
328  emit applyPushButtonClicked();
329  }
330 }
331 
333 {
334  QString fileName = QFileDialog::getOpenFileName(this, tr("Open..."),
335  QString(), tr("LEG (*.leg *.LEG);;"), nullptr, QFileDialog::DontConfirmOverwrite);
336 
337  if (fileName.isEmpty())
338  return;
339 
340  m_ui->m_tableWidget->setRowCount(0);
341 
342  boost::property_tree::ptree pt;
343  boost::property_tree::json_parser::read_json(fileName.toUtf8().data(), pt);
344 
345  boost::property_tree::ptree legend = pt.get_child("Legend");
346 
347  std::string attrName = legend.get<std::string>("Attribute");
348  std::string precision = legend.get<std::string>("Precision");
349 
350  m_ui->m_attrComboBox->setCurrentIndex(m_ui->m_attrComboBox->findText(attrName.c_str()));
351  m_ui->m_precSpinBox->setValue(boost::lexical_cast<double>(precision));
352 
353  std::vector<std::vector<std::string> > items;
354 
355  for(boost::property_tree::ptree::value_type &v: legend.get_child("Items"))
356  {
357  std::vector<std::string> item;
358  item.push_back(v.second.get<std::string>("ClassName"));
359  item.push_back(v.second.get<std::string>("Red"));
360  item.push_back(v.second.get<std::string>("Green"));
361  item.push_back(v.second.get<std::string>("Blue"));
362 
363  items.push_back(item);
364  }
365 
366  m_ui->m_tableWidget->setRowCount(static_cast<int>(items.size()));
367 
368  for (std::size_t i = 0; i < items.size(); ++i)
369  {
370  m_ui->m_tableWidget->setItem(static_cast<int>(i), 0, new QTableWidgetItem(items[i][0].c_str()));
371  m_ui->m_tableWidget->setItem(static_cast<int>(i), 1, new QTableWidgetItem(items[i][1].c_str()));
372  m_ui->m_tableWidget->setItem(static_cast<int>(i), 2, new QTableWidgetItem(items[i][2].c_str()));
373  m_ui->m_tableWidget->setItem(static_cast<int>(i), 3, new QTableWidgetItem(items[i][3].c_str()));
374 
375  QColor color;
376  color.setRgb(boost::lexical_cast<int>(items[i][1]), boost::lexical_cast<int>(items[i][2]), boost::lexical_cast<int>(items[i][3]));
377 
378  QPixmap pix(24, 24);
379  QPainter p(&pix);
380 
381  p.fillRect(0, 0, 12, 24, color);
382  p.fillRect(12, 0, 12, 24, color);
383  p.setBrush(Qt::transparent);
384  p.setPen(Qt::black);
385  p.drawRect(0, 0, 23, 23);
386 
387  QIcon icon(pix);
388 
389  QTableWidgetItem* item = new QTableWidgetItem(icon, "");
390  //item->setBackgroundColor(color);
391  item->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled);
392  m_ui->m_tableWidget->setItem(static_cast<int>(i), 4, item);
393 
394  {
395  QTableWidgetItem* item = new QTableWidgetItem();
396  item->setCheckState(Qt::Checked);
397  m_ui->m_tableWidget->setItem(static_cast<int>(i), 5, item);
398  }
399 
400  }
401 
402 }
403 
405 {
406  QString fileName = QFileDialog::getSaveFileName(this, tr("Save as..."),
407  QString(), tr("LEG (*.leg *.LEG);;"), nullptr, QFileDialog::DontConfirmOverwrite);
408 
409  saveLegend(fileName.toUtf8().data());
410 }
411 
412 void te::qt::widgets::RasterizationWizardPage::getDataAsString(std::vector<std::string>& vec, const std::string& attrName, int& nullValues)
413 {
414  assert(m_layer.get());
415 
416  std::unique_ptr<te::map::LayerSchema> dsType(m_layer->getSchema());
417 
418  std::size_t idx=std::string::npos;
419 
420  for (std::size_t t = 0; t < dsType->getProperties().size(); ++t)
421  {
422  if (dsType->getProperty(t)->getName() == attrName)
423  {
424  idx = t;
425  break;
426  }
427  }
428 
429  std::unique_ptr<te::da::DataSet> ds(m_layer->getData());
430 
431  ds->moveBeforeFirst();
432 
433  while (ds->moveNext())
434  {
435  if (!ds->isNull(idx))
436  vec.push_back(ds->getAsString(idx));
437  else
438  ++nullValues;
439  }
440 }
441 
443 {
444  delete m_cb;
445 
447 
448  int legendSize = static_cast<int>(m_legend.size());
449 
450  std::vector<te::color::RGBAColor> colorVec;
451 
452  if (meanTitle.empty())
453  {
454  colorVec = m_cb->getSlices(legendSize);
455  }
456  else
457  {
458  int beforeMean = 0;
459  int afterMean = 0;
460 
461  for (size_t t = 0; t < m_legend.size(); ++t)
462  {
463  std::string ruleName = *m_legend[t]->getName();
464 
465  if (ruleName != meanTitle)
466  {
467  beforeMean++;
468  }
469  else
470  {
471  afterMean = (int)(m_legend.size() - t - 1);
472  break;
473  }
474  }
475 
476  std::vector<te::color::RGBAColor> lowerColorVec = m_cb->getLowerMeanSlices(beforeMean);
477  te::color::RGBAColor meanColor = m_cb->getMeanSlice();
478  std::vector<te::color::RGBAColor> upperColorVec = m_cb->getUpperMeanSlices(afterMean);
479 
480  for (size_t t = 0; t < lowerColorVec.size(); ++t)
481  colorVec.push_back(lowerColorVec[t]);
482 
483  colorVec.push_back(meanColor);
484 
485  for (size_t t = 0; t < upperColorVec.size(); ++t)
486  colorVec.push_back(upperColorVec[t]);
487  }
488 
489  if (colorVec.size() != m_legend.size())
490  return;
491 
492  int geomType = getGeometryType();
493 
494  for (size_t t = 0; t < colorVec.size(); ++t)
495  {
496  std::vector<te::se::Symbolizer*> symbVec;
497 
498  te::se::Symbolizer* s = te::se::CreateSymbolizer((te::gm::GeomType)geomType, colorVec[t].getColor());
499 
500  symbVec.push_back(s);
501 
502  m_legend[t]->setSymbolizers(symbVec);
503  }
504 }
505 
507 {
508  if (count == 0)
509  return;
510 
511  std::string* ruleName = new std::string(NO_TITLE);
512 
513  te::se::Rule* rule = new te::se::Rule;
514  rule->setName(ruleName);
516 
517  int geomType = getGeometryType();
518  std::vector<te::se::Symbolizer*> symbVec;
520  symbVec.push_back(s);
521 
522  rule->setSymbolizers(symbVec);
523 
524  m_legend.push_back(rule);
525 }
526 
528 {
529  disconnect(m_ui->m_tableWidget, SIGNAL(itemChanged(QTableWidgetItem*)), this, SLOT(onTableWidgetItemChanged(QTableWidgetItem*)));
530 
531  m_ui->m_tableWidget->setRowCount(0);
532 
533  QStringList list;
534  list.append(tr("Class"));
535  list.append(tr("R"));
536  list.append(tr("G"));
537  list.append(tr("B"));
538  list.append(tr("Color"));
539  list.append(tr("Select"));
540 
541  m_ui->m_tableWidget->setColumnCount(6);
542  m_ui->m_tableWidget->setHorizontalHeaderLabels(list);
543 
544  te::color::ColorBar* cb = nullptr;
545 
546  if (loadColorBar)
547  {
548  if (!m_legend.empty() && !m_legend[0]->getSymbolizers().empty() && !m_legend[m_legend.size() - 1]->getSymbolizers().empty())
549  {
551 
552  scf.find(m_legend[0]->getSymbolizers()[0]);
553  te::color::RGBAColor initColor = scf.getColor();
554 
555  scf.find(m_legend[m_legend.size() - 1]->getSymbolizers()[0]);
556  te::color::RGBAColor endColor = scf.getColor();
557 
558  cb = new te::color::ColorBar(initColor, endColor, 256);
559  }
560  }
561 
562  for (std::size_t t = 0; t < m_legend.size(); ++t)
563  {
564  te::se::Rule* rule = m_legend[t];
565 
566  int newrow = m_ui->m_tableWidget->rowCount();
567  m_ui->m_tableWidget->insertRow(newrow);
568 
569  //class
570  {
571  //Value
572  std::string ruleValue;
573  te::fe::GetFilterUniqueValue(rule->getFilter(), ruleValue);
574  QTableWidgetItem* item = new QTableWidgetItem(QString::fromUtf8(ruleValue.c_str()));
575  item->setFlags(Qt::ItemIsEnabled);
576  m_ui->m_tableWidget->setItem(newrow, 0, item);
577  }
578 
579  const std::vector<te::se::Symbolizer*>& ss = rule->getSymbolizers();
581  const te::se::Fill* fill = ps->getFill();
583 
584  //R
585  {
586  QTableWidgetItem* item = new QTableWidgetItem(QString::number(color.getRed()));
587  m_ui->m_tableWidget->setItem(newrow, 1, item);
588  }
589 
590  //G
591  {
592  QTableWidgetItem* item = new QTableWidgetItem(QString::number(color.getGreen()));
593  m_ui->m_tableWidget->setItem(newrow, 2, item);
594  }
595 
596  //B
597  {
598  QTableWidgetItem* item = new QTableWidgetItem(QString::number(color.getBlue()));
599  m_ui->m_tableWidget->setItem(newrow, 3, item);
600  }
601 
602  //Color
603  {
604  const std::vector<te::se::Symbolizer*>& ss = rule->getSymbolizers();
605  QPixmap pix = te::qt::widgets::SymbologyPreview::build(ss, QSize(24, 24));
606  QIcon icon(pix);
607  QTableWidgetItem* item = new QTableWidgetItem(icon, "");
608  item->setFlags(Qt::ItemIsEnabled);
609  m_ui->m_tableWidget->setItem(newrow, 4, item);
610  }
611 
612  //checked
613  {
614  QTableWidgetItem* item = new QTableWidgetItem();
615  item->setCheckState(Qt::Checked);
616  m_ui->m_tableWidget->setItem(newrow, 5, item);
617  }
618  }
619 
620  if (cb)
621  {
622  disconnect(m_colorBar, SIGNAL(colorBarChanged()), this, SLOT(onColorBarChanged()));
623 
625  cbW->setColorBar(cb);
626 
627  connect(m_colorBar, SIGNAL(colorBarChanged()), this, SLOT(onColorBarChanged()));
628  }
629 
630  m_ui->m_tableWidget->resizeColumnsToContents();
631 
632  connect(m_ui->m_tableWidget, SIGNAL(itemChanged(QTableWidgetItem*)), this, SLOT(onTableWidgetItemChanged(QTableWidgetItem*)));
633 }
634 
636 {
637  assert(m_layer.get());
638 
640 }
641 
643 {
644  QString curValue = m_ui->m_attrComboBox->currentText();
645 
646  m_ui->m_attrComboBox->clear();
647 
648  std::unique_ptr<te::map::LayerSchema> dsType(m_layer->getSchema());
649 
650  for (size_t t = 0; t < dsType->getProperties().size(); ++t)
651  {
652  te::dt::Property* p = dsType->getProperty(t);
653 
654  int dataType = p->getType();
655 
656  switch (dataType)
657  {
658  case te::dt::INT16_TYPE:
659  case te::dt::INT32_TYPE:
660  case te::dt::INT64_TYPE:
661  case te::dt::FLOAT_TYPE:
662  case te::dt::DOUBLE_TYPE:
664  case te::dt::STRING_TYPE:
665  m_ui->m_attrComboBox->addItem(p->getName().c_str(), p->getType());
666 
667  default:
668  continue;
669  }
670  }
671 
672  if (curValue.isEmpty() == false)
673  {
674  int idx = m_ui->m_attrComboBox->findText(curValue);
675 
676  if (idx != -1)
677  m_ui->m_attrComboBox->setCurrentIndex(idx);
678  }
679 }
680 
682 {
683  int size = m_ui->m_tableWidget->rowCount();
684 
685  for (int i = 0; i < size; ++i)
686  {
687  QTableWidgetItem* item = m_ui->m_tableWidget->item(i, 5);
688  item->setCheckState(Qt::Checked);
689  }
690 }
691 
693 {
694  int size = m_ui->m_tableWidget->rowCount();
695 
696  for (int i = 0; i < size; ++i)
697  {
698  QTableWidgetItem* item = m_ui->m_tableWidget->item(i, 5);
699  item->setCheckState(Qt::Unchecked);
700  }
701 }
702 
704 {
705  if (m_ui->m_resXLineEdit->text().isEmpty())
706  return;
707 
708  te::gm::Envelope env = m_layer->getExtent();
709  if (!env.isValid())
710  {
711  QMessageBox::warning(this, tr("Cellular Spaces"), tr("Invalid bounding box."));
712  return;
713  }
714 
715  double resX = m_ui->m_resXLineEdit->text().toDouble();
716 
717  int maxCols = (int)ceil((env.m_urx - env.m_llx) / resX);
718  m_ui->m_colsLineEdit->setText(QString::number(maxCols));
719 }
720 
722 {
723  if (m_ui->m_resYLineEdit->text().isEmpty())
724  return;
725 
726  te::gm::Envelope env = m_layer->getExtent();
727  if (!env.isValid())
728  {
729  QMessageBox::warning(this, tr("Cellular Spaces"), tr("Invalid bounding box."));
730  return;
731  }
732 
733  double resY = m_ui->m_resXLineEdit->text().toDouble();
734  //unitConvertion(resY, getResolutionUnit(), te::srs::SpatialReferenceSystemManager::getInstance().getUnit(m_bbSRID));
735 
736  int maxRows = (int)ceil((env.m_ury - env.m_lly) / resY);
737  m_ui->m_rowsLineEdit->setText(QString::number(maxRows));
738 }
739 
741 {
742  return m_toFile;
743 }
744 
746 {
747  return m_outputDatasource;
748 }
749 
751 {
752  return m_ui->m_resXLineEdit->text().toDouble();
753 }
754 
756 {
757  return m_ui->m_resYLineEdit->text().toDouble();
758 }
759 
761 {
762  te::gm::Envelope env = m_layer->getExtent();
763  return env;
764 }
765 
767 {
768  return m_layer->getSRID();
769 }
770 
772 {
773  m_ui->m_newLayerNameLineEdit->clear();
774  m_ui->m_repositoryLineEdit->clear();
775 
777 
778  try
779  {
780  fileDialog.exec();
781  }
782  catch(te::common::Exception& ex)
783  {
784  QMessageBox::warning(this, tr("File information"), ex.what());
785  return;
786  }
787  catch(...)
788  {
789  QMessageBox::warning(this, tr("File information"), tr("Output layer is invalid."));
790  return;
791  }
792 
793  m_ui->m_newLayerNameLineEdit->setText(fileDialog.getFileName().c_str());
794  m_ui->m_repositoryLineEdit->setText(fileDialog.getPath().c_str());
795 
796  m_toFile = true;
797  m_ui->m_newLayerNameLineEdit->setEnabled(false);
798 }
799 
801 {
802  if (m_ui->m_repositoryLineEdit->text().isEmpty())
803  return "";
804 
805  return m_ui->m_repositoryLineEdit->text().toUtf8().data();
806 }
807 
809 {
810  return m_ui->m_attrComboBox->currentText().toUtf8().data();
811 }
812 
813 std::map<std::string, std::vector<int> > te::qt::widgets::RasterizationWizardPage::getInformations()
814 {
815  std::map<std::string, std::vector<int> > result;
816 
817  for (int i = 0; i < m_ui->m_tableWidget->rowCount(); ++i)
818  {
819  if (m_ui->m_tableWidget->item(i, 5)->checkState() != Qt::Checked)
820  continue;
821 
822  std::vector<int> v;
823  v.push_back(static_cast<int>(i+1));
824  v.push_back(m_ui->m_tableWidget->item(i, 1)->text().toInt());
825  v.push_back(m_ui->m_tableWidget->item(i, 2)->text().toInt());
826  v.push_back(m_ui->m_tableWidget->item(i, 3)->text().toInt());
827 
828  result[m_ui->m_tableWidget->item(i, 0)->text().toUtf8().data()] = v;
829  }
830 
831  return result;
832 }
833 
835 {
836  bool hasErrors = false;
837 
838  std::string errors;
839 
840  if (!m_layer)
841  {
842  if (hasErrors)
843  errors += "\n";
844 
845  errors += " - " + std::string(TE_TR("Layer Invalid."));
846 
847  hasErrors = true;
848  }
849 
850  if (m_ui->m_attrComboBox->currentText().isEmpty())
851  {
852  if (hasErrors)
853  errors += "\n";
854 
855  errors += " - " + std::string(TE_TR("Attribute not selected."));
856 
857  hasErrors = true;
858  }
859 
860  if (m_ui->m_resXLineEdit->text().isEmpty() || m_ui->m_resYLineEdit->text().isEmpty())
861  {
862  if (hasErrors)
863  errors += "\n";
864 
865  errors += " - " + std::string(TE_TR("Resolution not informed."));
866 
867  hasErrors = true;
868  }
869 
870  if (m_ui->m_repositoryLineEdit->text().isEmpty())
871  {
872  if (hasErrors)
873  errors += "\n";
874 
875  errors += " - " + std::string(TE_TR("Output repository not informed."));
876 
877  hasErrors = true;
878  }
879 
880  if (m_ui->m_tableWidget->rowCount() < 1)
881  {
882  if (hasErrors)
883  errors += "\n";
884 
885  errors += " - " + std::string(TE_TR("No legend was created. Choose the attribute and apply."));
886 
887  hasErrors = true;
888  }
889 
890  if (hasErrors)
891  {
892  std::string msg = std::string(TE_TR("Some errors accured:\n\n"));
893  msg += errors;
894 
895  throw te::common::Exception(msg);
896  }
897 }
898 
900 {
901  return m_ui->m_tableWidget;
902 }
903 
905 {
906  int rowCount = m_ui->m_tableWidget->rowCount();
907 
908  if (rowCount < 1)
909  return;
910 
911  if (path.empty())
912  return;
913 
914  boost::property_tree::ptree pt;
915  boost::property_tree::ptree legend;
916 
917  std::string attrName = m_ui->m_attrComboBox->currentText().toUtf8().data();
918  std::string precision = m_ui->m_precSpinBox->text().toUtf8().data();
919 
920  legend.add("Attribute", attrName);
921  legend.add("Precision", precision);
922 
923  boost::property_tree::ptree items;
924 
925  for (int i = 0; i < m_ui->m_tableWidget->rowCount(); ++i)
926  {
927  std::string className = m_ui->m_tableWidget->item(i, 0)->text().toUtf8().data();
928  std::string r = m_ui->m_tableWidget->item(i, 1)->text().toUtf8().data();
929  std::string g = m_ui->m_tableWidget->item(i, 2)->text().toUtf8().data();
930  std::string b = m_ui->m_tableWidget->item(i, 3)->text().toUtf8().data();
931 
932  boost::property_tree::ptree item;
933  item.add("ClassName", className);
934  item.add("Red", r);
935  item.add("Green", g);
936  item.add("Blue", b);
937 
938  items.add_child("Item", item);
939  }
940 
941  legend.add_child("Items", items);
942 
943  pt.add_child("Legend", legend);
944 
945  boost::property_tree::write_json(path, pt);
946 }
const Fill * getFill() const
Gets the Fill associates with the PolygonSymbolizer.
TESEEXPORT void GetColor(const te::se::Stroke *stroke, te::color::RGBAColor &color)
It gets the RGBA color from the Stroke element.
Defines a component for choose a file.
Definition: FileDialog.h:52
GeomType
Each enumerated type is compatible with a Well-known Binary (WKB) type code.
An abstract class that models a source of data in a query.
Definition: FromItem.h:50
A widget used to build a point symbolizer element.
int getRed() const
It returns the red component color value (a value from 0 to 255).
Definition: RGBAColor.h:307
A PolygonSymbolizer is used to draw a polygon (or other area-type geometries), including filling its ...
A class that models the name of a dataset used in a From clause.
Definition: DataSetName.h:43
TESEEXPORT Symbolizer * CreateSymbolizer(const te::gm::GeomType &geomType)
Try creates an appropriate symbolizer based on given geometry type.
boost::shared_ptr< DataSource > DataSourcePtr
boost::ptr_vector< Expression > Distinct
A class that models a Distinct clause on a query.
Definition: Distinct.h:37
A class that models the name of any property of an object.
A Symbolizer describes how a feature is to appear on a map.
Definition: Symbolizer.h:80
std::unique_ptr< Ui::RasterizationWizardPageForm > m_ui
virtual const char * what() const
It outputs the exception message.
std::map< std::string, std::vector< int > > getInformations()
TEMAPEXPORT void GroupingByUniqueValues(std::string attrName, std::vector< std::string > &inputValues, int dataType, std::vector< te::se::Rule * > &rules, int precision)
It groups the values using the unique value algorithm.
void setName(std::string *name)
Definition: Rule.cpp:58
void setSymbolizer(const te::se::PointSymbolizer *symb)
Sets a point symbolizer element to this widget.
TEMAPEXPORT te::gm::GeomType GetGeomType(const te::map::AbstractLayerPtr &layer)
It gets the geometry type of the given layer.
int getBlue() const
It returns the blue component color value (a value from 0 to 255).
Definition: RGBAColor.h:317
double m_urx
Upper right corner x-coordinate.
int getGreen() const
It returns the green component color value (a value from 0 to 255).
Definition: RGBAColor.h:312
const std::vector< te::color::RGBAColor > & getUpperMeanSlices(const int &n)
A widget used to build a line symbolizer element.
boost::ptr_vector< OrderByItem > OrderBy
A class that can be used to model an ORDER BY clause.
Definition: OrderBy.h:37
A PointSymbolizer specifies the rendering of a graphic Symbolizer at a point.
static te::dt::Date ds(2010, 01, 01)
void setFilter(te::fe::Filter *f)
Definition: Rule.cpp:91
const te::fe::Filter * getFilter() const
Definition: Rule.cpp:97
#define TE_TR(message)
It marks a string in order to get translated.
Definition: Translator.h:242
It models a property definition.
Definition: Property.h:59
This is an abstract class that models a query expression.
te::color::ColorBar * m_cb
Terralib color bar objetc.
const std::vector< te::color::RGBAColor > & getLowerMeanSlices(const int &n)
te::se::Symbolizer * getSymbolizer() const
Gets the configured point symbolizer element.
int b
Definition: TsRtree.cpp:32
TEFEEXPORT te::fe::Filter * CreateFilterByUniqueValue(const std::string &attrName, const std::string &value)
double m_llx
Lower left corner x-coordinate.
te::da::DataSourceInfoPtr m_outputDatasource
DataSource information.
static SpatialReferenceSystemManager & getInstance()
It returns a reference to the singleton instance.
An Envelope defines a 2D rectangular region.
void exec()
This method will open the dialog of file selection and populate the class members with the chosen fil...
Definition: FileDialog.cpp:54
std::vector< std::string > getDistinctClasses(const std::string &attrName)
te::qt::widgets::ColorCatalogWidget * m_colorBar
Widget used to pick a color.
te::map::AbstractLayerPtr m_layer
TerraLib layer auto ptr.
void setDistinct(Distinct *d)
If Distinct is specified, all duplicate rows are removed from the result set (one row is kept from ea...
Definition: Select.cpp:839
void updateUi(bool loadColorBar=false)
Updates the widget form based on internal fill element.
te::gm::Polygon * p
te::se::Symbolizer * getSymbolizer() const
Gets the configured line symbolizer element.
A Fill specifies the pattern for filling an area geometry.
Definition: Fill.h:59
void getDataAsString(std::vector< std::string > &vec, const std::string &attrName, int &nullValues)
const te::color::RGBAColor & getMeanSlice()
void setSymbolizers(const std::vector< Symbolizer * > &symbs)
Definition: Rule.cpp:152
void setOrderBy(OrderBy *o)
It sets the list of expressions used to sort the output result.
Definition: Select.cpp:829
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
A Symbology Enconding visitor that finds a color given a symbolizer element. If you want to use this ...
A widget used to build a polygon symbolizer element.
const std::vector< te::color::RGBAColor > & getSlices(const int &n)
It generates color bar.
const std::vector< Symbolizer * > & getSymbolizers() const
Definition: Rule.cpp:158
boost::ptr_vector< FromItem > From
It models the FROM clause for a query.
Definition: From.h:37
double m_lly
Lower left corner y-coordinate.
int getType() const
It returns the property data type.
Definition: Property.h:161
#define NO_TITLE
std::string getPath()
This method will return the chosen path.
Definition: FileDialog.cpp:103
void find(const te::se::Symbolizer *symbolizer)
It find the color based on given symbolizer.
A Rule is used to attach property/scale conditions to and group the individual symbols used for rende...
Definition: Rule.h:76
double m_ury
Upper right corner y-coordinate.
A helper class for 32-bit RGBA (Red-Green-Blue-Alpha channel) color.
Definition: RGBAColor.h:57
void onTableWidgetItemChanged(QTableWidgetItem *item)
void setSymbolizer(const te::se::PolygonSymbolizer *symb)
Sets a polygon symbolizer element to this widget.
te::color::ColorBar * getColorBar()
It returns the colorbar.
It models the concept of color bar.
A LineSymbolizer is used to style a stroke along a linear geometry type, such as a string of line seg...
const SvgParameter * getColor() const
Definition: Fill.cpp:76
te::qt::widgets::colorbar::ColorBar * getColorBar()
void onTableWidgetItemDoubleClicked(QTableWidgetItem *item)
std::string getFileName()
This method will return the file name.
Definition: FileDialog.cpp:113
void setLayer(te::map::AbstractLayerPtr layer)
void setColorBar(te::color::ColorBar *cb)
It sets the color bar.
A class that can be used in an ORDER BY clause to sort the items of a resulting query.
Definition: OrderByItem.h:53
te::color::RGBAColor getColor()
Get the color.
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
std::vector< te::se::Rule * > m_legend
Rule items.
static QPixmap build(const te::se::Symbolizer *symb, const QSize &size)
Generates the preview of given symbolizer element.
bool isValid() const
It tells if the rectangle is valid or not.
te::se::Symbolizer * getSymbolizer() const
Gets the configured polygon symbolizer element.
boost::shared_ptr< DataSourceInfo > DataSourceInfoPtr
void setSymbolizer(const te::se::LineSymbolizer *symb)
Sets a line symbolizer element to this widget.
void setFrom(From *f)
It sets the list of source information.
Definition: Select.cpp:789
static const std::string sm_nanStr
Not a number string value.
const std::string & getName() const
It returns the property name.
Definition: Property.h:127
TEFEEXPORT void GetFilterUniqueValue(const te::fe::Filter *filter, std::string &value)