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" 45 #include "ui_ClippingWizardPageForm.h" 48 #include <QGridLayout> 50 #include <QDoubleValidator> 51 #include <QIntValidator> 52 #include <QMessageBox> 53 #include <QTableWidgetItem> 60 te::qt::widgets::ClippingWizardPage::ClippingWizardPage(
QWidget* parent)
62 m_ui(new
Ui::ClippingWizardPageForm),
64 m_mapDisplay(
nullptr),
73 QGridLayout* displayLayout =
new QGridLayout(m_ui->m_navigatorWidget);
75 displayLayout->addWidget(m_navigator.get());
76 displayLayout->setContentsMargins(0,0,0,0);
78 m_ui->m_removeRoiToolButton->setIcon(QIcon::fromTheme(
"edit-deletetool"));
81 this->setTitle(tr(
"Clipping"));
82 this->setSubTitle(tr(
"Select the type of clipping and set their specific parameters."));
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));
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));
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)));
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()));
116 int index =
m_ui->m_strategyTypeComboBox->currentIndex();
117 int type =
m_ui->m_strategyTypeComboBox->itemData(index).toInt();
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())
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()
149 if(
m_ui->m_layerComboBox->currentText().isEmpty())
189 int index =
m_ui->m_strategyTypeComboBox->currentIndex();
190 int type =
m_ui->m_strategyTypeComboBox->itemData(index).toInt();
197 int index =
m_ui->m_strategyTypeComboBox->currentIndex();
198 int type =
m_ui->m_strategyTypeComboBox->itemData(index).toInt();
205 int index =
m_ui->m_strategyTypeComboBox->currentIndex();
206 int type =
m_ui->m_strategyTypeComboBox->itemData(index).toInt();
213 int index =
m_ui->m_strategyTypeComboBox->currentIndex();
214 int type =
m_ui->m_strategyTypeComboBox->itemData(index).toInt();
223 if(
m_ui->m_aggregAllRadioButton->isChecked())
225 if(
m_ui->m_groupByRadioButton->isChecked())
227 if(
m_ui->m_selectedGeomRadioButton->isChecked())
232 if(
m_ui->m_groupLayersRadioButton->isChecked())
234 if(
m_ui->m_singleLayersRadioButton->isChecked())
243 return m_ui->m_groupByRadioButton->isChecked();
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();
267 int index =
m_ui->m_layerComboBox->currentIndex();
268 QVariant varLayer =
m_ui->m_layerComboBox->itemData(index, Qt::UserRole);
272 std::unique_ptr<te::da::DataSetType> dsType = layer->getSchema();
274 std::string name = geomProp->
getName();
275 std::unique_ptr<te::gm::Geometry> geom;
276 std::unique_ptr< te::dt::AbstractData > adCloned;
278 if(
m_ui->m_aggregAllRadioButton->isChecked())
280 std::unique_ptr<te::da::DataSet>
ds = layer->getData();
281 ds->moveBeforeFirst();
283 while(ds->moveNext())
285 geom.reset( ds->getGeometry(name).release() );
291 adCloned.reset( geom->clone() );
293 if(geom->getSRID() !=
get()->getSRID())
294 geom->transform(
get()->getSRID());
296 if(geom->getMBR()->intersects(
get()->getExtent()))
297 geomVec.push_back(static_cast<te::gm::Geometry*>(adCloned.release()));
303 else if(
m_ui->m_selectedGeomRadioButton->isChecked())
308 QMessageBox::information(
this, tr(
"Clipping"), tr(
"Select the layer objects to perform the clipping operation."));
312 std::unique_ptr< te::gm::Geometry > geomSelected;
314 std::unique_ptr<te::da::DataSet>
ds = layer->getData(oidSet);
316 ds->moveBeforeFirst();
318 while(ds->moveNext())
320 geomSelected.reset( static_cast<te::gm::Geometry*>(ds->getGeometry(name)->clone()) );
322 if(geomSelected->isValid())
324 if(geomSelected->getSRID() !=
get()->getSRID())
325 geomSelected->transform(
get()->getSRID());
327 if(geomSelected->getMBR()->intersects(
get()->getExtent()))
328 geomVec.push_back(geomSelected.release() );
334 QMessageBox::information(
this, tr(
"Clipping"), tr(
"The seleceted geometries does not intersects the raster extent."));
343 int index =
m_ui->m_layerComboBox->currentIndex();
344 QVariant varLayer =
m_ui->m_layerComboBox->itemData(index, Qt::UserRole);
348 std::unique_ptr<te::da::DataSetType> dsType = layer->getSchema();
350 std::string name = geomProp->
getName();
352 if(
m_ui->m_groupByRadioButton->isChecked())
354 std::string propName =
m_ui->m_layerAttrComboBox->currentText().toUtf8().data();
356 std::map<std::string, std::vector<te::gm::Geometry*> > groups;
357 std::map<std::string, std::vector<te::gm::Geometry*> >::iterator itg;
359 std::unique_ptr<te::da::DataSet>
ds = layer->getData();
361 ds->moveBeforeFirst();
362 while(ds->moveNext())
368 if(geomIntersected->
getSRID() !=
get()->getSRID())
369 geomIntersected->
transform(
get()->getSRID());
371 std::string value = ds->getAsString(propName);
373 itg = groups.find(value);
377 if (itg==groups.end())
379 std::vector<te::gm::Geometry*> geomVec;
381 geomVec.push_back(geomIntersected);
382 groups.insert(std::pair<std::string, std::vector<te::gm::Geometry*> >(value,geomVec));
385 itg->second.push_back(geomIntersected);
392 QMessageBox::information(
this, tr(
"Clipping"), tr(
"There are not geometries intersecting with the raster extent."));
396 itg = groups.begin();
397 while(itg != groups.end())
401 geomMap.insert(std::pair<std::string, te::gm::Geometry*>(itg->first, geom.release()));
410 int row =
m_ui->m_roiTableWidget->rowCount();
412 m_ui->m_roiTableWidget->insertRow(row);
416 QTableWidgetItem* item =
new QTableWidgetItem(
"ROI Item "+QString::number(
m_count));
417 m_ui->m_roiTableWidget->setItem(row, 0, item);
419 m_ui->m_roiTableWidget->resizeRowsToContents();
420 m_ui->m_roiTableWidget->resizeColumnToContents(0);
426 emit completeChanged();
433 int type =
m_ui->m_strategyTypeComboBox->itemData(index).toInt();
437 m_ui->m_extentLayerComboBox->clear();
439 std::list<te::map::AbstractLayerPtr>::iterator it =
m_layerList.begin();
446 m_ui->m_extentLayerComboBox->addItem(l->getTitle().c_str(), QVariant::fromValue(l));
455 m_ui->m_layerComboBox->clear();
457 std::list<te::map::AbstractLayerPtr>::iterator it =
m_layerList.begin();
463 std::unique_ptr<te::da::DataSetType> dsType = l->getSchema();
465 if((
m_layer.get() != l.get()) && dsType->hasGeom())
466 m_ui->m_layerComboBox->addItem(l->getTitle().c_str(), QVariant::fromValue(l));
471 if(
m_ui->m_layerComboBox->count() > 0)
480 m_ui->m_layerAttrComboBox->clear();
482 QVariant varLayer =
m_ui->m_layerComboBox->itemData(index, Qt::UserRole);
485 std::unique_ptr<te::da::DataSetType> dsType = l->getSchema();
487 std::vector<te::dt::Property*> prop = dsType->getProperties();
489 for(std::size_t t = 0; t < dsType->getProperties().size(); ++t)
492 m_ui->m_layerAttrComboBox->addItem(dsType->getProperties()[t]->getName().c_str());
500 QVariant varLayer =
m_ui->m_extentLayerComboBox->itemData(index, Qt::UserRole);
507 if(!e.intersects(
m_layer->getExtent()))
509 m_ui->m_llxLineEdit->clear();
510 m_ui->m_llyLineEdit->clear();
511 m_ui->m_urxLineEdit->clear();
512 m_ui->m_uryLineEdit->clear();
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));
540 emit completeChanged();
557 emit completeChanged();
564 int selectedRow =
m_ui->m_roiTableWidget->currentIndex().row();
571 canvasInstance.setPolygonContourWidth(1);
575 canvasInstance.draw(
m_geomVec.at(selectedRow));
582 int row =
m_ui->m_roiTableWidget->currentIndex().row();
590 m_ui->m_roiTableWidget->removeRow(row);
599 if (
m_ui->m_llxLineEdit->text().isEmpty())
601 QMessageBox::information(
this, tr(
"Clipping"), tr(
"Lower Left X is empty, please enter value for preview."));
604 else if (
m_ui->m_llyLineEdit->text().isEmpty())
606 QMessageBox::information(
this, tr(
"Clipping"), tr(
"Lower Left Y is empty, please enter value for preview."));
609 else if (
m_ui->m_urxLineEdit->text().isEmpty())
611 QMessageBox::information(
this, tr(
"Clipping"), tr(
"Upper Right X is empty, please enter value for preview."));
614 else if (
m_ui->m_uryLineEdit->text().isEmpty())
616 QMessageBox::information(
this, tr(
"Clipping"), tr(
"Upper Right Y is empty, please enter value for preview."));
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();
629 QMessageBox::information(
this, tr(
"Clipping"), tr(
"The values informed does not valid."));
637 emit completeChanged();
642 if(
m_ui->m_startRowLineEdit->text().isEmpty())
644 QMessageBox::information(
this, tr(
"Clipping"), tr(
"Initial row is empty, please enter value for preview."));
647 else if(
m_ui->m_startColumnLineEdit->text().isEmpty())
649 QMessageBox::information(
this, tr(
"Clipping"), tr(
"Initial column is empty, please enter value for preview."));
652 else if(
m_ui->m_heightLineEdit->text().isEmpty())
654 QMessageBox::information(
this, tr(
"Clipping"), tr(
"Height is empty, please enter value for preview."));
657 else if(
m_ui->m_widthLineEdit->text().isEmpty())
659 QMessageBox::information(
this, tr(
"Clipping"), tr(
"Width is empty, please enter value for preview."));
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();
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);
680 emit completeChanged();
685 m_ui->m_strategyTypeComboBox->clear();
687 m_ui->m_strategyTypeComboBox->addItem(tr(
"Region of interest"),
CLIPPING_ROI);
702 canvasInstance.setPolygonContourWidth(2);
708 int index =
m_ui->m_strategyTypeComboBox->currentIndex();
709 int type =
m_ui->m_strategyTypeComboBox->itemData(index).toInt();
732 for(std::size_t i = 0; i <
m_geomVec.size(); ++i)
746 canvasInstance.draw(geom);
758 canvasInstance.
clear();
void onEnvelopeAcquired(te::gm::Envelope env)
te::qt::widgets::MapDisplay * m_mapDisplay
std::vector< te::gm::Geometry * > m_geomVec
void onPreviewDimensionClicked()
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)
te::gm::Envelope m_envExt
te::map::AbstractLayerPtr m_layer
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.
An utility struct for representing 2D coordinates.
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 onStrategyTypeComboBoxChanged(int index)
void setActionGroup(QActionGroup *actionGroup)
void onExtentLayerComboBoxChanged(int index)
Q_DECLARE_METATYPE(te::map::AbstractLayerPtr) te
bool isSingleRasterResult()
This file defines a class for a Clipping Wizard page.
te::map::AbstractLayerPtr get()
int getSRID() const _NOEXCEPT_OP(true)
It returns the Spatial Reference System ID associated to this geometric object.
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...
void onGeomAquired(te::gm::Polygon *poly)
virtual int getSRID() const
It return the Spatial Reference System used by the Map Display.
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.
bool isGroupByAttribute()
Polygon is a subclass of CurvePolygon whose rings are defined by linear rings.
void getLayerClipping(std::vector< te::gm::Geometry * > &geomVec)
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.
void set(te::map::AbstractLayerPtr layer)
This method is used to set the selected layer for clipping operation.
te::gm::Envelope m_envDim
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)
bool isDimensionClipping()
virtual void transform(int srid) _NOEXCEPT_OP(false)=0
It converts the coordinate values of the geometry to the new spatial reference system.
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 onStrategyTypeComboBoxActivated(int index)
void onLayerComboBoxActivated(int index)
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.
bool isLayerExtentClipping()
const std::string & getName() const
It returns the property name.