CloudDetectionDialog.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/qt/widgets/connector/clouddetection/CloudDetectionDialog.cpp
22 
23  \brief ....
24 */
25 
26 // TerraLib
27 #include "../../../rp/CloudDetection.h"
28 #include "../../../common/Exception.h"
29 #include "../../../common/progress/ProgressManager.h"
30 #include "../../../common/StringUtils.h"
31 #include "../../../core/translator/Translator.h"
32 #include "../../../dataaccess/datasource/DataSource.h"
33 #include "../../../dataaccess/datasource/DataSourceFactory.h"
34 #include "../../../dataaccess/datasource/DataSourceInfoManager.h"
35 #include "../../../dataaccess/datasource/DataSourceTransactor.h"
36 #include "../../../dataaccess/datasource/DataSourceManager.h"
37 #include "../../../dataaccess/utils/Utils.h"
38 #include "../../../geometry/GeometryProperty.h"
39 #include "../../../geometry/Utils.h"
40 #include "../../../maptools/Utils.h"
41 #include "../../../memory/DataSet.h"
42 #include "../../../memory/DataSetItem.h"
43 #include "../../../raster/RasterSummaryManager.h"
44 #include "../../../raster/Utils.h"
45 #include "../../../maptools/CanvasConfigurer.h"
46 #include "../../../se/serialization/xml/Symbolizer.h"
47 #include "../../../se/Symbolizer.h"
48 #include "../../../se/Utils.h"
49 #include "../../../xml/AbstractWriter.h"
50 #include "../../../xml/AbstractWriterFactory.h"
51 #include "../../../xml/Reader.h"
52 #include "../../../xml/ReaderFactory.h"
53 #include "../se/PolygonSymbolizerWidget.h"
54 #include "../../widgets/utils/FileDialog.h"
55 #include "../../widgets/datasource/selector/DataSourceSelectorDialog.h"
56 #include "../../widgets/canvas/Canvas.h"
57 #include "../../widgets/canvas/MapDisplay.h"
58 #include "../../widgets/layer/utils/DataSet2Layer.h"
59 #include "../../widgets/progress/ProgressViewerDialog.h"
60 #include "../../widgets/rp/RasterHistogramWidget.h"
61 #include "../../widgets/layer/search/LayerSearchDialog.h"
62 #include "../../widgets/layer/search/LayerSearchWidget.h"
63 #include "../../widgets/tools/ExtentAcquire.h"
64 #include "ui_CloudDetectionDialogForm.h"
65 #include "CloudDetectionDialog.h"
66 
67 // Qt
68 #include <QFileDialog>
69 #include <QDialogButtonBox>
70 #include <QMessageBox>
71 
72 // Boost
73 #include <boost/filesystem.hpp>
74 #include <boost/uuid/random_generator.hpp>
75 #include <boost/uuid/uuid_io.hpp>
76 
78 
79 te::qt::widgets::CloudDetectionDialog::CloudDetectionDialog(QWidget* parent, Qt::WindowFlags f)
80  : QDialog(parent, f),
81  m_ui(new Ui::CloudDetectionDialogForm),
82  m_mapDisplay(nullptr),
83  m_symbolizer(nullptr)
84 {
85 // add controls
86  m_ui->setupUi(this);
87 
88  m_lastText = "";
89  m_lastSelectedRow = -1;
90 
91  // set icons
92  m_ui->m_upToolButton->setIcon(QIcon::fromTheme("go-up"));
93  m_ui->m_downToolButton->setIcon(QIcon::fromTheme("go-down"));
94  m_ui->m_targetDatasourceToolButton->setIcon(QIcon::fromTheme("datasource"));
95  m_ui->m_styleToolButton->setIcon(QIcon::fromTheme("style"));
96 
97  QGridLayout* displayLayout = new QGridLayout(m_ui->m_navigatorWidget);
98  m_navigator.reset(new te::qt::widgets::RpToolsWidget(m_ui->m_navigatorWidget));
99  displayLayout->addWidget(m_navigator.get());
100  displayLayout->setContentsMargins(0,0,0,0);
101 
102  m_ui->m_navigatorWidget->setEnabled(false);
103 
104  connect(m_ui->m_cloudLayerComboBox, SIGNAL(activated(int)), this, SLOT(onCloudLayerComboBoxActivated(int)));
105  connect(m_ui->m_shadowLayerComboBox, SIGNAL(activated(int)), this, SLOT(onShadowLayerComboBoxActivated(int)));
106  connect(m_ui->m_cloudSearchLayerToolButton, SIGNAL(clicked()), this, SLOT(onSearchCloudLayerToolButtonClicked()));
107  connect(m_ui->m_shadowSearchLayerToolButton, SIGNAL(clicked()), this, SLOT(onSearchShadowLayerToolButtonClicked()));
108  connect(m_ui->m_cloudBandComboBox, SIGNAL(activated(int)), this, SLOT(onCloudBandComboBoxActivated(int)));
109  connect(m_ui->m_shadowBandComboBox, SIGNAL(activated(int)), this, SLOT(onShadowBandComboBoxActivated(int)));
110  connect(m_ui->m_upToolButton, SIGNAL(clicked()), this, SLOT(onUpToolButtonClicked()));
111  connect(m_ui->m_downToolButton, SIGNAL(clicked()), this, SLOT(onDownToolButtonClicked()));
112  connect(m_ui->m_previewCheckBox, SIGNAL(toggled(bool)), this, SLOT(onPreviewCheckBoxToggled(bool)));
113  connect(m_ui->m_targetDatasourceToolButton, SIGNAL(clicked()), this, SLOT(onTargetDatasourceToolButtonClicked()));
114  connect(m_ui->m_targetFileToolButton, SIGNAL(clicked()), this, SLOT(onTargetFileToolButtonClicked()));
115  connect(m_ui->m_okPushButton, SIGNAL(clicked()), this, SLOT(onOkPushButtonClicked()));
116  connect(m_ui->m_styleToolButton, SIGNAL(clicked()), this, SLOT(onStyleToolButtonClicked()));
117 
118  connect(m_ui->m_tableWidget, SIGNAL(cellClicked(int, int)), this, SLOT(onCellClicked(int, int)));
119  connect(m_ui->m_tableWidget, SIGNAL(cellDoubleClicked(int, int)), this, SLOT(onCellDoubleClicked(int, int)));
120  connect(m_ui->m_tableWidget, SIGNAL(cellChanged(int, int)), this, SLOT(onCellChanged(int, int)));
121 
122  connect(m_navigator.get(), SIGNAL(envelopeAcquired(te::gm::Envelope)), this, SLOT(onEnvelopeAcquired(te::gm::Envelope)));
123 
124  m_ui->m_filterTableWidget->setRowCount(2);
125 
126  QCheckBox* checkBox1 = new QCheckBox();
127  checkBox1->setParent(m_ui->m_filterTableWidget);
128  checkBox1->setChecked(true);
129  m_ui->m_filterTableWidget->setCellWidget(0, 0, checkBox1);
130  QTableWidgetItem *item = new QTableWidgetItem(QString("Opening"));
131  item->setFlags(item->flags() & ~Qt::ItemIsEditable);
132  m_ui->m_filterTableWidget->setItem(0, 1, item);
133  QTableWidgetItem *item1 = new QTableWidgetItem(QString("2"));
134  m_ui->m_filterTableWidget->setItem(0, 2, item1);
135 
136  QCheckBox* checkBox2 = new QCheckBox();
137  checkBox2->setParent(m_ui->m_filterTableWidget);
138  checkBox2->setChecked(true);
139  m_ui->m_filterTableWidget->setCellWidget(1, 0, checkBox2);
140  QTableWidgetItem *item2 = new QTableWidgetItem(QString("Closing"));
141  item2->setFlags(item2->flags() & ~Qt::ItemIsEditable);
142  m_ui->m_filterTableWidget->setItem(1, 1, item2);
143  QTableWidgetItem *item3 = new QTableWidgetItem(QString("2"));
144  m_ui->m_filterTableWidget->setItem(1, 2, item3);
145 
146  //build histogram
147  QGridLayout* histogramLayout = new QGridLayout(m_ui->m_histWidget);
148  m_histogramWidget.reset(new te::qt::widgets::RasterHistogramWidget(m_ui->m_histWidget));
149  m_histogramWidget->setEnableTools(true);
150  histogramLayout->addWidget(m_histogramWidget.get());
151  histogramLayout->setContentsMargins(0, 0, 0, 0);
152 
153 #if (QT_VERSION >= 0x050000)
154  m_ui->m_filterTableWidget->horizontalHeader()->setSectionResizeMode(QHeaderView::ResizeToContents);
155 #else
156  m_ui->m_filterTableWidget->horizontalHeader()->setResizeMode(QHeaderView::ResizeToContents);
157 #endif
158 
159  m_ui->m_helpPushButton->setNameSpace("dpi.inpe.br.plugins");
160  m_ui->m_helpPushButton->setPageReference("plugins/rp/rp_cloudDetection.html");
161 
162 }
163 
165 {
166  writeStyle();
167 }
168 
169 void te::qt::widgets::CloudDetectionDialog::setLayers(std::list<te::map::AbstractLayerPtr> layers)
170 {
171  int i = 0;
172 
173  QApplication::setOverrideCursor(Qt::WaitCursor);
174 
175  std::list<te::map::AbstractLayerPtr>::iterator it = layers.begin();
176  //Filter only raster layers
177  while (it != layers.end())
178  {
179  std::unique_ptr<te::da::DataSetType> dsType = it->get()->getSchema();
180  if (dsType->hasRaster())
181  {
182  m_layers.push_back(it->get());
183  m_ui->m_cloudLayerComboBox->insertItem(i, it->get()->getTitle().c_str());
184  m_ui->m_shadowLayerComboBox->insertItem(i, it->get()->getTitle().c_str());
185  ++i;
186  }
187 
188  ++it;
189  }
190 
191  m_cloudLayer = m_layers.begin()->get();
192  m_shadowLayer = m_layers.begin()->get();
193 
194  QTableWidgetItem *itemCloudMin = new QTableWidgetItem(QString(""));
195  itemCloudMin->setFlags(Qt::ItemIsEnabled | Qt::ItemIsEditable | Qt::ItemIsSelectable);
196  m_ui->m_tableWidget->setItem(0, 0, itemCloudMin);
197  QTableWidgetItem *itemCloudMax = new QTableWidgetItem(QString(""));
198  itemCloudMax->setFlags(Qt::ItemIsEnabled | Qt::ItemIsEditable | Qt::ItemIsSelectable);
199  m_ui->m_tableWidget->setItem(0, 1, itemCloudMax);
200  QTableWidgetItem *itemShadowMin = new QTableWidgetItem(QString(""));
201  itemShadowMin->setFlags(Qt::ItemIsEnabled | Qt::ItemIsEditable | Qt::ItemIsSelectable);
202  m_ui->m_tableWidget->setItem(1, 0, itemShadowMin);
203  QTableWidgetItem *itemShadowMax = new QTableWidgetItem(QString(""));
204  itemShadowMax->setFlags(Qt::ItemIsEnabled | Qt::ItemIsEditable | Qt::ItemIsSelectable);
205  m_ui->m_tableWidget->setItem(1, 1, itemShadowMax);
206 
207  setCloudBands();
208  setShadowBands();
209 
210  setCloudMinMax();
211  setShadowMinMax();
212 
213  m_ui->m_tableWidget->setCurrentCell(0, 0);
214 
215  m_ui->m_tableWidget->resizeColumnsToContents();
216 
217  m_ui->m_tableWidget->selectRow(0);
218 
219 #if (QT_VERSION >= 0x050000)
220  m_ui->m_tableWidget->horizontalHeader()->setSectionResizeMode(QHeaderView::ResizeToContents);
221 #else
222  m_ui->m_tableWidget->horizontalHeader()->setResizeMode(QHeaderView::ResizeToContents);
223 #endif
224 
225  onCellClicked(0,0);
226 
227  QApplication::restoreOverrideCursor();
228 }
229 
231 {
232  m_navigator->setMapDisplay(mapDisplay);
233  m_mapDisplay = mapDisplay;
234 
235  connect(m_mapDisplay, SIGNAL(extentChanged()), this, SLOT(onMapDisplayExtentChanged()));
236 }
237 
239 {
240  //configure tool
241  m_navigator->setActionGroup(actionGroup);
242  m_navigator->enableBoxAction();
243 }
244 
246 {
247  m_userPath = path;
248 
249  QString style = QString::fromUtf8(m_userPath.c_str())+ "/styleCloudDetection.xml";
250 
251  QFile file(style);
252 
253  if(file.exists())
254  readStyle();
255 }
256 
258 {
259  auto l_front = m_layers.begin();
260 
261  std::advance(l_front, index);
262  m_cloudLayer = *l_front;
263 
264  setCloudBands();
265  setCloudMinMax();
266 
267  int row = m_ui->m_tableWidget->currentRow();
268 
269  if (row == -1)
270  {
271  row = 0;
272  m_ui->m_tableWidget->setCurrentCell(0, 0);
273  }
274 
275  if (row == 0)
276  m_histogramWidget->setInputRaster(m_cloudRaster.get());
277  else if (row == 1)
278  m_histogramWidget->setInputRaster(m_shadowRaster.get());
279 
280  m_lastSelectedRow = row;
281 
282  drawHistogram();
283 }
284 
286 {
287  auto l_front = m_layers.begin();
288 
289  std::advance(l_front, index);
290  m_shadowLayer = *l_front;
291 
292  setShadowBands();
293  setShadowMinMax();
294 
295  int row = m_ui->m_tableWidget->currentRow();
296 
297  if (row == -1)
298  {
299  row = 1;
300  m_ui->m_tableWidget->setCurrentCell(1, 0);
301  }
302 
303  if (row == 0)
304  m_histogramWidget->setInputRaster(m_cloudRaster.get());
305  else if (row == 1)
306  m_histogramWidget->setInputRaster(m_shadowRaster.get());
307 
308  m_lastSelectedRow = row;
309 
310  drawHistogram();
311 }
312 
314 {
315  QApplication::setOverrideCursor(Qt::WaitCursor);
316 
317  if (m_cloudMinValue[index] == std::numeric_limits<double>::min() && m_cloudMaxValue[index] == std::numeric_limits<double>::max())
318  {
319  // get minimun and maximun values from cloud layer
320 
323  const std::complex<double>* cmin = rsMin->at(index).m_minVal;
324  const std::complex<double>* cmax = rsMax->at(index).m_maxVal;
325  double min = cmin->real();
326  double max = cmax->real();
327 
328  m_cloudMinValue[index] = min;
329  m_cloudMaxValue[index] = max;
330  }
331 
332  setCloudMinMax();
333 
334  int row = m_ui->m_tableWidget->currentRow();
335 
336  if (row == -1)
337  {
338  row = 0;
339  m_ui->m_tableWidget->setCurrentCell(0, 0);
340  }
341 
342  if (row == 0)
343  m_histogramWidget->setInputRaster(m_cloudRaster.get());
344  else if (row == 1)
345  m_histogramWidget->setInputRaster(m_shadowRaster.get());
346 
347  m_lastSelectedRow = row;
348 
349  drawHistogram();
350 
351  QApplication::restoreOverrideCursor();
352 }
353 
355 {
356  QApplication::setOverrideCursor(Qt::WaitCursor);
357 
358  if (m_shadowMinValue[index] == std::numeric_limits<double>::min() && m_shadowMaxValue[index] == std::numeric_limits<double>::max())
359  {
360  // get minimun and maximun values from shadow layer
363  const std::complex<double>* cmin = rsMin->at(index).m_minVal;
364  const std::complex<double>* cmax = rsMax->at(index).m_maxVal;
365  double min = cmin->real();
366  double max = cmax->real();
367 
368  m_shadowMinValue[index] = min;
369  m_shadowMaxValue[index] = max;
370  }
371 
372  setShadowMinMax();
373 
374  int row = m_ui->m_tableWidget->currentRow();
375 
376  if (row == -1)
377  {
378  row = 1;
379  m_ui->m_tableWidget->setCurrentCell(1, 0);
380  }
381 
382  if (row == 0)
383  m_histogramWidget->setInputRaster(m_cloudRaster.get());
384  else if (row == 1)
385  m_histogramWidget->setInputRaster(m_shadowRaster.get());
386 
387  m_lastSelectedRow = row;
388 
389  drawHistogram();
390 
391  QApplication::restoreOverrideCursor();
392 }
393 
395 {
397  dlg->getWidget()->filterOnlyByRaster();
398  dlg->getWidget()->setList(m_layers);
399  if (dlg->exec())
400  {
401  std::list<te::map::AbstractLayerPtr> layerList = dlg->getWidget()->getSelecteds();
402 
403  std::list<te::map::AbstractLayerPtr>::iterator it = layerList.begin();
404 
405  m_cloudLayer = *it;
406 
407  std::list<te::map::AbstractLayerPtr>::iterator itLayer = std::find(m_layers.begin(), m_layers.end(), *it);
408  const int pos = std::distance(m_layers.begin(), itLayer);
409  m_ui->m_cloudLayerComboBox->setCurrentIndex(pos);
410 
411  setCloudBands();
412  setCloudMinMax();
413  }
414 }
415 
417 {
419  dlg->getWidget()->filterOnlyByRaster();
420  dlg->getWidget()->setList(m_layers);
421  if (dlg->exec())
422  {
423  std::list<te::map::AbstractLayerPtr> layerList = dlg->getWidget()->getSelecteds();
424 
425  std::list<te::map::AbstractLayerPtr>::iterator it = layerList.begin();
426 
427  m_shadowLayer = *it;
428 
429  std::list<te::map::AbstractLayerPtr>::iterator itLayer = std::find(m_layers.begin(), m_layers.end(), *it);
430  const int pos = std::distance(m_layers.begin(), itLayer);
431  m_ui->m_shadowLayerComboBox->setCurrentIndex(pos);
432 
433  // get minimun and maximun values from shadow layer
434  std::unique_ptr<te::da::DataSetType> dsType = m_shadowLayer->getSchema();
435  te::rst::RasterProperty* rasterProp = te::da::GetFirstRasterProperty(dsType.get());
436  std::unique_ptr<te::da::DataSet> dsRaster = m_shadowLayer->getData();
437  std::unique_ptr<te::rst::Raster> raster = dsRaster->getRaster(rasterProp->getName());
438 
439  for (int b = 0; b < static_cast<int>(raster->getNumberOfBands()); b++)
440  {
443  const std::complex<double>* cmin = rsMin->at(b).m_minVal;
444  const std::complex<double>* cmax = rsMax->at(b).m_maxVal;
445 
446  double min = cmin->real();
447  double max = cmax->real();
448 
449  m_shadowMinValue.push_back(min);
450  m_shadowMaxValue.push_back(max);
451  }
452 
453  setShadowBands();
454  setShadowMinMax();
455  }
456 }
457 
459 {
460  if (m_ui->m_filterTableWidget->currentRow() == -1)
461  {
462  QMessageBox::warning(this, tr("Warning"), tr("Please, select a entry first to move!"));
463  return;
464  }
465 
466  int row = m_ui->m_filterTableWidget->currentRow();
467 
468  if (row == m_ui->m_filterTableWidget->rowCount() - 1)
469  return;
470 
471  QTableWidgetItem *item1Col0 = m_ui->m_filterTableWidget->takeItem(row, 0);
472  QTableWidgetItem *item1Col1 = m_ui->m_filterTableWidget->takeItem(row, 1);
473  QTableWidgetItem *item1Col2 = m_ui->m_filterTableWidget->takeItem(row, 2);
474  QTableWidgetItem *item2Col0 = m_ui->m_filterTableWidget->takeItem(row + 1, 0);
475  QTableWidgetItem *item2Col1 = m_ui->m_filterTableWidget->takeItem(row + 1, 1);
476  QTableWidgetItem *item2Col2 = m_ui->m_filterTableWidget->takeItem(row + 1, 2);
477 
478  m_ui->m_filterTableWidget->setItem(row, 0, item2Col0);
479  m_ui->m_filterTableWidget->setItem(row, 1, item2Col1);
480  m_ui->m_filterTableWidget->setItem(row, 2, item2Col2);
481  m_ui->m_filterTableWidget->setItem(row + 1, 0, item1Col0);
482  m_ui->m_filterTableWidget->setItem(row + 1, 1, item1Col1);
483  m_ui->m_filterTableWidget->setItem(row + 1, 2, item1Col2);
484 }
485 
487 {
488  if (m_ui->m_filterTableWidget->currentRow() == -1)
489  {
490  QMessageBox::warning(this, tr("Warning"), tr("Please, select a entry first to move!"));
491  return;
492  }
493 
494  int row = m_ui->m_filterTableWidget->currentRow();
495 
496  if (row == 0)
497  return;
498 
499  QTableWidgetItem *item1Col0 = m_ui->m_filterTableWidget->takeItem(row, 0);
500  QTableWidgetItem *item1Col1 = m_ui->m_filterTableWidget->takeItem(row, 1);
501  QTableWidgetItem *item1Col2 = m_ui->m_filterTableWidget->takeItem(row, 2);
502  QTableWidgetItem *item2Col0 = m_ui->m_filterTableWidget->takeItem(row - 1, 0);
503  QTableWidgetItem *item2Col1 = m_ui->m_filterTableWidget->takeItem(row - 1, 1);
504  QTableWidgetItem *item2Col2 = m_ui->m_filterTableWidget->takeItem(row - 1, 2);
505 
506  m_ui->m_filterTableWidget->setItem(row, 0, item2Col0);
507  m_ui->m_filterTableWidget->setItem(row, 1, item2Col1);
508  m_ui->m_filterTableWidget->setItem(row, 2, item2Col2);
509  m_ui->m_filterTableWidget->setItem(row - 1, 0, item1Col0);
510  m_ui->m_filterTableWidget->setItem(row - 1, 1, item1Col1);
511  m_ui->m_filterTableWidget->setItem(row - 1, 2, item1Col2);
512 }
513 
515 {
516  if(isChecked)
517  {
518  m_ui->m_navigatorWidget->setEnabled(true);
519  m_navigator->setEnvelopeTool(true);
520  }
521  else
522  {
523  m_ui->m_navigatorWidget->setEnabled(false);
524  m_navigator->setEnvelopeTool(false);
525  }
526 }
527 
529  int /*column*/)
530 {
531  if (row == m_lastSelectedRow)
532  return;
533 
534  if (row == 0)
535  m_histogramWidget->setInputRaster(m_cloudRaster.get());
536  else if (row == 1)
537  m_histogramWidget->setInputRaster(m_shadowRaster.get());
538 
539  m_lastSelectedRow = row;
540 
541  drawHistogram();
542 }
543 
545 {
546  m_lastText = m_ui->m_tableWidget->item(row, column)->text().toUtf8().data();
547 }
548 
550 {
551  if (!isdigit(*m_ui->m_tableWidget->item(row, column)->text().toUtf8().data()))
552  {
553  m_ui->m_tableWidget->item(row, column)->setText(m_lastText.c_str());
554  return;
555  }
556 }
557 
559  int column)
560 {
561  if (column != 0)
562  return;
563 }
564 
566 {
567  if (column != 2)
568  return;
569 
570  m_lastText = m_ui->m_filterTableWidget->item(row, column)->text().toUtf8().data();
571 }
572 
574 {
575  if (column != 2)
576  return;
577 
578  if (!isdigit(*m_ui->m_filterTableWidget->item(row, column)->text().toUtf8().data()))
579  {
580  m_ui->m_filterTableWidget->item(row, column)->setText(m_lastText.c_str());
581  return;
582  }
583 }
584 
586 {
587  m_ui->m_newLayerNameLineEdit->clear();
588  m_ui->m_newLayerNameLineEdit->setEnabled(true);
590  dlg.exec();
591 
592  std::list<te::da::DataSourceInfoPtr> dsPtrList = dlg.getSelecteds();
593 
594  if (dsPtrList.empty())
595  return;
596 
597  std::list<te::da::DataSourceInfoPtr>::iterator it = dsPtrList.begin();
598 
599  m_ui->m_repositoryLineEdit->setText(QString(it->get()->getTitle().c_str()));
600 }
601 
603 {
604  m_ui->m_newLayerNameLineEdit->clear();
605  m_ui->m_repositoryLineEdit->clear();
606 
608 
609  try
610  {
611  fileDialog.exec();
612  }
613  catch(te::common::Exception& ex)
614  {
615  QMessageBox::warning(this, tr("File information"), ex.what());
616  return;
617  }
618  catch(...)
619  {
620  QMessageBox::warning(this, tr("File information"), tr("Output layer is invalid."));
621  return;
622  }
623 
624  m_ui->m_newLayerNameLineEdit->setText(fileDialog.getFileName().c_str());
625  m_ui->m_repositoryLineEdit->setText(fileDialog.getPath().c_str());
626 
627  m_ui->m_newLayerNameLineEdit->setEnabled(false);
628 }
629 
631 {
632  if (!m_ui->m_previewCheckBox->isChecked() || !env.isValid())
633  return;
634 
635  if (env.getLowerLeftX() == 0 && env.getLowerLeftY() == 0 && env.getUpperRightX() == 0 && env.getUpperRightY() == 0)
636  return;
637 
638  // verify if is necessary convert the raster to the given srid
639  bool needRemap = false;
640  if (m_ui->m_tableWidget->currentRow() == 0)
641  {
642  if ((m_mapDisplay->getSRID() != TE_UNKNOWN_SRS) && (m_cloudLayer->getSRID() != TE_UNKNOWN_SRS) && (m_mapDisplay->getSRID() != m_cloudLayer->getSRID()))
643  needRemap = true;
644  }
645  else if (m_ui->m_tableWidget->currentRow() == 1)
646  {
647  if ((m_mapDisplay->getSRID() != TE_UNKNOWN_SRS) && (m_shadowLayer->getSRID() != TE_UNKNOWN_SRS) && (m_mapDisplay->getSRID() != m_shadowLayer->getSRID()))
648  needRemap = true;
649  }
650 
651  te::gm::Envelope envOut = env;
652 
653  // create a SRS converter
654  std::unique_ptr<te::srs::Converter> converter(new te::srs::Converter());
655 
656  if (needRemap)
657  {
658  converter->setSourceSRID(m_mapDisplay->getSRID());
659 
660  if (m_ui->m_tableWidget->currentRow() == 0)
661  converter->setTargetSRID(m_cloudLayer->getSRID());
662  else if (m_ui->m_tableWidget->currentRow() == 1)
663  converter->setTargetSRID(m_shadowLayer->getSRID());
664 
665  converter->convert(envOut.getLowerLeftX(), envOut.getLowerLeftY(), envOut.m_llx, envOut.m_lly);
666  converter->convert(envOut.getUpperRightX(), envOut.getUpperRightY(), envOut.m_urx, envOut.m_ury);
667  }
668 
669  if ((m_ui->m_tableWidget->currentRow() == 0) && (!envOut.intersects(m_cloudLayer->getExtent())))
670  {
671  QMessageBox::warning(this, tr("Warning"), tr("ROI is invalid."));
672  return;
673  }
674  else if ((m_ui->m_tableWidget->currentRow() == 1) && (!envOut.intersects(m_shadowLayer->getExtent())))
675  {
676  QMessageBox::warning(this, tr("Warning"), tr("ROI is invalid."));
677  return;
678  }
679 
681 
682  drawGeom();
683 
685 }
686 
688 {
689  drawGeom();
690 
691  if(m_ui->m_previewCheckBox->isChecked())
692  applyPreview();
693 }
694 
696 {
697  //check output parameters
698  if (m_ui->m_newLayerNameLineEdit->text().isEmpty())
699  {
700  QMessageBox::information(this, tr("Cloud Detection"), tr("Output image is not defined."));
701  return;
702  }
703 
704  if (!execute())
705  return;
706 
707  clearCanvas();
708 
709  emit closeTool();
710 }
711 
713 {
714  QDialog* dialog = new QDialog(this);
715  QBoxLayout* layout = new QBoxLayout(QBoxLayout::TopToBottom, dialog);
716 
717  QDialogButtonBox* bbox = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel, Qt::Horizontal, dialog);
718 
719  QWidget* symbWidget = nullptr;
720 
721  symbWidget = new te::qt::widgets::PolygonSymbolizerWidget(dialog);
723 
724  if(m_symbolizer != nullptr)
726 
727  layout->addWidget(symbWidget);
728  layout->addWidget(bbox);
729 
730  connect(bbox, SIGNAL(accepted()), dialog, SLOT(accept()));
731  connect(bbox, SIGNAL(rejected()), dialog, SLOT(reject()));
732 
733  if(dialog->exec() == QDialog::Rejected)
734  return;
735 }
736 
738 {
739  if (m_symbolizer == nullptr)
740  return;
741 
742  std::unique_ptr<te::xml::AbstractWriter> writer(te::xml::AbstractWriterFactory::make());
743 
744  QString path = QString::fromStdString(m_userPath)+ "/styleCloudDetection.xml";
745 
746  writer->setURI(path.toUtf8().data());
747 
748  writer->writeStartDocument("UTF-8", "no");
749 
750  writer->writeStartElement("PolygonSymbolizer");
751 
752  writer->writeAttribute("xmlns", "http://www.opengis.net/sld");
753  writer->writeAttribute("xmlns:ogc", "http://www.opengis.net/ogc");
754  writer->writeAttribute("xmlns:se", "http://www.opengis.net/se");
755  writer->writeAttribute("xmlns:xlink", "http://www.w3.org/1999/xlink");
756  writer->writeAttribute("xmlns:xsi", "http://www.w3.org/2001/XMLSchema-instance");
757  writer->writeAttribute("xsi:schemaLocation", "http://www.opengis.net/sld PolygonSymbolizer.xsd");
758 
759  writer->writeAttribute("version", m_symbolizer->getVersion());
760 
762 
763  writer->writeEndElement("PolygonSymbolizer");
764 
765  writer->writeToFile();
766 }
767 
769 {
770  std::unique_ptr<te::xml::Reader> reader(te::xml::ReaderFactory::make());
771  reader->setValidationScheme(false);
772 
773  QString path = QString::fromStdString(m_userPath)+ "/styleCloudDetection.xml";
774 
775  reader->read(path.toUtf8().data());
776  reader->next();
777 
778  if ((reader->getNodeType() == te::xml::START_ELEMENT) &&
779  (reader->getElementLocalName() == "PolygonSymbolizer"))
780  reader->next();
781 
783 }
784 
786 {
787  //get cloud layer
788  std::unique_ptr<te::rst::Raster> cloudRst(te::map::GetRaster(m_cloudLayer.get()));
789 
790  //get shadow layer
791  std::unique_ptr<te::rst::Raster> shadowRst(te::map::GetRaster(m_shadowLayer.get()));
792 
793  if (!cloudRst->getExtent()->intersects(*shadowRst->getExtent()))
794  {
795  QMessageBox::warning(this, tr("Cloud Detection"), tr("Input layers don't intersect!"));
796  return false;
797  }
798 
799  if ((cloudRst->getNumberOfColumns() != shadowRst->getNumberOfColumns()) ||
800  (cloudRst->getNumberOfRows() != shadowRst->getNumberOfRows()))
801  {
802  QMessageBox::warning(this, tr("Cloud Detection"), tr("Input layers has diferents sizes!"));
803  return false;
804  }
805 
806  int cloudBand = m_ui->m_cloudBandComboBox->currentText().toUtf8().toInt();
807  int shadowBand = m_ui->m_shadowBandComboBox->currentText().toUtf8().toInt();
808 
809  double minCloud = atof(m_ui->m_tableWidget->item(0, 0)->text().toUtf8().data());
810  double maxCloud = atof(m_ui->m_tableWidget->item(0, 1)->text().toUtf8().data());
811  double minShadow = atof(m_ui->m_tableWidget->item(1, 0)->text().toUtf8().data());
812  double maxShadow = atof(m_ui->m_tableWidget->item(1, 1)->text().toUtf8().data());
813 
814  std::vector<te::rp::Filter::InputParameters::FilterType> vecFilter;
815  std::vector<int> vecIt;
816 
817  int nrows = m_ui->m_filterTableWidget->rowCount();
818 
819  for (int i = 0; i < nrows; i++)
820  {
821  if (!dynamic_cast<QCheckBox*>(m_ui->m_filterTableWidget->cellWidget(i, 0))->isChecked())
822  continue;
823 
824  std::string filter = m_ui->m_filterTableWidget->item(i, 1)->text().toUtf8().data();
825  int nIt = m_ui->m_filterTableWidget->item(i, 2)->text().toUtf8().toInt();
826 
827  if (te::common::Convert2LCase(filter) == "opening")
828  {
829  vecFilter.push_back(te::rp::Filter::InputParameters::FilterType::ErosionFilterT);
830  vecIt.push_back(nIt);
831 
832  vecFilter.push_back(te::rp::Filter::InputParameters::FilterType::DilationFilterT);
833  vecIt.push_back(nIt);
834  }
835  else if (te::common::Convert2LCase(filter) == "closing")
836  {
837  vecFilter.push_back(te::rp::Filter::InputParameters::FilterType::DilationFilterT);
838  vecIt.push_back(nIt);
839 
840  vecFilter.push_back(te::rp::Filter::InputParameters::FilterType::ErosionFilterT);
841  vecIt.push_back(nIt);
842  }
843  }
844 
845  std::unique_ptr<te::rp::CloudDetection> cloudDetection(new te::rp::CloudDetection());
846 
847  try
848  {
849  QApplication::setOverrideCursor(Qt::WaitCursor);
850 
851  //run cloud detection operation
852  te::rst::Raster* raster = cloudDetection->executeCloudDetection(cloudRst.get(), shadowRst.get(), cloudBand, shadowBand,
853  minCloud, maxCloud, minShadow, maxShadow, vecFilter, vecIt);
854 
855  //check output parameters
856  std::string outputdataset = m_ui->m_newLayerNameLineEdit->text().toUtf8().data();
857 
858  if (outputdataset.empty())
859  {
860  QApplication::restoreOverrideCursor();
861  QMessageBox::warning(this, tr("Vectorizer"), tr("Output dataset name not defined."));
862  return false;
863  }
864 
865  std::string uriStr = m_ui->m_repositoryLineEdit->text().toUtf8().data();
866 
867  if (uriStr.empty())
868  {
869  QApplication::restoreOverrideCursor();
870  QMessageBox::warning(this, tr("Vectorizer"), tr("Output repository name not defined."));
871  return false;
872  }
873 
874  //check output datasource parameters
875  te::da::DataSourceInfoPtr outDSInfo;
876 
877  boost::filesystem::path uri(uriStr);
878 
879  std::size_t idx = outputdataset.find(".");
880  if (idx != std::string::npos)
881  outputdataset = outputdataset.substr(0, idx);
882 
883  std::string dsinfo("file://" + uri.string());
884 
885  // let's include the new datasource in the managers
886  boost::uuids::basic_random_generator<boost::mt19937> gen;
887  boost::uuids::uuid u = gen();
888  std::string id = boost::uuids::to_string(u);
889 
891  ds->setConnInfo(dsinfo);
892  ds->setTitle(uri.stem().string());
893  ds->setAccessDriver("OGR");
894  ds->setType("OGR");
895  ds->setDescription(uri.string());
896  ds->setId(id);
897 
899  outDSInfo = ds;
900 
901  //output parameters
902  std::vector<te::gm::Geometry*> geomVec;
903  std::vector< double > geomsValues;
904 
905  //vectorize
906  if (!vectorize(raster, geomVec, geomsValues))
907  {
908  QApplication::restoreOverrideCursor();
909  return false;
910  }
911 
912  //save data
913  std::unique_ptr<te::da::DataSetType> dsType = createDataSetType(outputdataset, raster->getSRID());
914 
915  std::unique_ptr<te::mem::DataSet> dsMem = createDataSet(dsType.get(), geomVec, geomsValues);
916 
917  te::da::DataSourcePtr dataSource = te::da::DataSourceManager::getInstance().get(outDSInfo->getId(), outDSInfo->getType(), outDSInfo->getConnInfo());
918 
919  saveDataSet(dsMem.get(), dsType.get(), dataSource, outputdataset);
920 
921  //create output layer
922  te::da::DataSourcePtr outDataSource = te::da::GetDataSource(outDSInfo->getId());
923 
924  te::qt::widgets::DataSet2Layer converter(outDSInfo->getId());
925 
926  te::da::DataSetTypePtr dt(outDataSource->getDataSetType(outputdataset).release());
927 
928  m_outputLayer = converter(dt);
929 
930  delete raster;
931  }
932  catch (te::common::Exception& e)
933  {
934  QApplication::restoreOverrideCursor();
935  QMessageBox::warning(this, tr("Cloud Detection"), e.what());
936  return false;
937  }
938 
939  QApplication::restoreOverrideCursor();
940 
941  emit addLayer(m_outputLayer);
942 
943  return true;
944 }
945 
946 bool te::qt::widgets::CloudDetectionDialog::vectorize(te::rst::Raster* raster, std::vector<te::gm::Geometry*>& geomVec, std::vector< double >& geomsValues)
947 {
948  //input parameters
949  unsigned int band = 0;
950  unsigned int maxGeom = 0;
951 
952  //progress
954 
955  QApplication::setOverrideCursor(Qt::WaitCursor);
956 
957  try
958  {
959  //run operation
960  raster->vectorize(geomVec, band, maxGeom, &geomsValues);
961  }
962  catch (const std::exception& e)
963  {
964  QMessageBox::warning(this, tr("Vectorizer"), e.what());
965 
966  QApplication::restoreOverrideCursor();
967 
968  return false;
969  }
970  catch (...)
971  {
972  QMessageBox::warning(this, tr("Vectorizer"), tr("An exception has occurred!"));
973 
974  QApplication::restoreOverrideCursor();
975 
976  return false;
977  }
978 
979  QApplication::restoreOverrideCursor();
980 
981  return true;
982 }
983 
985 {
986  m_ui->m_cloudBandComboBox->clear();
987  m_cloudMinValue.clear();
988  m_cloudMaxValue.clear();
989 
991 
992  for (int b = 0; b < static_cast<int>(m_cloudRaster->getNumberOfBands()); b++)
993  {
994  m_ui->m_cloudBandComboBox->addItem(te::common::Convert2String(b).c_str());
995 
996  m_cloudMinValue.push_back(std::numeric_limits<double>::min());
997  m_cloudMaxValue.push_back(std::numeric_limits<double>::max());
998  }
999 
1000  // get minimun and maximun values from cloud layer
1003  const std::complex<double>* cmin = rsMin->at(0).m_minVal;
1004  const std::complex<double>* cmax = rsMax->at(0).m_maxVal;
1005  double min = cmin->real();
1006  double max = cmax->real();
1007 
1008  m_cloudMinValue[0] = min;
1009  m_cloudMaxValue[0] = max;
1010 }
1011 
1013 {
1014  m_ui->m_shadowBandComboBox->clear();
1015  m_shadowMinValue.clear();
1016  m_shadowMaxValue.clear();
1017 
1019 
1020  for (int b = 0; b < static_cast<int>(m_shadowRaster->getNumberOfBands()); b++)
1021  {
1022  m_ui->m_shadowBandComboBox->addItem(te::common::Convert2String(b).c_str());
1023 
1024  m_shadowMinValue.push_back(std::numeric_limits<double>::min());
1025  m_shadowMaxValue.push_back(std::numeric_limits<double>::max());
1026  }
1027 
1028  // get minimun and maximun values from shadow layer
1031  const std::complex<double>* cmin = rsMin->at(0).m_minVal;
1032  const std::complex<double>* cmax = rsMax->at(0).m_maxVal;
1033  double min = cmin->real();
1034  double max = cmax->real();
1035 
1036  m_shadowMinValue[0] = min;
1037  m_shadowMaxValue[0] = max;
1038 }
1039 
1041 {
1042  std::string vmin = te::common::Convert2String(m_cloudMinValue[m_ui->m_cloudBandComboBox->currentIndex()], 2);
1043  m_ui->m_tableWidget->item(0, 0)->setText(QString(vmin.c_str()));
1044 
1045  std::string vmax = te::common::Convert2String(m_cloudMaxValue[m_ui->m_cloudBandComboBox->currentIndex()], 2);
1046  m_ui->m_tableWidget->item(0, 1)->setText(QString(vmax.c_str()));
1047 }
1048 
1050 {
1051  std::string vmin = te::common::Convert2String(m_shadowMinValue[m_ui->m_shadowBandComboBox->currentIndex()], 2);
1052  m_ui->m_tableWidget->item(1, 0)->setText(QString(vmin.c_str()));
1053 
1054  std::string vmax = te::common::Convert2String(m_shadowMaxValue[m_ui->m_shadowBandComboBox->currentIndex()], 2);
1055  m_ui->m_tableWidget->item(1, 1)->setText(QString(vmax.c_str()));
1056 }
1057 
1059 {
1060  int i = m_ui->m_tableWidget->currentRow();
1061 
1062  if (i == -1)
1063  return;
1064 
1065  QApplication::setOverrideCursor(Qt::WaitCursor);
1066 
1067  m_histogramWidget->setChartInputColor(127, 127, 127);
1068 
1069  int bandIdx = -1;
1070 
1071  if (i == 0)
1072  bandIdx = m_ui->m_cloudBandComboBox->currentIndex();
1073  else if (i == 1)
1074  bandIdx = m_ui->m_shadowBandComboBox->currentIndex();
1075 
1076  double min = m_ui->m_tableWidget->item(i, 0)->text().toDouble();
1077  double max = m_ui->m_tableWidget->item(i, 1)->text().toDouble();
1078 
1079  m_histogramWidget->updateMinimumValueLine(min, false);
1080  m_histogramWidget->updateMaximumValueLine(max, false);
1081 
1082  m_histogramWidget->drawHistogram(bandIdx);
1083 
1084  QApplication::restoreOverrideCursor();
1085 }
1086 
1088 {
1089  if (!m_cloudRasterPreview.get() || !m_shadowRasterPreview.get())
1090  return;
1091 
1092  QApplication::setOverrideCursor(Qt::WaitCursor);
1093 
1094  if (!m_cloudRasterPreview->getExtent()->intersects(*m_shadowRasterPreview->getExtent()))
1095  {
1096  QApplication::restoreOverrideCursor();
1097  QMessageBox::warning(this, tr("Cloud Detection"), tr("Input layers don't intersect!"));
1098  return;
1099  }
1100 
1101  if ((m_cloudRasterPreview->getNumberOfColumns() != m_shadowRasterPreview->getNumberOfColumns()) ||
1102  (m_cloudRasterPreview->getNumberOfRows() != m_shadowRasterPreview->getNumberOfRows()))
1103  {
1104  QApplication::restoreOverrideCursor();
1105  QMessageBox::warning(this, tr("Cloud Detection"), tr("Input layers has diferents sizes!"));
1106  return;
1107  }
1108 
1109  int cloudBand = m_ui->m_cloudBandComboBox->currentText().toUtf8().toInt();
1110  int shadowBand = m_ui->m_shadowBandComboBox->currentText().toUtf8().toInt();
1111 
1112  double minCloud = atof(m_ui->m_tableWidget->item(0, 0)->text().toUtf8().data());
1113  double maxCloud = atof(m_ui->m_tableWidget->item(0, 1)->text().toUtf8().data());
1114  double minShadow = atof(m_ui->m_tableWidget->item(1, 0)->text().toUtf8().data());
1115  double maxShadow = atof(m_ui->m_tableWidget->item(1, 1)->text().toUtf8().data());
1116 
1117  std::vector<te::rp::Filter::InputParameters::FilterType> vecFilter;
1118  std::vector<int> vecIt;
1119 
1120  int nrows = m_ui->m_filterTableWidget->rowCount();
1121 
1122  for (int i = 0; i < nrows; i++)
1123  {
1124  if (!dynamic_cast<QCheckBox*>(m_ui->m_filterTableWidget->cellWidget(i, 0))->isChecked())
1125  {
1126  continue;
1127  }
1128 
1129  std::string filter = m_ui->m_filterTableWidget->item(i, 1)->text().toUtf8().data();
1130  int nIt = m_ui->m_filterTableWidget->item(i, 2)->text().toUtf8().toInt();
1131 
1132  if (te::common::Convert2LCase(filter) == "opening")
1133  {
1134  vecFilter.push_back(te::rp::Filter::InputParameters::FilterType::ErosionFilterT);
1135  vecIt.push_back(nIt);
1136 
1137  vecFilter.push_back(te::rp::Filter::InputParameters::FilterType::DilationFilterT);
1138  vecIt.push_back(nIt);
1139  }
1140  else if (te::common::Convert2LCase(filter) == "closing")
1141  {
1142  vecFilter.push_back(te::rp::Filter::InputParameters::FilterType::DilationFilterT);
1143  vecIt.push_back(nIt);
1144 
1145  vecFilter.push_back(te::rp::Filter::InputParameters::FilterType::ErosionFilterT);
1146  vecIt.push_back(nIt);
1147  }
1148  }
1149 
1150  std::unique_ptr<te::rp::CloudDetection> cloudDetection(new te::rp::CloudDetection());
1151 
1152  try
1153  {
1154  //run cloud detection operation
1155  te::rst::Raster* raster = cloudDetection->executeCloudDetection(m_cloudRasterPreview.get(), m_shadowRasterPreview.get(), cloudBand, shadowBand,
1156  minCloud, maxCloud, minShadow, maxShadow, vecFilter, vecIt);
1157 
1158  //output parameters
1159  std::vector<te::gm::Geometry*> geomVec;
1160  std::vector< double > geomsValues;
1161 
1162  //vectorize
1163  if (!vectorize(raster, geomVec, geomsValues))
1164  {
1165  QApplication::restoreOverrideCursor();
1166  return;
1167  }
1168 
1169  delete raster;
1170 
1171  if (m_ui->m_previewCheckBox->isChecked())
1172  {
1173  //draw geometries
1174 
1175  const te::gm::Envelope& env = m_mapDisplay->getExtent();
1176 
1177  te::qt::widgets::Canvas* canvasInstance = new Canvas(m_mapDisplay->width(), m_mapDisplay->height());
1178  canvasInstance->setDevice(m_mapDisplay->getDraftPixmap(), false);
1179  canvasInstance->setWindow(env.m_llx, env.m_lly, env.m_urx, env.m_ury);
1180 
1181  canvasInstance->setPolygonContourWidth(1);
1182  canvasInstance->setPolygonContourColor(te::color::RGBAColor(217, 17, 27, TE_OPAQUE));
1183 
1184  te::map::CanvasConfigurer cc(canvasInstance);
1185 
1186  if(m_polygonSymbolizerWidget.get())
1187  {
1188  m_symbolizer = m_polygonSymbolizerWidget->getSymbolizer();
1189 
1190  cc.config(m_symbolizer);
1191  }
1192  else if(m_symbolizer != 0)
1193  {
1194  cc.config(m_symbolizer);
1195  }
1196 
1197  for(std::size_t i = 0; i < geomVec.size(); ++i)
1198  {
1199  if(geomVec[i]->getSRID() != m_mapDisplay->getSRID())
1200  geomVec[i]->transform(m_mapDisplay->getSRID());
1201 
1202  canvasInstance->draw(geomVec[i]);
1203  }
1204 
1205  m_mapDisplay->repaint();
1206 
1207  delete canvasInstance;
1208 
1209  drawGeom();
1210 
1211  }
1212  }
1213  catch (te::common::Exception& e)
1214  {
1215  QApplication::restoreOverrideCursor();
1216  QMessageBox::warning(this, tr("Cloud Detection"), e.what());
1217  return;
1218  }
1219 
1220  QApplication::restoreOverrideCursor();
1221 }
1222 
1224 {
1225  if(!m_geom.get() || m_geom->isValid())
1226  return;
1227 
1228  const te::gm::Envelope& env = m_mapDisplay->getExtent();
1229 
1230  te::qt::widgets::Canvas* canvasInstance = new Canvas(m_mapDisplay->width(), m_mapDisplay->height());
1231  canvasInstance->setDevice(m_mapDisplay->getDraftPixmap(), false);
1232  canvasInstance->setWindow(env.m_llx, env.m_lly, env.m_urx, env.m_ury);
1233 
1234  canvasInstance->setPolygonContourWidth(1);
1235  canvasInstance->setPolygonContourColor(te::color::RGBAColor(100, 177, 216, TE_OPAQUE));
1236 
1237  canvasInstance->draw(m_geom.get());
1238 
1239  m_mapDisplay->repaint();
1240 
1241  delete canvasInstance;
1242 }
1243 
1245 {
1246  if (m_geom->getGeomTypeId() == te::gm::PolygonType)
1247  {
1248  QApplication::setOverrideCursor(Qt::WaitCursor);
1249 
1250  te::gm::Envelope* env = new te::gm::Envelope(*m_geom->getMBR());
1251 
1252  //get cloud raster from ROI
1253  // verify if is necessary convert the raster to the given srid
1254  bool needRemap = false;
1255  if ((m_mapDisplay->getSRID() != TE_UNKNOWN_SRS) && (m_cloudLayer->getSRID() != TE_UNKNOWN_SRS) && (m_mapDisplay->getSRID() != m_cloudLayer->getSRID()))
1256  needRemap = true;
1257 
1258  // create a SRS converter
1259  std::unique_ptr<te::srs::Converter> converter(new te::srs::Converter());
1260 
1261  if (needRemap)
1262  {
1263  converter->setSourceSRID(m_mapDisplay->getSRID());
1264  converter->setTargetSRID(m_cloudLayer->getSRID());
1265 
1266  converter->convert(env->getLowerLeftX(), env->getLowerLeftY(), env->m_llx, env->m_lly);
1267  converter->convert(env->getUpperRightX(), env->getUpperRightY(), env->m_urx, env->m_ury);
1268  }
1269 
1270  std::unique_ptr<te::da::DataSetType> dsType = m_cloudLayer->getSchema();
1271 
1272  te::rst::RasterProperty* rasterProp = te::da::GetFirstRasterProperty(dsType.get());
1273  std::unique_ptr<te::da::DataSet> dsRaster = m_cloudLayer->getData();
1274 
1275  std::unique_ptr<te::rst::Raster> raster = dsRaster->getRaster(rasterProp->getName());
1276 
1277  std::map<std::string, std::string> infoCloud;
1278  infoCloud["FORCE_MEM_DRIVER"] = "TRUE";
1279  //execute clipping
1280  m_cloudRasterPreview.reset(raster->trim(env, infoCloud));
1281 
1282  //get shadow raster from ROI
1283  // verify if is necessary convert the raster to the given srid
1284  needRemap = false;
1285  if ((m_cloudLayer->getSRID() != TE_UNKNOWN_SRS) && (m_shadowLayer->getSRID() != TE_UNKNOWN_SRS) && (m_cloudLayer->getSRID() != m_shadowLayer->getSRID()))
1286  needRemap = true;
1287 
1288  if (needRemap)
1289  {
1290  converter->setSourceSRID(m_cloudLayer->getSRID());
1291  converter->setTargetSRID(m_shadowLayer->getSRID());
1292 
1293  converter->convert(env->getLowerLeftX(), env->getLowerLeftY(), env->m_llx, env->m_lly);
1294  converter->convert(env->getUpperRightX(), env->getUpperRightY(), env->m_urx, env->m_ury);
1295  }
1296 
1297  dsType = m_shadowLayer->getSchema();
1298  rasterProp = te::da::GetFirstRasterProperty(dsType.get());
1299  dsRaster = m_shadowLayer->getData();
1300 
1301  raster = dsRaster->getRaster(rasterProp->getName());
1302 
1303  std::map<std::string, std::string> infoShadow;
1304  infoShadow["FORCE_MEM_DRIVER"] = "TRUE";
1305  //execute clipping
1306  m_shadowRasterPreview.reset(raster->trim(env, infoShadow));
1307 
1308  if (m_ui->m_previewCheckBox->isChecked())
1309  {
1310  applyPreview();
1311  }
1312 
1313  QApplication::restoreOverrideCursor();
1314  }
1315 }
1316 
1317 std::unique_ptr<te::da::DataSetType> te::qt::widgets::CloudDetectionDialog::createDataSetType(std::string dataSetName, int srid)
1318 {
1319  std::unique_ptr<te::da::DataSetType> dsType(new te::da::DataSetType(dataSetName));
1320 
1321  //create id property
1323  dsType->add(idProperty);
1324 
1325  //create geometry property
1326  te::gm::GeometryProperty* geomProperty = new te::gm::GeometryProperty("geom", srid, te::gm::PolygonType);
1327  dsType->add(geomProperty);
1328 
1329  //create primary key
1330  std::string pkName = "pk_id";
1331  pkName += "_" + dataSetName;
1332  te::da::PrimaryKey* pk = new te::da::PrimaryKey(pkName, dsType.get());
1333  pk->add(idProperty);
1334 
1335  return dsType;
1336 }
1337 
1338 std::unique_ptr<te::mem::DataSet>
1340  te::da::DataSetType* dsType, std::vector<te::gm::Geometry*>& geoms,
1341  std::vector<double>& /*geomsValues*/)
1342 {
1343  std::unique_ptr<te::mem::DataSet> ds(new te::mem::DataSet(dsType));
1344 
1345  for (std::size_t t = 0; t < geoms.size(); ++t)
1346  {
1347  //create dataset item
1348  te::mem::DataSetItem* item = new te::mem::DataSetItem(ds.get());
1349 
1350  //set id
1351  item->setInt32(0, (int)t);
1352 
1353  //set geometry
1354  item->setGeometry(1, geoms[t]);
1355 
1356  ds->add(item);
1357  }
1358 
1359  return ds;
1360 }
1361 
1363 {
1364  //save dataset
1365  dataSet->moveBeforeFirst();
1366 
1367  std::map<std::string, std::string> options;
1368 
1369  ds->createDataSet(dsType, options);
1370 
1371  ds->add(dataSetName, dataSet, options);
1372 }
1373 
1375 {
1377 
1378  canvasInstance.clear();
1379 
1380  m_mapDisplay->repaint();
1381 }
1382 
1384 {
1385  clearCanvas();
1386 
1387  emit closeTool();
1388 }
TEDATAACCESSEXPORT DataSourcePtr GetDataSource(const std::string &datasourceId, const bool opened=true)
Search for a data source with the informed id in the DataSourceManager.
TEDATAACCESSEXPORT te::rst::RasterProperty * GetFirstRasterProperty(const DataSetType *dt)
void clear()
It clears the canvas content and fills with the background color.
unsigned int band
virtual void vectorize(std::vector< te::gm::Geometry * > &g, std::size_t b, unsigned int mp=0, std::vector< double > *const polygonsValues=0)
Vectorizes a given raster band, using GDALPolygonize function.
void saveDataSet(te::mem::DataSet *dataSet, te::da::DataSetType *dsType, te::da::DataSourcePtr ds, std::string dataSetName)
Geometric property.
void add(te::dt::Property *p)
It adds a property to the list of properties of the primary key.
Definition: PrimaryKey.h:123
Defines a component for choose a file.
Definition: FileDialog.h:52
void setGeometry(std::size_t i, te::gm::Geometry *value)
It sets the value of the i-th property.
void setDevice(QPaintDevice *device, bool takeOwnerShip)
It sets new device as QPrinter.
bool intersects(const Envelope &rhs) const
It returns true if the envelopes "spatially intersects".
boost::shared_ptr< DataSetType > DataSetTypePtr
Definition: DataSetType.h:653
An atomic property like an integer or double.
A PolygonSymbolizer is used to draw a polygon (or other area-type geometries), including filling its ...
std::list< te::map::AbstractLayerPtr > getSelecteds() const
boost::shared_ptr< DataSource > DataSourcePtr
std::string Convert2LCase(const std::string &value)
It converts a string to lower case.
Definition: StringUtils.h:202
#define TE_UNKNOWN_SRS
A numeric value to represent a unknown SRS identification in TerraLib.
std::unique_ptr< te::mem::DataSet > createDataSet(te::da::DataSetType *dsType, std::vector< te::gm::Geometry * > &geoms, std::vector< double > &geomsValues)
A class that models the description of a dataset.
Definition: DataSetType.h:72
te::qt::widgets::MapDisplay * m_mapDisplay
bool vectorize(te::rst::Raster *raster, std::vector< te::gm::Geometry * > &geomVec, std::vector< double > &geomsValues)
std::unique_ptr< te::gm::Geometry > m_geom
virtual const char * what() const
It outputs the exception message.
const double & getUpperRightX() const
It returns a constant refernce to the x coordinate of the upper right corner.
const std::string & getVersion() const
Definition: Symbolizer.cpp:104
static te::xml::AbstractWriter * make()
It creates a new XML writer using the dafault implementation.
double m_urx
Upper right corner x-coordinate.
#define TE_OPAQUE
For an RGBA color this is the value of the alpha-channel for totally opaque.
const double & getLowerLeftY() const
It returns a constant refernce to the y coordinate of the lower left corner.
std::unique_ptr< te::qt::widgets::RpToolsWidget > m_navigator
void setPolygonContourColor(const te::color::RGBAColor &color)
It sets the pen color used to draw the boundary of polygon geometries.
A widget to control the display of a set of layers.
This class is a dialog for the LayerSearchWidget.
static te::dt::Date ds(2010, 01, 01)
static te::xml::Reader * make()
It creates a new XML reader using the dafault implementation.
const double & getUpperRightY() const
It returns a constant refernce to the x coordinate of the upper right corner.
Q_DECLARE_METATYPE(te::map::AbstractLayerPtr) te
void addLayer(te::map::AbstractLayerPtr layer)
void draw(const te::gm::Geometry *geom)
It draws the geometry on canvas.
Raster property.
std::unique_ptr< te::qt::widgets::PolygonSymbolizerWidget > m_polygonSymbolizerWidget
void setInt32(std::size_t i, boost::int32_t value)
It sets the value of the i-th property.
int b
Definition: TsRtree.cpp:32
This class is used to define a component for viewing overlaid layers.
Implementation of a random-access dataset class for the TerraLib In-Memory Data Access driver...
void setWindow(const double &llx, const double &lly, const double &urx, const double &ury)
It sets the world (or window) coordinates area (supposing a cartesian reference system).
double m_llx
Lower left corner x-coordinate.
std::unique_ptr< te::rst::Raster > m_shadowRaster
static RasterSummaryManager & getInstance()
It returns a reference to the singleton instance.
An Envelope defines a 2D rectangular region.
An abstract class for raster data strucutures.
std::list< te::map::AbstractLayerPtr > m_layers
void exec()
This method will open the dialog of file selection and populate the class members with the chosen fil...
Definition: FileDialog.cpp:54
virtual int getSRID() const
It return the Spatial Reference System used by the Map Display.
URI C++ Library.
Definition: Attributes.h:37
This class provide cloud detection.
static te::dt::TimeDuration dt(20, 30, 50, 11)
void setPolygonContourWidth(int w)
It sets the polygon contour width.
virtual const te::gm::Envelope & getExtent() const
It returns the world extent showned by the MapDisplay.
void setActionGroup(QActionGroup *actionGroup)
boost::ptr_vector< BandSummary > RasterSummary
RasterSummary is just a typedef of a boost::ptr_vector.
Definition: RasterSummary.h:44
std::unique_ptr< te::rst::Raster > m_cloudRasterPreview
This class is designed to declare objects to be thrown as exceptions by TerraLib. ...
A widget used to build a polygon symbolizer element.
double m_lly
Lower left corner y-coordinate.
bool moveBeforeFirst()
It moves the internal pointer to a position before the first item in the collection.
A Converter is responsible for the conversion of coordinates between different Coordinate Systems (CS...
Definition: Converter.h:53
void setLayers(std::list< te::map::AbstractLayerPtr > layers)
An implementation of the DatasetItem class for the TerraLib In-Memory Data Access driver...
TEMAPEXPORT te::rst::Raster * GetRaster(AbstractLayer *layer)
It gets the raster referenced by the given data set layer.
std::string getPath()
This method will return the chosen path.
Definition: FileDialog.cpp:103
int getSRID() const
Returns the raster spatial reference system identifier.
const std::list< te::da::DataSourceInfoPtr > & getSelecteds() const
virtual QPixmap * getDraftPixmap() const
It returns the map display draft pixmap.
double m_ury
Upper right corner y-coordinate.
It describes a primary key (pk) constraint.
Definition: PrimaryKey.h:52
void setMapDisplay(te::qt::widgets::MapDisplay *mapDisplay)
const double & getLowerLeftX() const
It returns a constant reference to the x coordinate of the lower left corner.
A helper class for 32-bit RGBA (Red-Green-Blue-Alpha channel) color.
Definition: RGBAColor.h:57
This class is used to navigate over a DataSetLayer (having a raster representation) and given a set o...
Definition: RpToolsWidget.h:70
void setList(std::list< te::map::AbstractLayerPtr > &layerList)
A dialog for selecting a data source.
std::unique_ptr< te::rst::Raster > m_shadowRasterPreview
A class that represents a data source component.
std::string getFileName()
This method will return the file name.
Definition: FileDialog.cpp:113
void onFilterCellDoubleClicked(int row, int column)
std::string Convert2String(boost::int16_t value)
It converts a short integer value to a string.
Definition: StringUtils.h:56
void config(const te::se::Symbolizer *symbolizer)
It configs the canvas based on given symbolizer.
Calculate the min value.
std::unique_ptr< Ui::CloudDetectionDialogForm > m_ui
Calculate the max value.
boost::intrusive_ptr< AbstractLayer > AbstractLayerPtr
std::unique_ptr< te::rst::Raster > m_cloudRaster
std::unique_ptr< te::qt::widgets::RasterHistogramWidget > m_histogramWidget
std::unique_ptr< te::da::DataSetType > createDataSetType(std::string dataSetName, int srid)
bool isValid() const
It tells if the rectangle is valid or not.
file(WRITE ${CMAKE_BINARY_DIR}/config_qhelp.cmake"configure_file (${TERRALIB_ABSOLUTE_ROOT_DIR}/doc/qhelp/help.qhcp.in ${CMAKE_BINARY_DIR}/share/terraview/help/help.qhcp @ONLY)") add_custom_command(OUTPUT del_dir COMMAND $
TEGEOMEXPORT Geometry * GetGeomFromEnvelope(const Envelope *const e, int srid)
It creates a Geometry (a polygon) from the given envelope.
boost::shared_ptr< DataSourceInfo > DataSourceInfoPtr
const std::string & getName() const
It returns the property name.
Definition: Property.h:127
A Symbology Enconding visitor that configures a given canvas based on symbolizers elements...
void onEnvelopeAcquired(te::gm::Envelope env)