ClippingWizardPage.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/rp/ClippingWizardPage.cpp
22 
23  \brief This file defines a class for a Clipping Wizard page.
24 */
25 
26 // TerraLib
27 #include "../../../common/StringUtils.h"
28 #include "../../../dataaccess/dataset/DataSet.h"
29 #include "../../../dataaccess/dataset/ObjectIdSet.h"
30 #include "../../../dataaccess/utils/Utils.h"
31 #include "../../../geometry/Geometry.h"
32 #include "../../../geometry/GeometryProperty.h"
33 #include "../../../geometry/GeometryCollection.h"
34 #include "../../../geometry/LinearRing.h"
35 #include "../../../geometry/Polygon.h"
36 #include "../../../geometry/Utils.h"
37 #include "../../../raster/Grid.h"
38 #include "../../../raster/Raster.h"
39 #include "../../../maptools/Utils.h"
40 #include "../canvas/Canvas.h"
41 #include "../canvas/MapDisplay.h"
42 #include "RpToolsWidget.h"
43 
44 #include "ClippingWizardPage.h"
45 #include "ui_ClippingWizardPageForm.h"
46 
47 // Qt
48 #include <QGridLayout>
49 #include <QCheckBox>
50 #include <QDoubleValidator>
51 #include <QIntValidator>
52 #include <QMessageBox>
53 #include <QTableWidgetItem>
54 
55 // STL
56 #include <memory>
57 
59 
60 te::qt::widgets::ClippingWizardPage::ClippingWizardPage(QWidget* parent)
61  : QWizardPage(parent),
62  m_ui(new Ui::ClippingWizardPageForm),
63  m_layer(nullptr),
64  m_mapDisplay(nullptr),
65  m_count(0)
66 {
67 // setup controls
68  m_ui->setupUi(this);
69 
70  fillClippingTypes();
71 
72 //build form
73  QGridLayout* displayLayout = new QGridLayout(m_ui->m_navigatorWidget);
74  m_navigator.reset( new te::qt::widgets::RpToolsWidget(m_ui->m_navigatorWidget));
75  displayLayout->addWidget(m_navigator.get());
76  displayLayout->setContentsMargins(0,0,0,0);
77 
78  m_ui->m_removeRoiToolButton->setIcon(QIcon::fromTheme("edit-deletetool"));
79 
80 //configure page
81  this->setTitle(tr("Clipping"));
82  this->setSubTitle(tr("Select the type of clipping and set their specific parameters."));
83 
84  m_ui->m_llxLineEdit->setValidator(new QDoubleValidator(this));
85  m_ui->m_llyLineEdit->setValidator(new QDoubleValidator(this));
86  m_ui->m_urxLineEdit->setValidator(new QDoubleValidator(this));
87  m_ui->m_uryLineEdit->setValidator(new QDoubleValidator(this));
88 
89  m_ui->m_startRowLineEdit->setValidator(new QIntValidator(this));
90  m_ui->m_startColumnLineEdit->setValidator(new QIntValidator(this));
91  m_ui->m_widthLineEdit->setValidator(new QIntValidator(this));
92  m_ui->m_heightLineEdit->setValidator(new QIntValidator(this));
93 
94 //connects
95  connect(m_ui->m_strategyTypeComboBox, SIGNAL(activated(int)), this, SLOT(onStrategyTypeComboBoxActivated(int)));
96  connect(m_ui->m_strategyTypeComboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(onStrategyTypeComboBoxChanged(int)));
97  connect(m_ui->m_layerComboBox, SIGNAL(activated(int)), this, SLOT(onLayerComboBoxActivated(int)));
98  connect(m_ui->m_extentLayerComboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(onExtentLayerComboBoxChanged(int)));
99 
100  connect(m_ui->m_roiTableWidget, SIGNAL(cellClicked(int, int)), this, SLOT(onSelectRoiItem()));
101  connect(m_ui->m_removeRoiToolButton, SIGNAL(clicked()), this, SLOT(onRemoveRoiItem()));
102  connect(m_ui->m_previewButton, SIGNAL(clicked()), this, SLOT(onPreviewClicked()));
103  connect(m_ui->m_previewDimensionPushButton, SIGNAL(clicked()), this, SLOT(onPreviewDimensionClicked()));
104 
105  connect(m_navigator.get(), SIGNAL(envelopeAcquired(te::gm::Envelope)), this, SLOT(onEnvelopeAcquired(te::gm::Envelope)));
106  connect(m_navigator.get(), SIGNAL(geomAquired(te::gm::Polygon*)), this, SLOT(onGeomAquired(te::gm::Polygon*)));
107 }
108 
110 {
111  m_geomVec.clear();
112 }
113 
115 {
116  int index = m_ui->m_strategyTypeComboBox->currentIndex();
117  int type = m_ui->m_strategyTypeComboBox->itemData(index).toInt();
118 
119  if (type == CLIPPING_ROI)
120  {
121  if(m_geomVec.empty())
122  return false;
123 
124  return true;
125  }
126  else if(type == CLIPPING_LAYER_EXTENT)
127  {
128  if(m_ui->m_llxLineEdit->text().isEmpty() ||
129  m_ui->m_llyLineEdit->text().isEmpty() ||
130  m_ui->m_urxLineEdit->text().isEmpty() ||
131  m_ui->m_uryLineEdit->text().isEmpty())
132  return false;
133 
134  return true;
135  }
136  else if(type == CLIPPING_DIMENSION)
137  {
138  if(m_ui->m_startRowLineEdit->text().isEmpty() ||
139  m_ui->m_startColumnLineEdit->text().isEmpty() ||
140  m_ui->m_widthLineEdit->text().isEmpty() ||
141  m_ui->m_heightLineEdit->text().isEmpty()
142  )
143  return false;
144 
145  return true;
146  }
147  else if(type == CLIPPING_LAYER)
148  {
149  if(m_ui->m_layerComboBox->currentText().isEmpty())
150  return false;
151 
152  return true;
153  }
154 
155  return false;
156 }
157 
159 {
160  m_layer = layer;
161 }
162 
163 void te::qt::widgets::ClippingWizardPage::setList(std::list<te::map::AbstractLayerPtr>& layerList)
164 {
165  m_layerList = layerList;
166 }
167 
169 {
170  m_navigator->setMapDisplay(mapDisplay);
171  m_mapDisplay = mapDisplay;
172 }
173 
175 {
176  //configure tools
177  m_navigator->setActionGroup(actionGroup);
178  m_navigator->enableGeomAction();
179  m_navigator->enableBoxAction();
180 }
181 
183 {
184  return m_layer;
185 }
186 
188 {
189  int index = m_ui->m_strategyTypeComboBox->currentIndex();
190  int type = m_ui->m_strategyTypeComboBox->itemData(index).toInt();
191 
192  return type == CLIPPING_ROI;
193 }
194 
196 {
197  int index = m_ui->m_strategyTypeComboBox->currentIndex();
198  int type = m_ui->m_strategyTypeComboBox->itemData(index).toInt();
199 
200  return type == CLIPPING_LAYER_EXTENT;
201 }
202 
204 {
205  int index = m_ui->m_strategyTypeComboBox->currentIndex();
206  int type = m_ui->m_strategyTypeComboBox->itemData(index).toInt();
207 
208  return type == CLIPPING_DIMENSION;
209 }
210 
212 {
213  int index = m_ui->m_strategyTypeComboBox->currentIndex();
214  int type = m_ui->m_strategyTypeComboBox->itemData(index).toInt();
215 
216  return type == CLIPPING_LAYER;
217 }
218 
220 {
221  if(isLayerClipping())
222  {
223  if(m_ui->m_aggregAllRadioButton->isChecked())
224  return true;
225  if(m_ui->m_groupByRadioButton->isChecked())
226  return false;
227  if(m_ui->m_selectedGeomRadioButton->isChecked())
228  return true;
229  }
230  else
231  {
232  if(m_ui->m_groupLayersRadioButton->isChecked())
233  return true;
234  if(m_ui->m_singleLayersRadioButton->isChecked())
235  return false;
236  }
237 
238  return true;
239 }
240 
242 {
243  return m_ui->m_groupByRadioButton->isChecked();
244 }
245 
246 void te::qt::widgets::ClippingWizardPage::getExtentClipping(std::vector<te::gm::Geometry*> &geomVec)
247 {
248  geomVec = m_geomVec;
249 }
250 
252 {
253  env = m_envExt;
254 }
255 
256 void te::qt::widgets::ClippingWizardPage::getDimensionClipping(int& x, int& y, int& width, int& height)
257 {
258  x = m_ui->m_startColumnLineEdit->text().toInt();
259  y = m_ui->m_startRowLineEdit->text().toInt();
260  width = m_ui->m_widthLineEdit->text().toInt();
261  height = m_ui->m_heightLineEdit->text().toInt();
262 }
263 
264 void te::qt::widgets::ClippingWizardPage::getLayerClipping(std::vector<te::gm::Geometry*> &geomVec)
265 {
266  //get layer
267  int index = m_ui->m_layerComboBox->currentIndex();
268  QVariant varLayer = m_ui->m_layerComboBox->itemData(index, Qt::UserRole);
269  te::map::AbstractLayerPtr layer = varLayer.value<te::map::AbstractLayerPtr>();
270 
271  //get geometry property data
272  std::unique_ptr<te::da::DataSetType> dsType = layer->getSchema();
273  te::gm::GeometryProperty* geomProp = te::da::GetFirstGeomProperty(dsType.get());
274  std::string name = geomProp->getName();
275  std::unique_ptr<te::gm::Geometry> geom;
276  std::unique_ptr< te::dt::AbstractData > adCloned;
277 
278  if(m_ui->m_aggregAllRadioButton->isChecked())
279  {
280  std::unique_ptr<te::da::DataSet> ds = layer->getData();
281  ds->moveBeforeFirst();
282 
283  while(ds->moveNext())
284  {
285  geom.reset( ds->getGeometry(name).release() );
286 
287  if (geom.get())
288  {
289  if(geom->isValid())
290  {
291  adCloned.reset( geom->clone() );
292 
293  if(geom->getSRID() != get()->getSRID())
294  geom->transform(get()->getSRID());
295 
296  if(geom->getMBR()->intersects(get()->getExtent()))
297  geomVec.push_back(static_cast<te::gm::Geometry*>(adCloned.release()));
298  }
299 
300  }
301  }
302  }
303  else if(m_ui->m_selectedGeomRadioButton->isChecked())
304  {
305  const te::da::ObjectIdSet* oidSet = layer->getSelected();
306  if(!oidSet)
307  {
308  QMessageBox::information(this, tr("Clipping"), tr("Select the layer objects to perform the clipping operation."));
309  return;
310  }
311 
312  std::unique_ptr< te::gm::Geometry > geomSelected;
313 
314  std::unique_ptr<te::da::DataSet> ds = layer->getData(oidSet);
315 
316  ds->moveBeforeFirst();
317 
318  while(ds->moveNext())
319  {
320  geomSelected.reset( static_cast<te::gm::Geometry*>(ds->getGeometry(name)->clone()) );
321 
322  if(geomSelected->isValid())
323  {
324  if(geomSelected->getSRID() != get()->getSRID())
325  geomSelected->transform(get()->getSRID());
326 
327  if(geomSelected->getMBR()->intersects(get()->getExtent()))
328  geomVec.push_back(geomSelected.release() );
329  }
330  }
331 
332  if(geomVec.empty())
333  {
334  QMessageBox::information(this, tr("Clipping"), tr("The seleceted geometries does not intersects the raster extent."));
335  return;
336  }
337  }
338 }
339 
340 void te::qt::widgets::ClippingWizardPage::getLayerClippingAttribute(std::map<std::string, te::gm::Geometry*> &geomMap)
341 {
342  //get layer
343  int index = m_ui->m_layerComboBox->currentIndex();
344  QVariant varLayer = m_ui->m_layerComboBox->itemData(index, Qt::UserRole);
345  te::map::AbstractLayerPtr layer = varLayer.value<te::map::AbstractLayerPtr>();
346 
347  //get geometry property data
348  std::unique_ptr<te::da::DataSetType> dsType = layer->getSchema();
349  te::gm::GeometryProperty* geomProp = te::da::GetFirstGeomProperty(dsType.get());
350  std::string name = geomProp->getName();
351 
352  if(m_ui->m_groupByRadioButton->isChecked())
353  {
354  std::string propName = m_ui->m_layerAttrComboBox->currentText().toUtf8().data();
355 
356  std::map<std::string, std::vector<te::gm::Geometry*> > groups;
357  std::map<std::string, std::vector<te::gm::Geometry*> >::iterator itg;
358 
359  std::unique_ptr<te::da::DataSet> ds = layer->getData();
360 
361  ds->moveBeforeFirst();
362  while(ds->moveNext())
363  {
364  te::gm::Geometry* geomIntersected = static_cast<te::gm::Geometry*>(ds->getGeometry(name)->clone());
365 
366  if(geomIntersected->isValid())
367  {
368  if(geomIntersected->getSRID() != get()->getSRID())
369  geomIntersected->transform(get()->getSRID());
370 
371  std::string value = ds->getAsString(propName);
372 
373  itg = groups.find(value);
374 
375  if(geomIntersected->getMBR()->intersects(get()->getExtent()))
376  {
377  if (itg==groups.end())
378  {
379  std::vector<te::gm::Geometry*> geomVec;
380 
381  geomVec.push_back(geomIntersected);
382  groups.insert(std::pair<std::string, std::vector<te::gm::Geometry*> >(value,geomVec));
383  }
384  else
385  itg->second.push_back(geomIntersected);
386  }
387  }
388  }
389 
390  if(groups.empty())
391  {
392  QMessageBox::information(this, tr("Clipping"), tr("There are not geometries intersecting with the raster extent."));
393  return;
394  }
395 
396  itg = groups.begin();
397  while(itg != groups.end())
398  {
399  std::unique_ptr<te::gm::Geometry> geom = te::gm::GetGeometryUnion(itg->second);
400 
401  geomMap.insert(std::pair<std::string, te::gm::Geometry*>(itg->first, geom.release()));
402 
403  ++itg;
404  }
405  }
406 }
407 
409 {
410  int row = m_ui->m_roiTableWidget->rowCount();
411 
412  m_ui->m_roiTableWidget->insertRow(row);
413 
414  m_count++;
415 
416  QTableWidgetItem* item = new QTableWidgetItem("ROI Item "+QString::number(m_count));
417  m_ui->m_roiTableWidget->setItem(row, 0, item);
418 
419  m_ui->m_roiTableWidget->resizeRowsToContents();
420  m_ui->m_roiTableWidget->resizeColumnToContents(0);
421 }
422 
424  int /*index*/)
425 {
426  emit completeChanged();
427 }
428 
430 {
431  clearCanvas();
432 
433  int type = m_ui->m_strategyTypeComboBox->itemData(index).toInt();
434 
435  if(type == CLIPPING_LAYER_EXTENT)
436  {
437  m_ui->m_extentLayerComboBox->clear();
438 
439  std::list<te::map::AbstractLayerPtr>::iterator it = m_layerList.begin();
440 
441  while(it != m_layerList.end())
442  {
444 
445  if(m_layer.get() != l.get())
446  m_ui->m_extentLayerComboBox->addItem(l->getTitle().c_str(), QVariant::fromValue(l));
447 
448  ++it;
449  }
450 
452  }
453  else if(type == CLIPPING_LAYER)
454  {
455  m_ui->m_layerComboBox->clear();
456 
457  std::list<te::map::AbstractLayerPtr>::iterator it = m_layerList.begin();
458 
459  while(it != m_layerList.end())
460  {
462 
463  std::unique_ptr<te::da::DataSetType> dsType = l->getSchema();
464 
465  if((m_layer.get() != l.get()) && dsType->hasGeom())
466  m_ui->m_layerComboBox->addItem(l->getTitle().c_str(), QVariant::fromValue(l));
467 
468  ++it;
469  }
470 
471  if(m_ui->m_layerComboBox->count() > 0)
473  }
474 
475  drawGeom();
476 }
477 
479 {
480  m_ui->m_layerAttrComboBox->clear();
481 
482  QVariant varLayer = m_ui->m_layerComboBox->itemData(index, Qt::UserRole);
484 
485  std::unique_ptr<te::da::DataSetType> dsType = l->getSchema();
486 
487  std::vector<te::dt::Property*> prop = dsType->getProperties();
488 
489  for(std::size_t t = 0; t < dsType->getProperties().size(); ++t)
490  {
491  if(prop[t]->getType() != te::dt::GEOMETRY_TYPE)
492  m_ui->m_layerAttrComboBox->addItem(dsType->getProperties()[t]->getName().c_str());
493  }
494 }
495 
497 {
498  if(isLayerExtentClipping() && m_ui->m_extentLayerComboBox->count() > 0)
499  {
500  QVariant varLayer = m_ui->m_extentLayerComboBox->itemData(index, Qt::UserRole);
501  te::map::AbstractLayerPtr layer = varLayer.value<te::map::AbstractLayerPtr>();
502 
503  te::gm::Envelope e = layer->getExtent();
504 
505  e.transform(layer->getSRID(), m_layer->getSRID());
506 
507  if(!e.intersects(m_layer->getExtent()))
508  {
509  m_ui->m_llxLineEdit->clear();
510  m_ui->m_llyLineEdit->clear();
511  m_ui->m_urxLineEdit->clear();
512  m_ui->m_uryLineEdit->clear();
513 
514  clearCanvas();
515 
516  return;
517  }
518 
519  m_ui->m_llxLineEdit->setText(QString::number(e.getLowerLeftX(), 'f', 5));
520  m_ui->m_llyLineEdit->setText(QString::number(e.getLowerLeftY(), 'f', 5));
521  m_ui->m_urxLineEdit->setText(QString::number(e.getUpperRightX(), 'f', 5));
522  m_ui->m_uryLineEdit->setText(QString::number(e.getUpperRightY(), 'f', 5));
523  }
524 }
525 
527 {
528  if(m_mapDisplay->getSRID() != m_layer->getSRID())
529  env.transform(m_mapDisplay->getSRID(), m_layer->getSRID());
530 
531  if (!env.isValid() || !env.intersects(m_layer->getExtent()))
532  return;
533 
534  m_geomVec.push_back(te::gm::GetGeomFromEnvelope(&env, m_layer->getSRID()));
535 
536  addRoiItem();
537 
538  drawGeom();
539 
540  emit completeChanged();
541 }
542 
544 {
545  if(m_mapDisplay->getSRID() != m_layer->getSRID())
546  poly->transform(m_layer->getSRID());
547 
548  if(!poly->isValid() || !poly->intersects(te::gm::GetGeomFromEnvelope(&m_layer->getExtent(), m_layer->getSRID())))
549  return;
550 
551  m_geomVec.push_back(poly);
552 
553  addRoiItem();
554 
555  drawGeom();
556 
557  emit completeChanged();
558 }
559 
561 {
562  drawGeom();
563 
564  int selectedRow = m_ui->m_roiTableWidget->currentIndex().row();
565 
566  const te::gm::Envelope& mapExt = m_mapDisplay->getExtent();
567 
569  canvasInstance.setWindow(mapExt.m_llx, mapExt.m_lly, mapExt.m_urx, mapExt.m_ury);
570 
571  canvasInstance.setPolygonContourWidth(1);
572  canvasInstance.setPolygonContourColor(te::color::RGBAColor(100, 177, 216, 222));
573  canvasInstance.setPolygonFillColor(te::color::RGBAColor(100, 177, 216, 220));
574 
575  canvasInstance.draw(m_geomVec.at(selectedRow));
576 
577  m_mapDisplay->repaint();
578 }
579 
581 {
582  int row = m_ui->m_roiTableWidget->currentIndex().row();
583 
584  if(m_geomVec.empty())
585  {
586  m_count = 0;
587  return;
588  }
589 
590  m_ui->m_roiTableWidget->removeRow(row);
591 
592  m_geomVec.erase(m_geomVec.begin()+row);
593 
594  drawGeom();
595 }
596 
598 {
599  if (m_ui->m_llxLineEdit->text().isEmpty())
600  {
601  QMessageBox::information(this, tr("Clipping"), tr("Lower Left X is empty, please enter value for preview."));
602  return;
603  }
604  else if (m_ui->m_llyLineEdit->text().isEmpty())
605  {
606  QMessageBox::information(this, tr("Clipping"), tr("Lower Left Y is empty, please enter value for preview."));
607  return;
608  }
609  else if (m_ui->m_urxLineEdit->text().isEmpty())
610  {
611  QMessageBox::information(this, tr("Clipping"), tr("Upper Right X is empty, please enter value for preview."));
612  return;
613  }
614  else if (m_ui->m_uryLineEdit->text().isEmpty())
615  {
616  QMessageBox::information(this, tr("Clipping"), tr("Upper Right Y is empty, please enter value for preview."));
617  return;
618  }
619 
620  const double& llx = m_ui->m_llxLineEdit->text().toDouble();
621  const double& lly = m_ui->m_llyLineEdit->text().toDouble();
622  const double& urx = m_ui->m_urxLineEdit->text().toDouble();
623  const double& ury = m_ui->m_uryLineEdit->text().toDouble();
624 
625  te::gm::Envelope env(llx, lly, urx, ury);
626 
627  if (!env.isValid())
628  {
629  QMessageBox::information(this, tr("Clipping"), tr("The values informed does not valid."));
630  return;
631  }
632 
633  m_envExt = env;
634 
635  drawGeom();
636 
637  emit completeChanged();
638 }
639 
641 {
642  if(m_ui->m_startRowLineEdit->text().isEmpty())
643  {
644  QMessageBox::information(this, tr("Clipping"), tr("Initial row is empty, please enter value for preview."));
645  return;
646  }
647  else if(m_ui->m_startColumnLineEdit->text().isEmpty())
648  {
649  QMessageBox::information(this, tr("Clipping"), tr("Initial column is empty, please enter value for preview."));
650  return;
651  }
652  else if(m_ui->m_heightLineEdit->text().isEmpty())
653  {
654  QMessageBox::information(this, tr("Clipping"), tr("Height is empty, please enter value for preview."));
655  return;
656  }
657  else if(m_ui->m_widthLineEdit->text().isEmpty())
658  {
659  QMessageBox::information(this, tr("Clipping"), tr("Width is empty, please enter value for preview."));
660  return;
661  }
662 
663  int x = m_ui->m_startColumnLineEdit->text().toInt();
664  int y = m_ui->m_startRowLineEdit->text().toInt();
665  int width = m_ui->m_widthLineEdit->text().toInt();
666  int height = m_ui->m_heightLineEdit->text().toInt();
667 
668  std::unique_ptr<te::rst::Raster> inputRst(te::map::GetRaster(m_layer.get()));
669 
670  if(inputRst.get())
671  {
672  te::gm::Coord2D ulc = inputRst->getGrid()->gridToGeo(((double)x) - 0.5, ((double)y) - 0.5);
673  te::gm::Coord2D lrc = inputRst->getGrid()->gridToGeo(((double)(x + width)) - 0.5, ((double)(y + height)) - 0.5);
674 
675  m_envDim = te::gm::Envelope(ulc.x, lrc.y, lrc.x, ulc.y);
676  }
677 
678  drawGeom();
679 
680  emit completeChanged();
681 }
682 
684 {
685  m_ui->m_strategyTypeComboBox->clear();
686 
687  m_ui->m_strategyTypeComboBox->addItem(tr("Region of interest"), CLIPPING_ROI);
688  m_ui->m_strategyTypeComboBox->addItem(tr("Layer Extent"), CLIPPING_LAYER_EXTENT);
689  m_ui->m_strategyTypeComboBox->addItem(tr("Layer"), CLIPPING_LAYER);
690  m_ui->m_strategyTypeComboBox->addItem(tr("Dimension"), CLIPPING_DIMENSION);
691 }
692 
694 {
695  m_mapDisplay->getDraftPixmap()->fill(Qt::transparent);
696 
697  const te::gm::Envelope& mapExt = m_mapDisplay->getExtent();
698 
700  canvasInstance.setWindow(mapExt.m_llx, mapExt.m_lly, mapExt.m_urx, mapExt.m_ury);
701 
702  canvasInstance.setPolygonContourWidth(2);
703  canvasInstance.setPolygonContourColor(te::color::RGBAColor(100, 177, 216, TE_OPAQUE));
704  canvasInstance.setPolygonFillColor(te::color::RGBAColor(100, 177, 216, 80));
705 
706  te::gm::Geometry* geom = nullptr;
707 
708  int index = m_ui->m_strategyTypeComboBox->currentIndex();
709  int type = m_ui->m_strategyTypeComboBox->itemData(index).toInt();
710 
711 
712  if(type == CLIPPING_LAYER_EXTENT)
713  {
714  if(m_envExt.isValid())
715  {
716  canvasInstance.setPolygonContourDashStyle(te::map::LineDashStyle::DashLine);
717 
718  te::gm::Envelope ext = m_envExt.intersection(m_layer->getExtent());
719 
720  geom = te::gm::GetGeomFromEnvelope(&ext, m_layer->getSRID());
721  }
722  }
723 
724  if(type == CLIPPING_DIMENSION)
725  {
726  if(m_envDim.isValid())
727  geom = te::gm::GetGeomFromEnvelope(&m_envDim, m_layer->getSRID());
728  }
729 
730  if(type == CLIPPING_ROI)
731  {
732  for(std::size_t i = 0; i < m_geomVec.size(); ++i)
733  {
734  if(m_geomVec[i]->getSRID() != m_mapDisplay->getSRID())
735  m_geomVec[i]->transform(m_mapDisplay->getSRID());
736 
737  canvasInstance.draw(m_geomVec[i]);
738  }
739  }
740 
741  if(geom)
742  {
743  if(geom->getSRID() != m_mapDisplay->getSRID())
744  geom->transform(m_mapDisplay->getSRID());
745 
746  canvasInstance.draw(geom);
747 
748  delete geom;
749  }
750 
751  m_mapDisplay->repaint();
752 }
753 
755 {
757 
758  canvasInstance.clear();
759 
760  m_mapDisplay->repaint();
761 }
void onEnvelopeAcquired(te::gm::Envelope env)
te::qt::widgets::MapDisplay * m_mapDisplay
void clear()
It clears the canvas content and fills with the background color.
std::vector< te::gm::Geometry * > m_geomVec
Geometric property.
double y
y-coordinate.
Definition: Coord2D.h:114
bool intersects(const Envelope &rhs) const
It returns true if the envelopes "spatially intersects".
void transform(int srid)
It converts the coordinate values of the geometry to the new spatial reference system.
void getLayerExtentClipping(te::gm::Envelope &env)
double x
x-coordinate.
Definition: Coord2D.h:113
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.
TEGEOMEXPORT std::unique_ptr< te::gm::Geometry > GetGeometryUnion(const std::vector< te::gm::Geometry * > &geomVec)
It returns the union of a geometry vector.
A widget to control the display of a set of layers.
An utility struct for representing 2D coordinates.
Definition: Coord2D.h:40
static te::dt::Date ds(2010, 01, 01)
void setList(std::list< te::map::AbstractLayerPtr > &layerList)
virtual bool intersects(const Geometry *const rhs) const _NOEXCEPT_OP(false)
It returns true if the geometry object spatially intersects rhs geometry.
void setActionGroup(QActionGroup *actionGroup)
Q_DECLARE_METATYPE(te::map::AbstractLayerPtr) te
This file defines a class for a Clipping Wizard page.
int getSRID() const _NOEXCEPT_OP(true)
It returns the Spatial Reference System ID associated to this geometric object.
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< Ui::ClippingWizardPageForm > m_ui
const Envelope * getMBR() const _NOEXCEPT_OP(true)
It returns the minimum bounding rectangle for the geometry in an internal representation.
virtual bool isValid() const _NOEXCEPT_OP(false)
It tells if the geometry is well formed.
An Envelope defines a 2D rectangular region.
void setMapDisplay(te::qt::widgets::MapDisplay *mapDisplay)
This class represents a set of unique ids created in the same context. i.e. from the same data set...
Definition: ObjectIdSet.h:55
void onGeomAquired(te::gm::Polygon *poly)
virtual int getSRID() const
It return the Spatial Reference System used by the Map Display.
URI C++ Library.
Definition: Attributes.h:37
virtual const te::gm::Envelope & getExtent() const
It returns the world extent showned by the MapDisplay.
std::unique_ptr< te::qt::widgets::RpToolsWidget > m_navigator
Geometry is the root class of the geometries hierarchy, it follows OGC and ISO standards.
double m_lly
Lower left corner y-coordinate.
TEMAPEXPORT te::rst::Raster * GetRaster(AbstractLayer *layer)
It gets the raster referenced by the given data set layer.
Polygon is a subclass of CurvePolygon whose rings are defined by linear rings.
Definition: Polygon.h:50
void getLayerClipping(std::vector< te::gm::Geometry * > &geomVec)
virtual QPixmap * getDraftPixmap() const
It returns the map display draft pixmap.
double m_ury
Upper right corner y-coordinate.
void getLayerClippingAttribute(std::map< std::string, te::gm::Geometry * > &geomMap)
void getExtentClipping(std::vector< te::gm::Geometry * > &geomVec)
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 set(te::map::AbstractLayerPtr layer)
This method is used to set the selected layer for clipping operation.
Envelope intersection(const Envelope &rhs) const
It returns an envelope that represents the point set intersection with another envelope.
TEDATAACCESSEXPORT te::gm::GeometryProperty * GetFirstGeomProperty(const DataSetType *dt)
virtual void transform(int srid) _NOEXCEPT_OP(false)=0
It converts the coordinate values of the geometry to the new spatial reference system.
This file has the RpToolsWidget class.
boost::intrusive_ptr< AbstractLayer > AbstractLayerPtr
std::list< te::map::AbstractLayerPtr > m_layerList
void transform(int oldsrid, int newsrid)
It will transform the coordinates of the Envelope from the old SRS to the new one.
void getDimensionClipping(int &x, int &y, int &width, int &height)
bool isValid() const
It tells if the rectangle is valid or not.
TEGEOMEXPORT Geometry * GetGeomFromEnvelope(const Envelope *const e, int srid)
It creates a Geometry (a polygon) from the given envelope.
const std::string & getName() const
It returns the property name.
Definition: Property.h:127