ROIManagerWidget.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/classification/ROIManagerWidget.cpp
22 
23  \brief This file has the ROIManagerWidget class.
24 */
25 
26 // TerraLib
27 #include "../../../classification/ROI.h"
28 #include "../../../classification/ROISet.h"
29 #include "../../../dataaccess/utils/Utils.h"
30 #include "../../../geometry/Coord2D.h"
31 #include "../../../geometry/Geometry.h"
32 #include "../../../geometry/GeometryProperty.h"
33 #include "../../../geometry/MultiPolygon.h"
34 #include "../../../geometry/Point.h"
35 #include "../../../geometry/Utils.h"
36 #include "../../../dataaccess/dataset/DataSetType.h"
37 #include "../../../dataaccess/dataset/DataSetAdapter.h"
38 #include "../../../dataaccess/dataset/DataSetTypeConverter.h"
39 #include "../../../dataaccess/datasource/DataSourceFactory.h"
40 #include "../../../se/PolygonSymbolizer.h"
41 #include "../../../se/Fill.h"
42 #include "../../../se/Rule.h"
43 #include "../../../se/Style.h"
44 #include "../../../se/Symbolizer.h"
45 #include "../../../se/Utils.h"
46 #include "../../widgets/Utils.h"
47 #include "../canvas/Canvas.h"
48 #include "../canvas/MapDisplay.h"
49 #include "../rp/RpToolsWidget.h"
50 #include "../utils/ColorPickerToolButton.h"
51 #include "ROIManagerWidget.h"
52 #include "ui_ROIManagerWidgetForm.h"
53 
54 // Qt
55 #include <QFileDialog>
56 #include <QGridLayout>
57 #include <QMessageBox>
58 #include <QPointF>
59 
60 //STL
61 #include <memory>
62 
63 // Boost
64 #include <boost/uuid/random_generator.hpp>
65 #include <boost/filesystem.hpp>
66 #include <boost/uuid/uuid_io.hpp>
67 
69 
70 #define ROI_TREE_ITEM 0
71 #define ROI_POLYGON_TREE_ITEM 1
72 
74  : QWidget(parent, f),
75  m_ui(new Ui::ROIManagerWidgetForm),
76  m_mapDisplay(nullptr),
77  m_rs(nullptr),
78  m_sampleCounter(0)
79 {
80  m_ui->setupUi(this);
81 
82  m_ui->m_openLayerROIToolButton->setIcon(QIcon::fromTheme("folder-open"));
83  m_ui->m_fileDialogToolButton->setIcon(QIcon::fromTheme("folder-open"));
84  m_ui->m_removeROIToolButton->setIcon(QIcon::fromTheme("edit-deletetool"));
85  m_ui->m_exportROISetToolButton->setIcon(QIcon::fromTheme("document-export"));
86  m_ui->m_addROIToolButton->setIcon(QIcon::fromTheme("list-add"));
87 
88  // Color Picker
89  m_colorPicker = new te::qt::widgets::ColorPickerToolButton(this);
90  m_colorPicker->setFixedSize(70, 24);
91  m_colorPicker->setColor(QColor(255, 255, 0, 128));
92 
93  //build form
94  QGridLayout* colorPickerLayout = new QGridLayout(m_ui->m_colorWidget);
95  colorPickerLayout->setContentsMargins(0, 0, 0, 0);
96  colorPickerLayout->addWidget(m_colorPicker);
97 
98  QGridLayout* layout = new QGridLayout(m_ui->m_navigatorWidget);
99  m_navigator.reset(new te::qt::widgets::RpToolsWidget(m_ui->m_navigatorWidget));
100  layout->addWidget(m_navigator.get(), 0, 0);
101  layout->setContentsMargins(0,0,0,0);
102  layout->setSizeConstraint(QLayout::SetMinimumSize);
103 
104  //connects
105  connect(m_ui->m_openLayerROIToolButton, SIGNAL(clicked()), this, SLOT(onOpenLayerROIToolButtonClicked()));
106  connect(m_ui->m_addROIToolButton, SIGNAL(clicked()), this, SLOT(onAddROIToolButtonClicked()));
107  connect(m_ui->m_removeROIToolButton, SIGNAL(clicked()), this, SLOT(onRemoveROIToolButtonClicked()));
108  connect(m_ui->m_fileDialogToolButton, SIGNAL(clicked()), this, SLOT(onFileDialogToolButtonClicked()));
109  connect(m_ui->m_exportROISetToolButton, SIGNAL(clicked()), this, SLOT(onExportROISetToolButtonClicked()));
110  connect(m_ui->m_roiSetTreeWidget, SIGNAL(itemClicked(QTreeWidgetItem*, int)), this, SLOT(onROITreItemClicked(QTreeWidgetItem*, int)));
111  connect(m_ui->m_layerROIComboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(onLayerComboBoxChanged(int)));
112  connect(m_ui->m_layerROIComboBox, SIGNAL(activated(int)), this, SLOT(onLayerComboBoxChanged(int)));
113 
114  connect(m_navigator.get(), SIGNAL(envelopeAcquired(te::gm::Envelope)), this, SLOT(onEnvelopeAcquired(te::gm::Envelope)));
115  connect(m_navigator.get(), SIGNAL(geomAquired(te::gm::Polygon*)), this, SLOT(onGeomAquired(te::gm::Polygon*)));
116 }
117 
119 {
120  if(m_vectorLayer.get())
121  {
122  m_vectorLayer->setVisibility(m_vectorLayerVisibility);
123 
124  te::se::Style* s = m_vectorLayer->getStyle();
125  te::se::Rule* r = s->getRule(0);
126 
127  r->setSymbolizer(0, m_symb);
128  }
129 }
130 
131 Ui::ROIManagerWidgetForm* te::qt::widgets::ROIManagerWidget::getForm() const
132 {
133  return m_ui.get();
134 }
135 
137 {
138  m_navigator->setMapDisplay(mapDisplay);
139  m_mapDisplay = mapDisplay;
140 }
141 
143 {
144  //configure tools
145  m_navigator->setActionGroup(actionGroup);
146  m_navigator->enableGeomAction();
147  m_navigator->enableBoxAction();
148 }
149 
150 void te::qt::widgets::ROIManagerWidget::setList(std::list<te::map::AbstractLayerPtr>& layerList)
151 {
152  m_ui->m_layerROIComboBox->clear();
153 
154  std::list<te::map::AbstractLayerPtr>::iterator it = layerList.begin();
155 
156  while(it != layerList.end())
157  {
159 
160  std::unique_ptr<te::da::DataSetType> dsType = l->getSchema();
161 
162  if(dsType->hasGeom())
163  {
164  if(dsType->getProperties().size() == 5 &&
165  dsType->getProperty(1)->getName() == TE_CL_ROI_GEOM_ID_NAME &&
166  dsType->getProperty(2)->getName() == TE_CL_ROI_LABEL_NAME &&
167  dsType->getProperty(3)->getName() == TE_CL_ROI_COLOR_NAME)
168  {
169  m_ui->m_layerROIComboBox->addItem(it->get()->getTitle().c_str(), QVariant::fromValue(l));
170  }
171  }
172 
173  ++it;
174  }
175 }
176 
178 {
179  m_layer = layer;
180 }
181 
183 {
184  return m_rs;
185 }
186 
188 {
189  if(!m_rs)
190  return;
191 
192  m_mapDisplay->getDraftPixmap()->fill(Qt::transparent);
193 
194  const te::gm::Envelope& mapExt = m_mapDisplay->getExtent();
195 
197  canvasInstance.setWindow(mapExt.m_llx, mapExt.m_lly, mapExt.m_urx, mapExt.m_ury);
198 
199  std::map<std::string, te::cl::ROI*> roiMap = m_rs->getROISet();
200  std::map<std::string, te::cl::ROI*>::iterator it = roiMap.begin();
201 
202  while(it != roiMap.end())
203  {
204  te::cl::ROI* roi = it->second;
205 
206  std::map<std::string, te::gm::Polygon*> polyMap = roi->getPolygons();
207  std::map<std::string, te::gm::Polygon*>::iterator itPoly = polyMap.begin();
208 
209  te::color::RGBAColor rgba(roi->getColor());
210 
211  canvasInstance.setPolygonContourWidth(2);
212  canvasInstance.setPolygonContourColor(rgba);
213  canvasInstance.setPolygonFillColor(te::color::RGBAColor(rgba.getRed(), rgba.getGreen(), rgba.getBlue(), 80));
214 
215  while(itPoly != polyMap.end())
216  {
217  te::gm::Polygon* poly = itPoly->second;
218 
219  if(poly->getSRID() != m_mapDisplay->getSRID())
220  poly->transform(m_mapDisplay->getSRID());
221 
222  canvasInstance.draw(poly);
223 
224  ++itPoly;
225  }
226  ++it;
227  }
228 
229  //draw selected
230  if(!m_ui->m_roiSetTreeWidget->selectedItems().isEmpty())
231  {
232  QTreeWidgetItem* item = m_ui->m_roiSetTreeWidget->selectedItems()[0];
233 
234  if(item->type() == ROI_POLYGON_TREE_ITEM)
235  {
236  std::string id = item->data(0, Qt::UserRole).toString().toUtf8().data();
237 
238  QTreeWidgetItem* parent = item->parent();
239 
240  std::string label = parent->text(0).toUtf8().data();
241 
242  te::cl::ROI* roi = m_rs->getROI(label);
243 
244  te::color::RGBAColor rgba(roi->getColor());
245 
246  te::gm::Polygon* p = roi->getPolygons()[id];
247 
248  canvasInstance.setPolygonContourWidth(1);
249  canvasInstance.setPolygonContourColor(rgba);
250  canvasInstance.setPolygonFillColor(rgba);
251 
252  if(p->getSRID() != m_mapDisplay->getSRID())
253  p->transform(m_mapDisplay->getSRID());
254 
255  canvasInstance.draw(p);
256  }
257  }
258 
259  m_mapDisplay->repaint();
260 }
261 
263 {
264  QString inputFile = QFileDialog::getOpenFileName(this, tr("Select a ROI file"), te::qt::widgets::GetFilePathFromSettings("roifile"),
265  "Shape Files (*.shp *.SHP)");
266 
267  if(inputFile.isEmpty())
268  return;
269 
270  boost::filesystem::path uri(inputFile.toUtf8().data());
271 
272  QFileInfo inf(inputFile);
273 
274  te::qt::widgets::AddFilePathToSettings(inf.absolutePath(), "roifile");
275 
276  std::string fileName = inf.baseName().toUtf8().data();
277 
278  std::string dsInf("file://" + uri.string());
279 
280  te::da::DataSourcePtr dsPtr(te::da::DataSourceFactory::make("OGR", dsInf).release());
281 
282  dsPtr->open();
283 
284  std::unique_ptr<te::da::DataSetType> dsType = dsPtr->getDataSetType(fileName);
285 
286  if(dsType->hasGeom())
287  {
288  if(!(dsType->getProperties().size() == 5 &&
289  dsType->getProperty(1)->getName() == TE_CL_ROI_GEOM_ID_NAME &&
290  dsType->getProperty(2)->getName() == TE_CL_ROI_LABEL_NAME &&
291  dsType->getProperty(3)->getName() == TE_CL_ROI_COLOR_NAME))
292  {
293  QMessageBox::warning(this, tr("Classifier"), tr("The layer informed does not have ROI properties."));
294  return;
295  }
296  }
297  else
298  {
299  QMessageBox::warning(this, tr("Classifier"), tr("The layer informed does not have geometries."));
300  return;
301  }
302 
303  std::unique_ptr<te::da::DataSet> ds = dsPtr->getDataSet(fileName);
304 
305  if(te::da::GetFirstGeomProperty(dsType.get())->getSRID() != m_layer->getSRID())
306  {
307  std::unique_ptr<te::da::DataSetTypeConverter> converter(
308  new te::da::DataSetTypeConverter(dsType.get(),
309  dsPtr->getCapabilities(),
310  dsPtr->getEncoding()));
311 
312  te::da::AssociateDataSetTypeConverterSRID(converter.get(), m_layer->getSRID());
313 
314  std::unique_ptr<te::da::DataSet> dsLayer = dsPtr->getDataSet(fileName);
315 
316  te::da::DataSetAdapter* dsAdapter = te::da::CreateAdapter(dsLayer.release(), converter.get());
317 
318  ds.reset(dsAdapter);
319  }
320 
321  te::cl::ROISet* importedROISet = nullptr;
322 
323  try
324  {
325  importedROISet = te::cl::ROISet::createROISet(std::move(ds));
326  }
327  catch(...)
328  {
329  QMessageBox::warning(this, tr("Warning"), tr("Error extracting ROISet Information. Invalid layer."));
330  return;
331  }
332 
333  std::map<std::string, te::cl::ROI*> roiMap = importedROISet->getROISet();
334  std::map<std::string, te::cl::ROI*>::iterator it = roiMap.begin();
335 
336  if(!checkGeomIntersection(importedROISet))
337  {
338  QMessageBox::warning(this, tr("Warning"), tr("The samples imported does not intersects the raster extent."));
339  return;
340  }
341 
342  m_ui->m_layerROIComboBox->clear();
343 
344  m_ui->m_layerROIComboBox->addItem(inf.baseName());
345 
346  m_ui->m_roiSetTreeWidget->clear();
347 
348  m_sampleCounter = 0;
349 
350  while(it != roiMap.end())
351  {
352  te::cl::ROI* roi = it->second;
353 
354  std::map<std::string, te::gm::Polygon*> polyMap = roi->getPolygons();
355  std::map<std::string, te::gm::Polygon*>::iterator itPoly = polyMap.begin();
356 
357  //update roi set tree
358  QPixmap pix(16,16);
359  pix.fill(QColor(roi->getColor().c_str()).rgba());
360  QIcon icon(pix);
361 
362  QTreeWidgetItem* item = new QTreeWidgetItem(m_ui->m_roiSetTreeWidget, ROI_TREE_ITEM);
363  item->setText(0, roi->getLabel().c_str());
364  item->setIcon(0, icon);
365 
366  m_ui->m_roiSetTreeWidget->addTopLevelItem(item);
367 
368  while(itPoly != polyMap.end())
369  {
370  //update tree
371  ++m_sampleCounter;
372 
373  QString sampleCounter;
374  sampleCounter.setNum(m_sampleCounter);
375  QString sampleName(tr("Sample"));
376  QString fullName;
377  fullName.append(sampleName);
378  fullName.append(" - ");
379  fullName.append(sampleCounter);
380 
382  subItem->setText(0, fullName);
383  subItem->setData(0, Qt::UserRole, QVariant(itPoly->first.c_str()));
384  subItem->setIcon(0, QIcon::fromTheme("file-vector"));
385  item->addChild(subItem);
386  item->setExpanded(true);
387 
388  ++itPoly;
389  }
390  ++it;
391  }
392 
393  if(m_rs)
394  delete m_rs;
395 
396  m_rs = importedROISet;
397 
398  drawROISet();
399 }
400 
402 {
403  if(m_ui->m_labelROILineEdit->text().isEmpty())
404  {
405  QMessageBox::warning(this, tr("Warning"), tr("ROI Label is empty."));
406  return;
407  }
408 
409  //get roi info
410  std::string label = m_ui->m_labelROILineEdit->text().toUtf8().data();
411  std::string color = m_colorPicker->getColor().name().toUtf8().data();
412 
413  //create roi
414  te::cl::ROI* roi = new te::cl::ROI(label);
415  roi->setColor(color);
416 
417  //check if roi set exist
418  if(!m_rs)
419  {
420  m_rs = new te::cl::ROISet();
421  }
422 
423  std::map<std::string, te::cl::ROI*>::iterator it = m_rs->getROISet().find(label);
424 
425  if(it != m_rs->getROISet().end())
426  {
427  QMessageBox::warning(this, tr("Warning"), tr("Duplicated label is not allowed."));
428  return;
429  }
430 
431  //add roi into roi set
432  m_rs->addROI(roi);
433 
434  //update roi set tree
435  QPixmap pix(16,16);
436  pix.fill(m_colorPicker->getColor());
437  QIcon icon(pix);
438 
439  QTreeWidgetItem* item = new QTreeWidgetItem(m_ui->m_roiSetTreeWidget, ROI_TREE_ITEM);
440  item->setText(0, roi->getLabel().c_str());
441  item->setIcon(0, icon);
442 
443  m_ui->m_roiSetTreeWidget->addTopLevelItem(item);
444 
445  m_ui->m_labelROILineEdit->clear();
446 }
447 
449 {
450  if (m_ui->m_roiSetTreeWidget->selectedItems().empty())
451  {
452  QMessageBox::warning(this, tr("Warning"), tr("Select a item first."));
453  return;
454  }
455 
456  QTreeWidgetItem* item = m_ui->m_roiSetTreeWidget->selectedItems()[0];
457 
458  if (item->type() == ROI_TREE_ITEM)
459  {
460  std::string label = item->text(0).toUtf8().data();
461  m_rs->removeROI(label);
462 
463  delete item;
464  }
465  else if (item->type() == ROI_POLYGON_TREE_ITEM)
466  {
467  std::string id = item->data(0, Qt::UserRole).toString().toUtf8().data();
468 
469  QTreeWidgetItem* parent = item->parent();
470 
471  std::string label = parent->text(0).toUtf8().data();
472 
473  te::cl::ROI* roi = m_rs->getROI(label);
474 
475  roi->removePolygon(id);
476 
477  parent->removeChild(item);
478  }
479 
480  if (m_rs && m_rs->getROISet().empty())
481  {
482  m_sampleCounter = 0;
483  }
484 
485  drawROISet();
486 }
487 
489 {
490  QString fileName = QFileDialog::getSaveFileName(this, tr("Save ROI Set to File"), te::qt::widgets::GetFilePathFromSettings("roifile"), tr("Shape Files (*.shp *.SHP)"));
491 
492  if (fileName.isEmpty())
493  return;
494 
495  QFileInfo file(fileName);
496 
497  te::qt::widgets::AddFilePathToSettings(file.absolutePath(), "roifile");
498 
499  if(file.suffix().isEmpty())
500  fileName.append(".shp");
501 
502  m_ui->m_roiSetNameLineEdit->setText(fileName);
503 }
504 
506 {
507  drawROISet();
508 
509  if(!item || item->type() != ROI_POLYGON_TREE_ITEM)
510  return;
511 
512  const te::gm::Envelope& mapExt = m_mapDisplay->getExtent();
513 
515  canvasInstance.setWindow(mapExt.m_llx, mapExt.m_lly, mapExt.m_urx, mapExt.m_ury);
516 
517  std::string id = item->data(0, Qt::UserRole).toString().toUtf8().data();
518 
519  QTreeWidgetItem* parent = item->parent();
520 
521  std::string label = parent->text(0).toUtf8().data();
522 
523  te::cl::ROI* roi = m_rs->getROI(label);
524 
525  te::color::RGBAColor rgba(roi->getColor());
526 
527  te::gm::Polygon* p = roi->getPolygons()[id];
528 
529  canvasInstance.setPolygonContourWidth(1);
530  canvasInstance.setPolygonContourColor(rgba);
531  canvasInstance.setPolygonFillColor(rgba);
532 
533  canvasInstance.draw(p);
534 
535  m_mapDisplay->repaint();
536 }
537 
539 {
540  QVariant varLayer = m_ui->m_layerROIComboBox->itemData(index, Qt::UserRole);
541  te::map::AbstractLayerPtr layer = varLayer.value<te::map::AbstractLayerPtr>();
542 
543  if(!layer.get() || !m_layer)
544  return;
545 
546  std::unique_ptr<te::da::DataSet> ds = layer->getData();
547 
548  te::da::DataSourcePtr dsPtr = te::da::GetDataSource(layer->getDataSourceId());
549 
550  std::unique_ptr<te::da::DataSetType> dsType = dsPtr->getDataSetType(layer->getTitle());
551 
552  if(te::da::GetFirstGeomProperty(dsType.get())->getSRID() != m_layer->getSRID())
553  {
554  std::unique_ptr<te::da::DataSetTypeConverter> converter(
555  new te::da::DataSetTypeConverter(dsType.get(),
556  dsPtr->getCapabilities(),
557  dsPtr->getEncoding()));
558 
559  te::da::AssociateDataSetTypeConverterSRID(converter.get(), m_layer->getSRID());
560 
561  std::unique_ptr<te::da::DataSet> dsLayer = dsPtr->getDataSet(layer->getTitle());
562 
563  te::da::DataSetAdapter* dsAdapter = te::da::CreateAdapter(dsLayer.release(), converter.get());
564 
565  ds.reset(dsAdapter);
566  }
567 
568  te::cl::ROISet* importedROISet = nullptr;
569 
570  try
571  {
572  importedROISet = te::cl::ROISet::createROISet(std::move(ds));
573  }
574  catch(...)
575  {
576  QMessageBox::warning(this, tr("Warning"), tr("Error extracting ROISet Information. Invalid layer."));
577  return;
578  }
579 
580  std::map<std::string, te::cl::ROI*> roiMap = importedROISet->getROISet();
581  std::map<std::string, te::cl::ROI*>::iterator it = roiMap.begin();
582 
583  if(!checkGeomIntersection(importedROISet))
584  {
585  QMessageBox::warning(this, tr("Warning"), tr("The samples imported does not intersects the raster extent."));
586  return;
587  }
588 
589  m_ui->m_roiSetTreeWidget->clear();
590 
591  m_sampleCounter = 0;
592 
593  while(it != roiMap.end())
594  {
595  te::cl::ROI* roi = it->second;
596 
597  std::map<std::string, te::gm::Polygon*> polyMap = roi->getPolygons();
598  std::map<std::string, te::gm::Polygon*>::iterator itPoly = polyMap.begin();
599 
600  //update roi set tree
601  QPixmap pix(16,16);
602  pix.fill(QColor(roi->getColor().c_str()).rgba());
603  QIcon icon(pix);
604 
605  QTreeWidgetItem* item = new QTreeWidgetItem(m_ui->m_roiSetTreeWidget, ROI_TREE_ITEM);
606  item->setText(0, roi->getLabel().c_str());
607  item->setIcon(0, icon);
608 
609  m_ui->m_roiSetTreeWidget->addTopLevelItem(item);
610 
611  while(itPoly != polyMap.end())
612  {
613  //update tree
614  ++m_sampleCounter;
615 
616  QString sampleCounter;
617  sampleCounter.setNum(m_sampleCounter);
618  QString sampleName(tr("Sample"));
619  QString fullName;
620  fullName.append(sampleName);
621  fullName.append(" - ");
622  fullName.append(sampleCounter);
623 
625  subItem->setText(0, fullName);
626  subItem->setData(0, Qt::UserRole, QVariant(itPoly->first.c_str()));
627  subItem->setIcon(0, QIcon::fromTheme("file-vector"));
628  item->addChild(subItem);
629  item->setExpanded(true);
630 
631  ++itPoly;
632  }
633  ++it;
634  }
635 
636  if(m_rs)
637  delete m_rs;
638 
639  m_rs = importedROISet;
640 
641  drawROISet();
642 }
643 
645 {
646  if(m_ui->m_roiSetNameLineEdit->text().isEmpty())
647  {
648  QMessageBox::warning(this, tr("Warning"), tr("File name not defined."));
649  return;
650  }
651  std::string fileName = m_ui->m_roiSetNameLineEdit->text().toUtf8().data();
652 
653  if(m_rs->getROISet().empty())
654  {
655  QMessageBox::warning(this, tr("Warning"), tr("ROI Set is empty."));
656  return;
657  }
658 
659  int srid = m_mapDisplay->getSRID();
660 
661  try
662  {
663  m_rs->exportToFile(fileName, srid);
664  }
665  catch(...)
666  {
667  QMessageBox::warning(this, tr("Warning"), tr("Error exporting ROI Set."));
668  return;
669  }
670 
671  QMessageBox::information(this, tr("Classifier"), tr("ROI Set exported successfully."));
672 }
673 
675 {
676  if(flag)
677  {
678  //int idxLayer = m_ui->m_vectorLayerComboBox->currentIndex();
679  //QVariant varLayer = m_ui->m_vectorLayerComboBox->itemData(idxLayer, Qt::UserRole);
680  //te::map::AbstractLayerPtr layer = varLayer.value<te::map::AbstractLayerPtr>();
681 
682  //m_vectorLayer = layer;
683  m_vectorLayerVisibility = m_layer->getVisibility();
684  m_vectorLayer->setVisibility(te::map::VISIBLE);
685 
686  te::se::Style* s = m_vectorLayer->getStyle();
687  te::se::Rule* r = s->getRule(0);
688  const te::se::Symbolizer* symb = r->getSymbolizer(0);
689 
690  m_symb = symb->clone();
691 
692  if(symb->getType() == "PolygonSymbolizer")
693  {
694  te::se::PolygonSymbolizer* ps = static_cast<te::se::PolygonSymbolizer*>((symb)->clone());
695 
696  te::se::Fill* fill = ps->getFill()->clone();
697  fill->setOpacity("0.2");
698 
699  ps->setFill(fill);
700 
701  r->setSymbolizer(0, ps);
702  }
703  }
704 }
705 
707 {
708  drawROISet();
709 }
710 
712 {
713  if(m_mapDisplay->getSRID() != m_layer->getSRID())
714  env.transform(m_mapDisplay->getSRID(), m_layer->getSRID());
715 
716  if (!env.isValid() || !env.intersects(m_layer->getExtent()))
717  return;
718 
719  if (m_ui->m_roiSetTreeWidget->selectedItems().empty())
720  {
721  QMessageBox::warning(this, tr("Warning"), tr("Select a ROI item first."));
722  return;
723  }
724 
725  QTreeWidgetItem* item = m_ui->m_roiSetTreeWidget->selectedItems()[0];
726 
727  if (item->type() != ROI_TREE_ITEM)
728  {
729  QMessageBox::warning(this, tr("Warning"), tr("Select a ROI item first."));
730  }
731 
732  //get roi
733  std::string label = item->text(0).toUtf8().data();
734  te::cl::ROI* roi = m_rs->getROI(label);
735 
736  bool repaint = false;
737 
738  te::gm::Polygon* pol = dynamic_cast<te::gm::Polygon*>(te::gm::GetGeomFromEnvelope(&env, m_layer->getSRID()));
739 
740  if (!pol || !pol->isValid())
741  return;
742 
743  if (roi)
744  {
745  //create a polygon id
746  static boost::uuids::basic_random_generator<boost::mt19937> gen;
747  boost::uuids::uuid u = gen();
748  std::string id = boost::uuids::to_string(u);
749 
750  //add polygon into roi
751  roi->addPolygon(pol, id);
752 
753  //update tree
754  ++m_sampleCounter;
755 
756  QString sampleCounter;
757  sampleCounter.setNum(m_sampleCounter);
758  QString sampleName(tr("Sample"));
759  QString fullName;
760  fullName.append(sampleName);
761  fullName.append(" - ");
762  fullName.append(sampleCounter);
763 
765  subItem->setText(0, fullName);
766  subItem->setData(0, Qt::UserRole, QVariant(id.c_str()));
767  subItem->setIcon(0, QIcon::fromTheme("file-vector"));
768  item->setExpanded(true);
769 
770  int value = item->childCount();
771 
772  if (value == 1)
773  repaint = true;
774 
775  item->addChild(subItem);
776 
777  }
778 
779  if (repaint)
780  m_ui->m_roiSetTreeWidget->repaint();
781 
782  drawROISet();
783 }
784 
786 {
787  m_intersects = false;
788 
789  std::map<std::string, te::cl::ROI*> roiMap = rs->getROISet();
790  std::map<std::string, te::cl::ROI*>::iterator it = roiMap.begin();
791 
792  while(it != roiMap.end())
793  {
794  te::cl::ROI* roi = it->second;
795 
796  std::map<std::string, te::gm::Polygon*> polyMap = roi->getPolygons();
797  std::map<std::string, te::gm::Polygon*>::iterator itPoly = polyMap.begin();
798 
799  while(itPoly != polyMap.end())
800  {
801  if(itPoly->second->intersects(te::gm::GetGeomFromEnvelope(&m_layer->getExtent(),
802  m_layer->getSRID())))
803  m_intersects = true;
804 
805  ++itPoly;
806  }
807  ++it;
808  }
809 
810  return m_intersects;
811 }
812 
814 {
815  if(m_mapDisplay->getSRID() != m_layer->getSRID())
816  poly->transform(m_layer->getSRID());
817 
818  if (!poly->isValid() && !poly->intersects(te::gm::GetGeomFromEnvelope(&m_layer->getExtent(), m_layer->getSRID())))
819  return;
820 
821  if(m_ui->m_roiSetTreeWidget->selectedItems().empty())
822  {
823  QMessageBox::warning(this, tr("Warning"), tr("Select a ROI item first."));
824  return;
825  }
826 
827  QTreeWidgetItem* item = m_ui->m_roiSetTreeWidget->selectedItems()[0];
828 
829  if(item->type() != ROI_TREE_ITEM)
830  {
831  QMessageBox::warning(this, tr("Warning"), tr("Select a ROI item first."));
832  }
833 
834 
835  //get roi
836  std::string label = item->text(0).toUtf8().data();
837  te::cl::ROI* roi = m_rs->getROI(label);
838 
839  bool repaint = false;
840 
841  if(roi)
842  {
843  //create a polygon id
844  static boost::uuids::basic_random_generator<boost::mt19937> gen;
845  boost::uuids::uuid u = gen();
846  std::string id = boost::uuids::to_string(u);
847 
848  //add polygon into roi
849  roi->addPolygon(poly, id);
850 
851  //update tree
852  ++m_sampleCounter;
853 
854  QString sampleCounter;
855  sampleCounter.setNum(m_sampleCounter);
856  QString sampleName(tr("Sample"));
857  QString fullName;
858  fullName.append(sampleName);
859  fullName.append(" - ");
860  fullName.append(sampleCounter);
861 
863  subItem->setText(0, fullName);
864  subItem->setData(0, Qt::UserRole, QVariant(id.c_str()));
865  subItem->setIcon(0, QIcon::fromTheme("file-vector"));
866  item->setExpanded(true);
867 
868  int value = item->childCount();
869  if(value == 1)
870  repaint = true;
871 
872  item->addChild(subItem);
873 
874  }
875 
876  if(repaint)
877  m_ui->m_roiSetTreeWidget->repaint();
878 
879  drawROISet();
880 }
881 
883 {
885 
886  canvasInstance.clear();
887 
888  m_mapDisplay->repaint();
889 }
890 
892 {
893  m_navigator->onDisableToolbar();
894 }
TEDATAACCESSEXPORT DataSourcePtr GetDataSource(const std::string &datasourceId, const bool opened=true)
Search for a data source with the informed id in the DataSourceManager.
void onROITreItemClicked(QTreeWidgetItem *item, int column)
te::cl::ROI * getROI(std::string label)
Gets a ROI from this set.
Definition: ROISet.cpp:54
const Fill * getFill() const
Gets the Fill associates with the PolygonSymbolizer.
#define ROI_POLYGON_TREE_ITEM
void clear()
It clears the canvas content and fills with the background color.
static std::unique_ptr< DataSource > make(const std::string &driver, const te::core::URI &connInfo)
bool intersects(const Envelope &rhs) const
It returns true if the envelopes "spatially intersects".
void setList(std::list< te::map::AbstractLayerPtr > &layerList)
This method is used to set the list of layers.
void transform(int srid)
It converts the coordinate values of the geometry to the new spatial reference system.
The Style defines the styling that is to be applied to a geographic dataset (vector geometries or cov...
Definition: Style.h:65
This file has the ROIManagerWidget class.
A PolygonSymbolizer is used to draw a polygon (or other area-type geometries), including filling its ...
boost::shared_ptr< DataSource > DataSourcePtr
TEDATAACCESSEXPORT void AssociateDataSetTypeConverterSRID(DataSetTypeConverter *converter, const int &inputSRID, const int &outputSRID=TE_UNKNOWN_SRS)
A Symbolizer describes how a feature is to appear on a map.
Definition: Symbolizer.h:80
std::unique_ptr< Ui::ROIManagerWidgetForm > m_ui
TEQTWIDGETSEXPORT void AddFilePathToSettings(const QString &path, const QString &typeFile)
Save last used path in QSettings.
double m_urx
Upper right corner x-coordinate.
void addPolygon(te::gm::Polygon *p, std::string id)
Add a new region into this ROI.
Definition: ROI.cpp:67
A widget to control the display of a set of layers.
static te::dt::Date ds(2010, 01, 01)
#define TE_CL_ROI_GEOM_ID_NAME
This mark defines the geom id attribute name.
virtual bool intersects(const Geometry *const rhs) const _NOEXCEPT_OP(false)
It returns true if the geometry object spatially intersects rhs geometry.
void addROI(te::cl::ROI *roi)
Add a new ROI to this set.
Definition: ROISet.cpp:64
void exportToFile(std::string fileName, int srid)
Export the ROISet to a shapefile.
Definition: ROISet.cpp:82
te::map::AbstractLayerPtr m_layer
void setActionGroup(QActionGroup *actionGroup)
This method is used to set the action group.
A ROISet is a set of ROI&#39;s.
Definition: ROISet.h:53
void onEnvelopeAcquired(te::gm::Envelope env)
An converter for DataSetType.
Rule * getRule(std::size_t i) const
Definition: Style.cpp:105
Q_DECLARE_METATYPE(te::map::AbstractLayerPtr) te
int getSRID() const _NOEXCEPT_OP(true)
It returns the Spatial Reference System ID associated to this geometric object.
static te::cl::ROISet * createROISet(std::unique_ptr< te::da::DataSet > ds)
Imports the ROISet from a dataset.
Definition: ROISet.cpp:113
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.
Custom tool button used to pick a color.
void setMapDisplay(te::qt::widgets::MapDisplay *mapDisplay)
This method is used to set the display.
virtual bool isValid() const _NOEXCEPT_OP(false)
It tells if the geometry is well formed.
#define TE_CL_ROI_COLOR_NAME
This mark defines the color attribute name.
An Envelope defines a 2D rectangular region.
virtual int getSRID() const
It return the Spatial Reference System used by the Map Display.
#define TE_CL_ROI_LABEL_NAME
This mark defines the label attribute name.
void removeROI(std::string label)
Removes a ROI from this set.
Definition: ROISet.cpp:69
virtual const te::gm::Envelope & getExtent() const
It returns the world extent showned by the MapDisplay.
te::gm::Polygon * p
void setOpacity(const std::string &opacity)
Definition: Fill.cpp:71
void set(te::map::AbstractLayerPtr layer)
This method is used to set current layer.
A Fill specifies the pattern for filling an area geometry.
Definition: Fill.h:59
te::map::Visibility m_vectorLayerVisibility
void onGeomAquired(te::gm::Polygon *poly)
void setColor(std::string color)
Set the ROI color using the hexadecimal color name.
Definition: ROI.cpp:52
A region of interest (often abbreviated ROI), is a selected subset of samples within a dataset identi...
Definition: ROI.h:60
Ui::ROIManagerWidgetForm * getForm() const
double m_lly
Lower left corner y-coordinate.
Fill * clone() const
It creates a new copy of this object.
Definition: Fill.cpp:86
void removePolygon(std::string id)
Removes a region from this ROI.
Definition: ROI.cpp:72
Polygon is a subclass of CurvePolygon whose rings are defined by linear rings.
Definition: Polygon.h:50
A Rule is used to attach property/scale conditions to and group the individual symbols used for rende...
Definition: Rule.h:76
virtual QPixmap * getDraftPixmap() const
It returns the map display draft pixmap.
te::map::AbstractLayerPtr m_vectorLayer
double m_ury
Upper right corner y-coordinate.
virtual const std::string & getType() const =0
It returns the symbolizer type.
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
std::string getLabel()
Get the ROI label.
Definition: ROI.cpp:47
TEQTWIDGETSEXPORT QString GetFilePathFromSettings(const QString &typeFile)
Returns the value of the last saved file path for the typeFile required.
void setFill(Fill *f)
A Fill specifies the pattern for filling an area geometry.
virtual Symbolizer * clone() const =0
It creates a new copy of this object.
void setSymbolizer(std::size_t i, Symbolizer *s)
Definition: Rule.cpp:144
TEDATAACCESSEXPORT te::gm::GeometryProperty * GetFirstGeomProperty(const DataSetType *dt)
TEDATAACCESSEXPORT DataSetAdapter * CreateAdapter(DataSet *ds, DataSetTypeConverter *converter, bool isOwner=false)
boost::intrusive_ptr< AbstractLayer > AbstractLayerPtr
void transform(int oldsrid, int newsrid)
It will transform the coordinates of the Envelope from the old SRS to the new one.
te::qt::widgets::MapDisplay * m_mapDisplay
bool checkGeomIntersection(te::cl::ROISet *rs)
#define ROI_TREE_ITEM
An adapter for DataSet.
std::unique_ptr< te::qt::widgets::RpToolsWidget > m_navigator
const Symbolizer * getSymbolizer(std::size_t i) const
Definition: Rule.cpp:163
ROIManagerWidget(QWidget *parent=0, Qt::WindowFlags f=0)
bool isValid() const
It tells if the rectangle is valid or not.
std::map< std::string, te::cl::ROI * > & getROISet()
Get the roi set map.
Definition: ROISet.cpp:77
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.
ColorPickerToolButton * m_colorPicker
std::map< std::string, te::gm::Polygon * > & getPolygons()
Get all polygons belongs to this roi.
Definition: ROI.cpp:62
std::string getColor()
Get the ROI color defined by a hexadecimal color name.
Definition: ROI.cpp:57